standard deviation of image

I have a 3-dimensional image (image1) and a 2-dimensional image (image2) with values from 1 to 7 and want to find the standard deviation for specific values. I'm using the following code to calculate the mean value but dont know how to calculate the standard deviation. Any suggestion please?
for i=1:3
x=image1(:,:,i)
for j=1:7
L = bwlabel(image2==j);
STATS = regionprops(L,x,'MeanIntensity','Area','PixelValues');
n_stats = size(STATS,1);
area_=zeros(n_stats,1);
mean_=zeros(n_stats,1);
[m1,n1] = find(cat(1,STATS.Area) >=5);
for ii=1:n_stats
mean_(ii)=STATS(ii,:).MeanIntensity;
end
mean1=mean_(m1);
mean2(j,i)=mean(mean1);
end

답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 12월 9일

0 개 추천

You can use regionprops to calculate the various fields requested of each label in a label image, e.g.:
A = uint8(rand(10)*10); %random label image
STATS = regionprops(A,'area');
areas = [STATS(:).Area]
And I don't understand what you want the standard deviation of. If youu want it of all objects with the same value, won't it be zero? Clarify your goal, I guess. (and look at stdfilt)

댓글 수: 4

Walter Roberson
Walter Roberson 2011년 12월 9일
Ah, that confused me as well, but I now see that the "2-dimensional image with values from 1 to 7" does not necessarily imply that the original image is solid color in those areas. Each of the areas in the 2D image acts as a mask to be applied to the 3D image.
Image Analyst
Image Analyst 2011년 12월 9일
No it won't be zero because he's passing in the (badly named) original image x, so the pixel values of the blob will be those of the original image, not the labeled binary image.
Hassan
Hassan 2011년 12월 10일
Thanks Sean for the comment. As I said I have 2 images, image 1 is a 3-dimensional image and image 2 is a categorised 2-dimensional image with values 1 to 7. I want to find the standard deviation of the pixels values from image 1 that has a value of 1 (and then 2, 3,4 ,..,7) in image 2.
Hassan
Hassan 2011년 12월 10일
Sorry guys for not desribing the problem clearly. You are right Walter 'Each of the areas in the 2D image acts as a mask to be applied to the 3D image.'
thats right Image Analyst.

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

Image Analyst
Image Analyst 2011년 12월 9일

0 개 추천

I don't have MATLAB on this computer so I can't test but I believe it would be something like
pixelValues = [STATS(k).PixelValues];
sd = std(pixelValues(:)); % StDev of kth blob
or something like that.

댓글 수: 3

Hassan
Hassan 2011년 12월 10일
What is 'k' in STATS(k)?
Image Analyst
Image Analyst 2011년 12월 10일
That's the kth region. You'd have it in a loop over all k, all possible blob numbers, like
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, grayImage, 'PixelValues');
sd = zeros(1, numberOfBlobs);
for k = 1 : numberOfBlobs
pixelValues = [STATS(k).PixelValues];
sd(k) = std(pixelValues(:)); % StDev of kth blob
end
Hassan
Hassan 2011년 12월 10일
I couldnt run the code. I got the following error messageç
??? Error using ==> bwlabel
Too many input arguments.
I think binary image should be the 2'dimensional categorized image and gray image should be the 3'dimensional image.
[labeledImage, numberOfBlobs] = bwlabel(image 2, image 1, 'PixelValues');
sd = zeros(1, numberOfBlobs);
for k = 1 : numberOfBlobs
pixelValues = [STATS(k).PixelValues];
sd(k) = std(pixelValues(:)); % StDev of kth blob
end

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

질문:

2011년 12월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by