Straightening image from X-ray tomography
6 views (last 30 days)
Show older comments
Dear all,
I am scanning some no rigid materials with X-ray tomography. I got a stack of images where unfortunately is impossible to have the sample straight like you can see below.

I already tried to do it with ImageJ for one image and the result is not that bad.

The problem is: I have a stack of images with 1500 images and it's really long to do it with ImageJ. Do you have an idea of to straight the material for a stack of images with Matlab?
Best
0 Comments
Accepted Answer
jonas
on 4 Jul 2018
Edited: jonas
on 4 Jul 2018
Here is something I have stitched together that seems to work fairly well.
%%Load Image, rotate and convert to binary
GRAY=imread('scan_00123.tif');
GRAY=rot90(GRAY);
threshold = graythresh(GRAY);
BW = im2bw(GRAY, threshold);
%%Find Coordinates of images and smooth a curve
[y,x]=find(BW==1);
y=y-mean(y);
figure;
subplot(1,2,1);hold on
plot(x,y)
win=1500;
y2=smooth(x,y,win);
plot(x,y2,'r')
%%Fix size of vector
[x, index] = unique(x);
xq=1:size(GRAY,2);
yq = interp1(x, y2(index), xq,'linear','extrap');
plot(xq,yq,'--k')
%%Adjust image column-wise
NewImage=uint16(nan(size(GRAY,1)*3,size(GRAY,2)));
ymid=size(GRAY,1)*3/2;
for i=1:size(GRAY,2)
s=yq(i);
NewImage(ymid-s:ymid-1-s+size(GRAY,1),i)=GRAY(:,i);
end
figure;
NewImage(isnan(NewImage))=0;
imshow(NewImage)
10 Comments
jonas
on 6 Jul 2018
'specific for this material?'
In general, no. Most of the script should work for any thin material. You may have to adjust the segmentation slightly depending on the color/brightness of the material.
specific direction?
The script, as is, works for materials aligned vertically. Simply remove the line
GRAY=rot90(GRAY);
for materials stretched horizontally.
More Answers (0)
See Also
Categories
Find more on Biomedical Imaging in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!