![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148825/image.png)
how to make multiple ellipses in image (one inside another) and find the sum of pixels between two ellipses.
2 次查看(过去 30 天)
显示 更早的评论
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))
0 个评论
采纳的回答
Image Analyst
2022-10-7
That's exactly what my demo does. See attached demos.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148825/image.png)
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 个评论
Image Analyst
2022-10-9
@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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!