regionprops and standard deviation (binary image)

Hi everyone, i am using the function" regionprops" to get the largest perimeter in my binary image. I have got the value of the largest perimeter but still need to have its standard deviation. Does anyone know how to get this std? Thank you very much

 채택된 답변

Walter Roberson
Walter Roberson 2018년 1월 26일

0 개 추천

When you do the regionprops() also ask for 'PixelIdxList' . When you find the region with the largest perimeter, extract its PixelIdxList. Use that PixelIdxList to index the 2D image, and take std() of the pixels that are returned.
If your original image was color, then sometimes the easiest is to break it into 3 variables and use PixelIdxList on each. That is not the only way, but it is easy to understand whereas the conversion of 2D linear indices to appropriate 3D indices can be a bit tricky to understand.

댓글 수: 5

I appreciate your help in this matter.
I have written the following code:
s = regionprops(binaryimage,'PixelIdxList','Perimeter')% original image is not a color image
allPerimeters =[s.Perimeter]% all perimeters in this binary image
largestPerimeterIs=allPerimeters(1); % the largest perimeter value is the first value in allPerimeters
for k = 1:NumObjects
s(k).RegionNumber = mode(single(originalImage(s(k).PixelIdxList(1))));
end
region_vector = [s.RegionNumber]
How can i extract the PixelIdxList of the region with the largest perimeter in order to apply the std of all those returned pixels?
Thank you again
originalImage(s(k).PixelIdxList(1)) is going to be a scalar value, so I do not understand why you would mode() it?
"How can i extract the PixelIdxList of the region with the largest perimeter"
[~, objidx] = max(allPerimeters);
std( double(OriginalImage(s(objidx).PixelIdxList)) )
by trying the following code, std is equal to 0. What shall i change in the "std(double(OriginalImage(s(objidx).PixelIdxList)))"?
s = regionprops(binaryimage,'all')
[~, objidx] = max(allPerimeters);
std(double(OriginalImage(s(objidx).PixelIdxList)))
thank you
s = regionprops(binaryimage,'all')
[~, objidx] = max(allPerimeters);
obj_pixels = OriginalImage(s(objidx).PixelIdxList);
if length(unique(obj_pixels)) == 1
sprintf('all pixels in the object are exactly the same! All of them have value %d\n', obj_pixels(1));
else
std(double(obj_pixels))
end
Depending how your image was constructed and how you are constructing your binary image, the situation could either be an improbable coincidence or something to be expected. You could post your image and your code that creates the binary image for us to examine.
Thank you

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

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 1월 30일

0 개 추천

You can get the standard deviation of the gray levels in the blob with the largest perimeter more directly (than by using PixelIdxList) like this:
% Get blob with largest perimeter.
binaryImage = bwpropfilt(binaryImage, 'Perimeter', 1);
% Get standard deviation of pixels in that blob
stdGrayLevels = std(double(grayImage(binaryImage)))

댓글 수: 1

Thank you for your help. I prefer to use the above code in my case. i have tried your code but it did not work.

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

질문:

2018년 1월 26일

댓글:

2018년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by