필터 지우기
필터 지우기

How to find the area of a segmented image in matlab?

조회 수: 4 (최근 30일)
Ramanathan Anandarama Krishnan
Ramanathan Anandarama Krishnan 2019년 7월 17일
댓글: Rik 2020년 11월 11일
I need to find the total area of the segmented image(attached below) in Matlab. However i am not able to get that if i use regionprops('Area') command. It gives me total pixel size which is 2048*2048 but i need to find the area of only the segmented region(Black)? Please tell me how to do it.
  댓글 수: 2
Sreenath Reddy
Sreenath Reddy 2020년 11월 11일
can u add full source code please to find the area
Rik
Rik 2020년 11월 11일
Have you looked at the answers below?

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2019년 7월 17일
편집: Rik 2019년 7월 17일
You can make use of the fact that true is stored as a 1. Make sure your object is the only one marked with true and then use this:
A=sum(IM, 'all');
If you're using on older release, use this instead:
A=sum(IM(:));
  댓글 수: 6
Rik
Rik 2019년 7월 18일
Just as a point of clarification: this code counts the number of nonzero pixels. If you input an RGB image, it will count each pixel 3 times. You need to convert it to black and white image where the white is the area you want to count. rgb2gray followed by a threshold should work best.
If you want to count the black pixels, you will have to invert the image, as Image Analyst suggested. (when you posted the question I either missed that you wanted the black area, or I misread, or you edited the question)
As for the conversion to real external units, you should try to get the dicom header. They will contain the needed information.
Ramanathan Anandarama Krishnan
Ramanathan Anandarama Krishnan 2019년 7월 19일
Dear Rik,
Thanks a lot for your suggestions. It's my mistake that i did not put a proper question. In my first image BACKGROUND was WHITE and ROI was black. As per Image analyst idea i inverted the image and now i have got ROI has white now and Background as Black(Image Attached). Now, i am using ur code(as well as image analyst code) to get the area.
As u said, i will try DICOM header.Please look the attachment once and tell if it is correct or not? Thanks Rik.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 7월 17일
You need to invert your image so that your black region of interest is white. Then call sum() to get the number of pixels:
numberOfBlackPixels = sum(~binaryImage(:));
Or you can get a different area from a different method using bwarea(), which takes into account the shape of the boundary to get like half pixels or whatever:
numberOfBlackPixels = bwarea(~binaryImage);
Or you can use regionprops():
props = regionprops(~binaryImage, 'area');
numberOfBlackPixels = props.Area;
  댓글 수: 3
Image Analyst
Image Analyst 2019년 7월 18일
My answer is correct (Rik mistake was forgetting to invert the image, or else you said you wanted the black instead of the white after he answered) and the answer is in pixels. If you want to have the answer in cm or square cm you'll have to multiply by a factor, like
areaInCm = areaInPixels * cmPerPixel ^2;
See attached demo for a full example. If I helped you please Vote for or Accept the answer.
Ramanathan Anandarama Krishnan
Ramanathan Anandarama Krishnan 2019년 7월 18일
Hello Analyst,
Once again thanks a lot for helping me time and again in this. Your answers made me to work on this after i got struck for 2 days. However, i have very few doubts with respect to what u had said. I use the given code as follows:
C=regionprops(J,'Area')
I replace C instead of areaInpixels as per your guidance. However i get a error as undefined function or variable ''cmperpixel... Please help with respect to this.
And in the function u gave there is a undefined variable ''calibrate'. I know these doubts are very basic but since i am very new to matlab i request you to help me in this. I use matlab Version 2014a. Thanks a lot

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by