I have a question in image processing, this code shows how to add noise to the image and then retrieve it again ... The problem when retrieving the image error occurs and show the image that was retrieved in white

2 visualizaciones (últimos 30 días)
img = imread( ('eight.tif') ); % read image, use gray-level images here.
A = imnoise(img,'Gaussian',0,1);
IMG = fft2( img ); % Fourier of img
sz = size( img );
G = fspecial('gaussian' ,[5,5]); % create a filter with std sigma same size as img
%# Filter it
h = imfilter(A,G,'same');
H = fft2( h ); % Fourier of filter
F = IMG.*H; % filter in Fourier space
f = ifft2( F ); % back to spatial domain.
figure, imagesc(f);title('Gaussian filter in Frequency Domain')
figure,imshow(img),title('Original Image');
figure,imshow(A),title('Noisy Image');
imshow(f)
% Calculate MSE, mean square error.
img =im2double(img);
f =im2double(f);
[M N] = size(img);
error0 = img - f;
Mean_Square_Error = sum(sum(error0 .* error0)) / (M * N)
and the MSE must be less than one, but here greater than one ?

Respuesta aceptada

John BG
John BG el 16 de Sept. de 2017

Hi Ahmed

I have applied some changes to your code but perhaps you would like to consider using a different filter.

attached test567.m

1.

reference image

clear all;clc
img = imread( ('eight.tif') );      % read image, use gray-level images here. 
figure(1);imshow(img);title('Original Image')  % it's useful to mark references as early as possible

2.

really contaminated image

.

A = imnoise(img,'Gaussian',0,1); 
figure(2);imshow(A)title('Noisy Image')

.

.

IMG2 = fft2 ( img );                 % Fourier of img sz = size( img ) 
G = fspecial('gaussian' ,[5,5]) % create a filter with std sigma same size as img %# Filter it 
h = imfilter(A,G,'same')
H = fft2 ( h )                          % Fourier of filter 
F = IMG2.*H                          % filter in Fourier space 
f = ifft2( F )                           % back to spatial domain. 
f=f-min(min(f));
f=f*255/max(max(f));
figure(3); imagesc(f);title('Gaussian filter in Frequency Domain') 

.

Please note that min max values of the filter itself are really high, and the range between such min max is really narrow compared to the values of literally any pixel of the filter.

You may want a higher range.

.

figure(6); imshow(uint8(f))                   % Calculate MSE, mean square error. 

.

.

Mean_Square_Error =immse(img,f)
Mean_Square_Error =
   1.8836e+04

apparently command immse suggested by Image Analyst yields an error assessment way larger than applying Ahmed's error formula.

either im2double() on unit8 type or the other way round, or uint8() on double type both ways get to same error figure.

   [M N] = size(img)
  M =
     242
  N =
     308
   Mean_Square_Error2 = sum(sum(error0 .* error0)) / (M * N)
  Mean_Square_Error2 =
    208.7750
  error02 = im2double(img) - f;
  Mean_Square_Error3 = sum(sum(error0 .* error0)) / (M * N)
  Mean_Square_Error3 =
    208.7750

.

Ahmed

if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?

To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link

thanks in advance

John BG

jgb2012@sky.com

Más respuestas (1)

Image Analyst
Image Analyst el 8 de Sept. de 2017
Try
imshow(f, []);
Then you can move on to the several other errors in your code.
By the way, there is an immse() function you know.
  2 comentarios
Ahmed Grera
Ahmed Grera el 8 de Sept. de 2017
Hi Dr. Image Analyst
The MSE must be less than one, but here greater than one ?
Walter Roberson
Walter Roberson el 17 de Sept. de 2017
It is not good form to unaccept an Answer in favour of your own Answer. If posters decide that a different Answer is better then they can unaccept the original Answer themselves.
Unaccepting an Answer should seldom be done for an active question.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by