How can I automatically crop an image in an elliptical shape?
3 views (last 30 days)
Show older comments
I have taken photographs of Petri dishes. The photographs are rectangular in shape, but I need to crop them such that the image is entirely of the Petri dish and therefore roughly circular in shape.
I see that imcrop can be used to rectilinearly crop images, but is there an elliptical analog to this?
Just for some background, I am working on a Matlab code that will automatically count the number of bacterial colonies on a Petri dish by inputting an image of the dish into the imfindcircles function.
Alternatively, is there a simple-ish way of having Matlab automatically detect the boundaries of the Petri dish, draw an outline around it, and then omit all parts of the image that are not inside of the drawn shape? My function depends on cropping the image precisely around the Petri dish boundaries.
Attached are a few examples of the images I am working with.
Thank you very much in advance for your help!
Accepted Answer
KSSV
on 13 Apr 2017
I=imread('dish.jpg');
h = imshow(I) ;
%%call imellipse
% set some positon for ellipse
x = 10;
y = 10;
d1 = 100;
d2 = 100;
e = imellipse(gca, [x y d1 d2]);
% wait to change the positon
position = wait(e);
% ipdate the positon
pos = getPosition(e);
x = pos(1);
y = pos(2);
d1 = pos(3);
d2 = pos(4);
%
BW = createMask(e,h);
% here assuming your image is uint8
BW = uint8(BW);
I2 = I.*BW; % everything outside circle to black
imwrite(I2,'out.png','Transparency',0);
there would be further elegant solution. Especially Image Analyst will answer.
2 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!