フィルターのクリア

Why my value of MSE and PSNR have 3 values?

3 ビュー (過去 30 日間)
Atifah Samuri
Atifah Samuri 2021 年 12 月 30 日
編集済み: DGM 2021 年 12 月 31 日
My code is shown below:
InputImage=imread('ifa.jpg');
ReconstructedImage=imread('ifamedifilt.jpg');
n=size(InputImage);
M=n(1);
N=n(2);
MSE = sum(sum((InputImage-ReconstructedImage).^2))/(M*N);
PSNR = 10*log10(256*256/MSE);
fprintf('\nMSE: %7.2f ', MSE);
fprintf('\nPSNR: %9.7f dB', PSNR);
and these are the values:
MSE: 0.88
MSE: 7.45
MSE: 1.94
PSNR: 48.7440467 dB
PSNR: 39.4403644 dB
PSNR: 45.2839345 dB
First image is ifa.jpg and the next one is ifamedifilt.jpg

採用された回答

DGM
DGM 2021 年 12 月 31 日
編集済み: DGM 2021 年 12 月 31 日
The images are RGB. The results are 1x1x3 -- one result per channel.
If your goal were to get a single value for the whole image, you can do that.
MSE = sum((InputImage(:)-ReconstructedImage(:)).^2)/(M*N);
  2 件のコメント
Atifah Samuri
Atifah Samuri 2021 年 12 月 31 日
The images in RGB and the value have 3. If I use this code:
MSE = sum((InputImage(:)-ReconstructedImage(:)).^2)/(M*N);
Which value is used to get a single value?
How it operate?
DGM
DGM 2021 年 12 月 31 日
編集済み: DGM 2021 年 12 月 31 日
That's taking the MSE of all elements of the array when compared to the corresponding element in the other array. It does it by reshaping the arrays into vectors. You could do the same thing by doing
MSE = sum((InputImage-ReconstructedImage).^2,'all')/(M*N);
Either way, the point is to reduce the numerator to a scalar. It's not picking one particular channel, nor is it converting to grayscale. An error in the blue channel has the same weight as an error in red or green, which is not the case when doing luma conversion with rgb2gray(). It all depends what's desired.

サインインしてコメントする。

その他の回答 (1 件)

yanqi liu
yanqi liu 2021 年 12 月 31 日
編集済み: yanqi liu 2021 年 12 月 31 日
yes,sir,it is rgb type,may be use rgb2gray to make it gray type,such as
InputImage=double(rgb2gray(imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/848510/image.jpeg')));
ReconstructedImage=double(rgb2gray(imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/848515/image.jpeg')));
n=size(InputImage);
M=n(1);
N=n(2);
MSE = sum(sum((InputImage-ReconstructedImage).^2))/(M*N);
PSNR = 10*log10(256*256/MSE);
fprintf('\nMSE: %7.2f ', MSE);
MSE: 2.48
fprintf('\nPSNR: %9.7f dB', PSNR);
PSNR: 44.2200271 dB

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by