HOW TO IDENTIFY MEAN AND STANDARD DEVIATION FOR THIS CODE?

1 次查看(过去 30 天)
Read image by its file name
I = imread('.');
I=imresize(I,[256 256]);
I=im2double(I);
imshow(I)
% Convert RGB to HSV
img1=rgb2hsv(I);
figure(), subplot(2, 2, 1), imshow(I), title('Original')
subplot(2, 2, 2), imshow(img1(:,:,1)), title('Hue'), colorbar
subplot(2, 2, 3), imshow(img1(:,:,2)), title('Saturation'), colorbar
subplot(2, 2, 4), imshow(img1(:,:,3)), title('Value of Brightness'), colorbar
H=img1(:,:,1).*255;
S=img1(:,:,2).*255;
V=img1(:,:,3).*255;
% H(:,:,1) = H(:,:,1) * 2.5;
% min. and max value of hsv
Hmin = min(H(:));
Smin = min(S(:));
Vmin = min(V(:));
Hmax = max(H(:));
Smax = max(S(:));
Vmax = max(V(:));
%Set the hue value to zero if it
%less than 50 or great than 150
H((H < 50) | (H > 150)) = 0;
%Set the hue value of wheat straw
% pixel to zero
H(H > 49 & H < 60 & S > 5 & S < 50 & V > 150) = 0;
%Thresholding
T = 49; %T can be any value in [1, 49]
t = T./255;
BW = im2bw(H, t);
%Delete the objects less than 100 pixels
BW = bwareaopen(BW, 100);
%Show the identification result
figure, imshow(BW);
% Calculate the area, in pixels, of binary image.
numberOfPixels1 = sum(BW(:));
% Another way to calculate it that takes fractional pixels into account.
numberOfPixels2 = bwarea(BW);
% CALCULATE PARAMETERS
I =rgb2gray(I);
I=double(I);
BW =(BW);
% % % Find the mean squared error
mse = sum((I(:)-BW(:)).^2) / numel(I);
%
% % % now find the psnr, as peak=255
psnr = 10*log10(255*255/mse);
  3 个评论
tashu Dabariya
tashu Dabariya 2019-6-17
% CALCULATE PARAMETERS
I =rgb2gray(I);
I=double(I);
BW =(BW);
% % % Find the mean squared error
mse = sum((I(:)-BW(:)).^2) / numel(I);
%
% % % now find the psnr, as peak=255
psnr = 10*log10(255*255/mse)
is it right way to calculatet psnr and mse?
for mean and std variable might be I and BW

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2019-6-17
编辑:Adam Danz 2019-6-17
It looks like you want to calculate the mean squared error between the I and BW arrays which can be done using immse() from the image processing toolbox.
err = immse(I,double(BW));
  3 个评论
Adam Danz
Adam Danz 2019-6-17
I saw in your code, you converted I to double: I=double(I); In my answer, I also converted BW to double which would avoid that error.
Adam Danz
Adam Danz 2019-6-17
编辑:Adam Danz 2019-6-17
tashu, this is a different question than what you started with and I suggest writing a new question with a more focused title so it attracts experts in this area.
Also, providing code is a big help but please format it by using the format buttons while your editing the question. I've formatted your code so far but it saves us some time if you do it yourself. Thanks.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by