![](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!