Straightening image from X-ray tomography

6 views (last 30 days)

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

Accepted Answer

jonas
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
redmef
redmef on 6 Jul 2018
Just one quick question: this code is specific for this material and that direction; Does it work for any direction and thin material ?
jonas
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Biomedical Imaging in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!