0% found this document useful (0 votes)
53 views2 pages

Matlab Restoration

This document contains MATLAB code to perform various image processing tasks: 1. Adding noise to images using imnoise and filtering noise using filters like average, median, and ordered filters. 2. Removing periodic noise from an image by taking the FFT, identifying noise spikes, and multiplying the FFT by an indicator function to remove the spikes before taking the inverse FFT. 3. Averaging multiple images with added Gaussian noise to reduce the noise. Taking the mean across images decreases the noise which appears as random variations across images.

Uploaded by

Tanthai Tanasuk
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

Matlab Restoration

This document contains MATLAB code to perform various image processing tasks: 1. Adding noise to images using imnoise and filtering noise using filters like average, median, and ordered filters. 2. Removing periodic noise from an image by taking the FFT, identifying noise spikes, and multiplying the FFT by an indicator function to remove the spikes before taking the inverse FFT. 3. Averaging multiple images with added Gaussian noise to reduce the noise. Taking the mean across images decreases the noise which appears as random variations across images.

Uploaded by

Tanthai Tanasuk
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name ………………………………………………… ID ………………………

1. Enter the following MATLAB commands and describe what each step does

Syntax What it does


Adding noises using imnoise(img,’type’)
>> t = imread(‘trees.tif’); Read the image tree.tif into variable t
>> t2 = t + 120; imview(t2);
>> sp1 = imnoise(t, ‘salt & pepper’);
>> imview(sp1);
>> sp2 = imnoise(t, ‘salt & pepper’, 0.2);
>> imview(sp2);
What does the parameter 0.2 do?
Find out its default value.
>> ga1 = imnoise(t, ‘gaussian’); imview(ga1);
>> ga2 = imnoise(t, ‘gaussian’, 2, 0.3);
>> imview(ga2);
What does the first parameter 2 refer to?
What does the second parameter 0.3 refer to?
Find out the default values of these parameters.
>> spk = imnoise(t, ‘speckle’); imview(spk);
Filtering
>> a7 = fspecial(‘average’, [7 7])
>> sp = im2double(sp1);
>> sp_a7 = filter2(a7, sp); imview(sp_a7);
>> a = fspecial(‘average’)
What is the default filter size?
>> sp_a = filter2(a, sp); imview(sp_a);
>> sp_m = medfilt2(sp); imview(sp_m);
>> sp2_m = medfilt2(sp2, [5 5]); imview(sp2_m)
>> sp2_o = ordfilt2( sp2, 3, [0 1 0; 1 1 1; 0 1 0] );
What does the parameter 3 refer to?
Perform a max filter on ga1
Perform a min filter on ga2
Name ………………………………………………… ID ………………………

2. Removing periodic noise


Syntax What it does
>> Load an image into a variable im
>> im = im2double(im);
>> sz = size(im);
>> [x y] = meshgrid(1:sz (2),1:sz(1));
>> p = ( 1+ sin(x+y / 1.5) )/2;
What is the range of p?
>> corrupted_im = (im + p)/2;
What is the range of corrupted_im?
>> spec = fftshift ( fft2(corrupted_im) );
>> log_spec = log(1+abs(spec));
>> figure; imagesc(log_spec); pixval;
Find out the locations of the noise spikes
Assign the coordinates of the noise
>> ns = [ ; ];
spikes
>> D1 = sqrt((x-ns(1,1)).^2 + (y-ns(1,2)).^2);
>> D2 = sqrt((x-ns(2,1)).^2 + (y-ns(2,2)).^2);
>> inrf = ~(D1 < r | D2 < r);
>> filtered_spec = spec.*inrf;
>> figure;
>> imagesc(log(1+abs(filtered_spec))); pixval
>> im_inrf = abs(ifft2(filtered_spec));

3. Image Averaging is another method to reduce zero-mean Gaussian noise if we


have several corrupted images at hand.
Syntax What it does
Load an image into a variable im
for i = 1:10
im_ga(:,:,i) = imnoise(im,‘gaussian’);
end
im_ga_av = mean(im_ga,3);
Calculate the mean square error (MSE)
Display the averaged image and
compare it to the original.

You might also like