how to make multiple ellipses in image (one inside another) and find the sum of pixels between two ellipses.

4 views (last 30 days)
Dear Expert,
I have an tif file and i want to cut the elliptical part of from that image (which i am doing by the following code) . Although I can get sum of elliptical by the following method. But I want to make multiple elliptise(first ellipse and then second smaller ellipse inside the first one and so on) and i also want to know the sum of pixels between two ellipses. I am attaching an image showing how I want to draw the ellipses.
Thank you
[FileName,PathName] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files'},'Please Select an Image');
image = imread([PathName FileName]);
imshow(image) %needed to use imellipse
user_defined_ellipse = imellipse(gca, []); % creates user defined ellipse object.
wait(user_defined_ellipse);% You need to click twice to continue.
MASK = double(user_defined_ellipse.createMask());
new_image_name = [PathName 'Cropped_Image_' FileName];
new_image_name = new_image_name(1:strfind(new_image_name,'.')-1); %removing the .jpg, .tiff, etc
new_image_name = [new_image_name '.tif']; % making the image .png so it can be transparent
imwrite(image, new_image_name,'png','Alpha',MASK);
msg = msgbox(['The image was written to ' new_image_name],'New Image Path');
waitfor(msg);
cropped_img_sum = imread(new_image_name);
winopen(new_image_name);
cropped_img = sum(sum(cropped_img))

Accepted Answer

Image Analyst
Image Analyst on 7 Oct 2022
That's exactly what my demo does. See attached demos.
meanInsideEllipse =
100.464150943396
areaOfEllipse =
9805
You could of course sum all the gray levels inside if you wanted by adding this:
sumInsideEllipse = sum(monochromeImage(maskImage))
  4 Comments
Image Analyst
Image Analyst on 9 Oct 2022
@SHUBHAM AGARWAL I don't know. Not all of the Image Processing functions work well if you have changed the zoom. It might not be possible. Call tech support for a definitive answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by