2017-05-08 104 views
1

我是圖像處理新手,並開始使用MATLAB進行天文攝影處理。我試圖用MATLAB處理土星行星的10個損壞的圖像(相同的圖像,但混有不同的噪聲)。我瞭解到,通過將10幅圖像疊加在一起可以產生高PSNR降噪圖像,並嘗試使用下面的代碼使其工作。圖像堆疊使用MATLAB降噪降噪

但輸出看起來像不清晰的飽和圖像,沒有降噪。

enter image description here

能否請你看看下面的代碼,並告訴我在哪裏我錯在哪裏?

%% 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); 

回答

1

我覺得這個說法非常說明了一切(重點煤礦):

但輸出看起來像沒有降噪不清楚飽和圖像。

它看起來像您的圖像實際上是在上限飽和一uint8變量,這是您的結果圖像resultIM和數據矩陣planetdata的數據類型。在不斷添加圖像時,對於無符號的8位整數類型,像素值飽和爲最大值255。

您需要做的是將中間計算轉換爲更大的數據類型,例如更大的integer typefloating point type。然後,一旦您的計算完成(例如,將總和除以圖像堆棧大小以獲得平均圖像),您可以根據需要縮放和/或四捨五入您的數據,並將其轉換回uint8類型。

+0

謝謝你的建議。我把它們改成了double,把它改回了uint8。我得到了很好的結果。 – ncbdrck

+0

@ncbdrck然後考慮接受答案 –