How to find number of pixels (or matrix count) in a group in a given imagesc or data
19 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I need a help to find all the number of pixels present in the data. I have attached the data and the imagesc of it. The data contains the height information of pixel. I have already updated the data according to my requirement by limiting the height value and change to 'nan'.
The blue represents the 'Nan' and the yellow represents the heights that are accepted. As marked in the imagesc figure, i need a new array that will store value like 2,1,1,1,11,5,3,3,... each represents the group of pixels includig single pixel.
Please look at the attached data.xlsx and help me to find, how to get the output as i am expecting.
0 个评论
采纳的回答
Dave B
2021-12-20
There are a few functions for finding little regions like this, but if you have the Image Processing Toolbox you might consider regionprops, which works well for htis kind of problem.
a=readmatrix('data.xlsx');
b=regionprops(~isnan(a),'Area','PixelIdxList');
% Area gives the number of pixels in a region
b(1).Area
b(2).Area
b(3).Area
% PixelIdxList is good if you want to go back to the original image and see
% what was in there (other than that it wasn't NaN)
a(b(1).PixelIdxList)
a(b(2).PixelIdxList)
a(b(3).PixelIdxList)
0 个评论
更多回答(1 个)
Image Analyst
2021-12-20
Don't use nan. To find the number of non-zero pixels set all your nans to 0 and use nnz
grayImage(isnan(grayImage)) = 0; % Make Nan's equal to zero.
numNonZeroPixels = nnz(grayImage)
To get the area and intensity of each 4-connected blob, do this:
labeledImage = bwlabel(grayImage > 0, 4);
props = regionprops(labeledImage, grayImage, 'Area', 'MeanIntensity');
allAreas = [props.Area];
allIntensities = [props.MeanIntensity];
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!