How can I detect and crop an evolving specimen profile?

3 views (last 30 days)
Hi!
I have images of a specimen whose shape changes due to loading. To proceed in my analysis, I would like to be able to retain only the front face of the specimen, and remove the background. I can of course manually draw the region I want to keep and crop the rest, but because there are over 2000 images, I'd like to automate this process. Only trouble is, I can't just draw one mask and use it to crop all the images - the shape of the front face of the specimen doesn't stay constant over the 2000 images, and is changing ever so slightly, image to image (evolving profile, pictures attached).
Any ideas for profile detection? I've added some images, to make it clearer.

Answers (1)

Abhishek Kolla
Abhishek Kolla on 2 Aug 2021
Find the edges of the binary image to get a mask of the specimen . Edges can be found using Find edges in intensity image - MATLAB edge (mathworks.com)
To remove the spurious edges we can apply morphological operations on the image using Morphological operations on binary images - MATLAB bwmorph (mathworks.com)
Then find all the co-ordinates of the mask generated in the original image using minimum and maximum.
Kindly have a look at the following example code:
im=imread('Test1.jpg');
im=imgaussfilt(im,2);
bw=edge(im,'Canny');
bw=bwmorph(bw,'majority');
imshow(bw);
minx=10000; miny=10000; maxx=-1;maxy=-1;
for i=1:size(bw,1)
for j=1:size(bw,2)
if(bw(i,j)==1)
if(i<minx)
minx=i;
end
if(i>maxx)
maxx=i;
end
if(j<miny)
miny=j;
end
if(j>maxy)
maxy=j;
end
end
end
end
k=im(minx:maxx,miny:maxy);
imshow(k);
The output obtained on one of the Test image is enclosed

Community Treasure Hunt

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

Start Hunting!