0% found this document useful (0 votes)
7 views7 pages

Tutorial 2

The document outlines several image processing programs using MATLAB, including image restoration via inverse filtering, color approximation, quantization, smoothing and sharpening, morphological operations, image segmentation, and edge detection. Each program includes code snippets and descriptions of the operations performed on images. Some outputs indicate issues with Octave compatibility.

Uploaded by

paulbogale
Copyright
© © All Rights Reserved
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)
7 views7 pages

Tutorial 2

The document outlines several image processing programs using MATLAB, including image restoration via inverse filtering, color approximation, quantization, smoothing and sharpening, morphological operations, image segmentation, and edge detection. Each program includes code snippets and descriptions of the operations performed on images. Some outputs indicate issues with Octave compatibility.

Uploaded by

paulbogale
Copyright
© © All Rights Reserved
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/ 7

Program-5: Write a program, for Image restoration using Inverse Filtering

a. Facial Image
b. Texture Image
Code:
oriImg1 = imread('dog.jpg');
blurImg1 = imread('monalisa.jpg');
ori_fft1 = fft2(im2double(oriImg1));
blur_fft1 = fft2(im2double(blurImg1));
H1 = blur_fft1./ ori_fft1;
G1 = 1./H1;
rec_fft1 = blur_fft1 .* G1;
rec_inverse1 = real(ifft2(rec_fft1));
oriImg2 = imread(' C:\Users\MaxProUltra\Desktop\Code\p1.jpg');
blurImg2 = imread(' C:\Users\MaxProUltra\Desktop\Code\test2.jpg');
ori_fft2 = fft2(im2double(oriImg2));
blur_fft2 = fft2(im2double(blurImg2));
H2 = blur_fft2./ ori_fft2;
G2 = 1./H2;
rec_fft2 = blur_fft2 .* G2;
rec_inverse2 = real(ifft2(rec_fft2));
figure
subplot(2,3,1),imshow(oriImg1),title('original image');
subplot(2,3,2),imshow(blurImg1),title('blurred image');
subplot(2,3,3),imshow(rec_inverse1),title('Recovered by inverse filter');
subplot(2,3,4),imshow(oriImg2),title('original image');
subplot(2,3,5),imshow(blurImg2),title('blurred image');
subplot(2,3,6),imshow(rec_inverse2),title('Recovered by inverse filter');
Output:
Octave not working for me.

Program-6: Write a program for color image processing


a. Color approximation

Segni Guta91900103158TC3
b. Quantization
Program Code: Color Approximation
RGB = imread('C:\Users\MaxProUltra\Desktop\Code\MatLab\test2.png');
subplot(1,2,1),imshow(RGB);
title('Original Image')
[X,map] = rgb2ind(RGB, 8);
subplot(1,2,2),imshow(X, map);
title('Reduced Number of Color');
Program Output: Color Approximation

Program Code: Quantization


img = imread('C:\Users\MaxProUltra\Desktop\Code\MatLab\test2.png');
subplot(1,2,1), imshow(img)
title('Original Image')
Qimg = floor(img ./ (256/128)); %128 Level
subplot(1,2,2), imshow(Qimg);
title('Quantized Image');

Segni Guta91900103158TC3
Output:

Program-7: Write a program for smoothening and sharpening for 8-


bit color image.
Program Code:
img = imread('C:\Users\MaxProUltra\Desktop\Code\MatLab\test2.png');
subplot(1,3,1), imshow(img);
title('Original Image');
smthImg = imgaussfilt(img,1);
subplot(1,3,2), imshow(smthImg);
title('Smoothed Image');
shrpImg = imsharpen(img,'radius',8);
subplot(1,3,3), imshow(shrpImg);
title('Sharpened Image');

Segni Guta91900103158TC3
Program Output:

Program-8: Write a program to implement morphological operations.


Program Code:
img = imread('C:\Users\MaxProUltra\Desktop\Code\MatLab\test2.png');
subplot(1,3,1), imshow(img);
title('Original Image');
se = strel('line',21,89);
Erode = imerode(img, se);
subplot(1,3,2), imshow(Erode);
title('Erode Image');
Dilate = imdilate(img, se);
subplot(1,3,3), imshow(Dilate);
title('Dilate Image');

Output:

Segni Guta91900103158TC3
Program-9: Write a program for image segmentation
a. Local thresholding
b. Global thresholding
Program Code:

img = imread('dog.jpg');
subplot(1,3,1), imshow(img);
title('Original Image');
ltImg = adaptthresh(img, 0.1);
subplot(1,3,2), imshow(ltImg);
title('Local Adaptive Threshold');
f = im2uint8(img);
count =0;
T = mean2(f);
done = false;
while ~done
count = count +1;
g = f > T;

Segni Guta91900103158TC3
Tnext = 0.5*(mean(f(g)) +mean(f(~g)));
done = abs(T -Tnext)<0.5;
T = Tnext;
end
gtImg = im2bw(f, T/255);
subplot(1,3,3), imshow(gtImg);
title('Global Threshold');

Output: Octave not working for me.


Program-10: Write a program for edge detection.
Program Code:
img = imread('C:\Users\MaxProUltra\Desktop\Code\MatLab\test2.png');
subplot(1, 3, 1);
filterImg = rgb2gray(img);
imshow(filterImg);
title('Original Image');
prewittImg = edge(filterImg, 'prewitt');
subplot(1, 3, 2);
imshow(prewittImg);
title('Prewitt Edge Detection');
soberImg = edge(filterImg, 'sobel');
subplot(1, 3, 3);
imshow(soberImg);
title('Sober Edge Detection');

Program Output:

Segni Guta91900103158TC3
Segni Guta91900103158TC3

You might also like