我是图像处理的新手,并开始使用MATLAB进行天文摄影处理。我正在尝试使用MATLAB处理土星行星的10个损坏的图像(相同的图像但混合了不同的噪声)。我了解到,通过将10张图像叠加在一起可以获得具有高PSNR的降噪图像,并尝试使用以下编码使其工作。
但输出看起来像是一个不清晰的饱和图像,没有降噪。
你能看一下下面的代码并告诉我哪里出错了吗?
%% We are going to stack the 10 corrupted images and finally calculate the PSNR SSIM
clearvars;% Clear all the variables
close all;
load('planetdata.mat'); %to load the corrupted Image set (4-D uint8)
Clean = imread('Clean Image of Saturn.jpg');%Clean Image of Saturn.600x800x3 uint8
planet1(: , :, :) = planetdata(1, :, :, :);%One corrupted Image as reff
% Set the number of images to stack is 10
stack_number = 10;
% Lets use Clean image as reference of dimensions required
im_x = size(Clean, 1);
im_y = size(Clean, 2);
im_z = size(Clean, 3);
% Lets Generate a blank image for image stacking
resultIM = uint8(zeros(im_x, im_y, im_z));
% Iterate through the images to stack
for i = 1:1:stack_number
% Read in the target object image
CorruptIM(: , :, :) = planetdata(i, :, :, :);
% Perform image stacking using the target object image
resultIM = resultIM + CorruptIM;
end
% resultIM = resultIM / stack_number;
%% Lets Display Results
workspace; % to Make sure the work space panel is showing.
fontSize = 15;
figure;
subplot(1, 3, 1);
imshow(Clean);
title('Clean Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Give a name to the title bar.
set(gcf,'name','Stacking','numbertitle','off')
% Display one corrupt image as reference
subplot(1, 3, 2);
imshow(planet1);
title('Corrupt Image 1 : Ref', 'FontSize', fontSize);
% Display Stacked image
subplot(1, 3, 3);
imshow(resultIM);
title('Stacked Image', 'FontSize', fontSize);
%% PSNR AND SSIM Calculation
%Lets Find PSNR for For Resultant Image
[row,col] = size(Clean);
size_host = row*col;
o_double = double(Clean);
w_double = double(resultIM);
s=0;
for j = 1:size_host % the size of the original image
s = s+(w_double(j) - o_double(j))^2 ;
end
mes =s/size_host;
psnr =10*log10((255)^2/mes);
fprintf('The PSNR value for Stacked Image is %0.4f.\n',psnr);
%Lets Find SSIM for resultant Image
[ssimval, ssimmap] = ssim(uint8(resultIM),Clean);
fprintf('The SSIM value for Stacked Image is %0.4f.\n',ssimval);
答案 0 :(得分:1)
我认为这一句话几乎都说明了(强调我的):
但输出看起来像一个不清晰的饱和图像,没有降噪。
看起来您的图片实际上是uint8
变量的上限饱和,integer type变量是结果图片resultIM
和数据矩阵planetdata
的数据类型。在不断添加图像时,对于无符号8位整数类型,像素值的最大值为255。
您需要做的是转换为更大的数据类型以进行中间计算,例如较大的floating point type或https://angular.io/docs/ts/latest/guide/universal.html。然后,一旦您的计算完成(例如将总和除以图像堆栈大小以获得平均图像),您可以根据需要缩放和/或舍入数据并将其转换回uint8
类型。