How to run the same code for color any one help me.

조회 수: 3(최근 30일)
indrani dalui
indrani dalui 2019년 3월 29일
답변: Mrutyunjaya Hiremath 2020년 5월 6일
%------ GET DEMO IMAGES ----------------------------------------------------------
% Read in a standard MATLAB gray scale demo image.
RGBImage = imread('experimental.JPG');
[rows columns] = size(RGBImage);
% Display the first image.
subplot(2, 2, 1);
imshow(RGBImage, []);
title('Original RGB Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Get a second image by adding noise to the first image.
noisyImage = imnoise(RGBImage, 'gaussian', 0, 0.003);
% Display the second image.
subplot(2, 2, 2);
imshow(noisyImage, []);
title('Noisy Image', 'FontSize', fontSize);
%------ PSNR CALCULATION ----------------------------------------------------------
% Now we have our two images and we can calculate the PSNR.
% First, calculate the "square error" image.
% Make sure they're cast to floating point so that we can get negative differences.
% Otherwise two uint8's that should subtract to give a negative number
% would get clipped to zero and not be negative.
squaredErrorImage = (double(RGBImage) - double(noisyImage)) .^ 2;
% Display the squared error image.
subplot(2, 2, 3);
imshow(squaredErrorImage, []);
title('Squared Error Image', 'FontSize', fontSize);
% Sum the Squared Image and divide by the number of elements
% to get the Mean Squared Error. It will be a scalar (a single number).
mse = sum(sum(squaredErrorImage)) / (rows * columns);
% Calculate PSNR (Peak Signal to Noise Ratio) from the MSE according to the formula.
PSNR = 10 * log10( 256^2 / mse);
% Alert user of the answer.
message = sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', mse, PSNR);


Mrutyunjaya Hiremath
Mrutyunjaya Hiremath 2020년 5월 6일
Try the attached file.

Community Treasure Hunt

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

Start Hunting!

Translated by