How to calculate standard deviation from ROI of image after thresholding?

3 ビュー (過去 30 日間)
hhh
hhh 2016 年 6 月 7 日
回答済み: DGM 2024 年 6 月 16 日
Hello, I have images and I use graythresh threshold to select object from the image. I want to get standard deviation of the pixel value from the ROI of the image. From regionprop, I can only get maxintensity, minintensity, meanintensity, pixelvalues, and weightedcentroid.
level=graythresh(I2);
BW=im2bw(I2,level);
figure, imshow(BW);
%ROI
L=bwlabel(BW);
s=regionprops(L,I2, 'MaxIntensity', 'MeanIntensity','MinIntensity','PixelValues');
max_I=s.MaxIntensity
min_I=s.MinIntensity
%average_I=s.MeanIntensity
pix_val=s.PixelValues;
M=max(max(L));
for i=1:M
sumAv(i)=s(i).MeanIntensity;
end
average_I=mean(sumAv)
I need to find standard deviation from the ROI. Can anyone help me to solve this. I've been looking for a way, unfortunately, I'm not very good with Matlab. This is my first time using it.
Thank you in advance.

回答 (1 件)

DGM
DGM 2024 年 6 月 16 日
You have the pixel values, so you can just use those.
% a grayscale image
inpict = imread('cameraman.tif');
% an antialiased mask with several blobs
mask = imread('cmanpolyblobs.png');
mask = mask>128; % we don't need the antialiasing
imshow(mask)
% get regionprops
S = regionprops(mask,inpict,'pixelvalues','meanintensity','centroid');
% these are represented in unit scale,
% that way the results are independent of the input class
nblobs = numel(S);
regionmu = im2double(cast(vertcat(S.MeanIntensity),class(inpict)));
regionsigma = zeros(nblobs,1);
for k = 1:nblobs
regionsigma(k) = std(im2double(S(k).PixelValues));
end
% create a composite image, and plot the blob stats
% so that we have some idea that they make sense
alph = im2double(mask);
BG = im2double(inpict);
comp = alph.*BG + 0.5*(1-alph).*BG;
imshow(comp); hold on
for k = 1:nblobs
c = S(k).Centroid;
ht = text(c(1),c(2),sprintf('mean:%.4f\nstd:%.4f',regionmu(k),regionsigma(k)));
ht.Color = 'k';
ht.HorizontalAlignment = 'center';
ht.BackgroundColor = 'r';
% the centroid of this blob isn't a good place to put the annotation
% so let's just move it over
if k == 1
ht.Position(1) = ht.Position(1) + 70;
end
end
Oh wow. That's a jumbled mess on the forum. Oh well.
Either way, we can see that the dark region on the coat is very smooth, and has a low standard deviation. The camera and face have a lot of contrast, and so the std is high. The grass and sky are in between.

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by