0% found this document useful (0 votes)
36 views15 pages

DIP Practical Program-1

The document outlines a practical program for various image processing techniques, including image enhancement, histogram equalization, image restoration, filtering, edge detection, compression, subtraction, boundary extraction, and segmentation. Each section provides a MATLAB program that demonstrates the specific technique along with the expected output. The programs utilize functions such as imread, imshow, imfilter, and others to manipulate and analyze images.

Uploaded by

Jinisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views15 pages

DIP Practical Program-1

The document outlines a practical program for various image processing techniques, including image enhancement, histogram equalization, image restoration, filtering, edge detection, compression, subtraction, boundary extraction, and segmentation. Each section provides a MATLAB program that demonstrates the specific technique along with the expected output. The programs utilize functions such as imread, imshow, imfilter, and others to manipulate and analyze images.

Uploaded by

Jinisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

DIP Practical Program

1.Implement image enhancement technique


Program:
I = imread('pepper.jpg');

imshow(I);

title('Original Image');

f = imadjust(I,stretchlim(I),[0 1]);

img_gray = rgb2gray(f);

se = strel('disk',12);

th_filtered = imtophat(img_gray,se);

figure;

imshow(th_filtered);

title('Top-Hat Filtered Image');

contrast_adjusted = imadjust(th_filtered);

figure;

imshow(contrast_adjusted);

title('Contrast Adjusted Image');

K = medfilt2(img_gray);

J = adapthisteq(K,'cliplimit',0.5);

H = fspecial('average',[8 3]);

f_avg = imfilter(J,H,'replicate');

contrast_adj_image = contrast_adjusted - 0.3*f_avg;

figure;

imshow(contrast_adj_image);

title('Final Processed Image');

Out put:
2.Histogram equalization
Program:

a=imread('apple2.jpg');
b=rgb2gray(a);

imshow(b);

imhist(b);

subplot(3,2,1),imshow(b);

subplot(3,2,2),imhist(b);

d=histeq(b);

subplot(3,2,3),imshow(d);

subplot(3,2,4),imhist(d);

Output:

3.Image restoration
Program:
I = imread('pepper.jpg');

grayImage = rgb2gray(I);

PSF = fspecial('motion', 20, 45);

blurredImage = imfilter(grayImage, PSF, 'conv', 'circular');

estimated_nsr = 0.001;
restoredImage = deconvwnr(blurredImage, PSF, estimated_nsr);

figure;

subplot(1, 3, 1); imshow(grayImage); title('Original Image');

subplot(1, 3, 2); imshow(blurredImage); title('Blurred Image');

subplot(1, 3, 3); imshow(restoredImage); title('Restored Image');

imwrite(restoredImage, 'restored_image.jpg');

out put:

4.Implement image filtering


Program:

img = imread('pepper.jpg');

f_avg = fspecial('average', 3);

img_avg = imfilter(img, f_avg);

subplot(2, 1, 1);

imshow(img);

title('Original Image');

subplot(2, 1, 2);

imshow(img_avg);

title('Average Filtered Image');


Out put:

5.Edge detection using operators(Roberts,prewits and


sobels operators)
Program:
I=imread('apple2.jpg');

subplot(3,2,1);

imshow(I);

title('Original Image');
G=rgb2gray(I);

subplot(3,2,2);

imshow(G);

title('Grayscale Image');

F=edge(G,'Prewitt');

subplot(3,2,3);

imshow(F);

title('Prewitt Image');

H=edge(G,'sobel');

subplot(3,2,4);

imshow(H);

title('Sobel Image');

J=edge(G,'Roberts');

subplot(3,2,5);

imshow(J);

title('Roberts Image');

out put:
6. Implement Image Compression
Program:
img = imread('apple2.jpg');

gray_img = rgb2gray(img);

img_double = im2double(gray_img);

[U, S, V] = svd(img_double);

k = 10;

compressed_img = U(:, 1:k) * S(1:k, 1:k) * V(:, 1:k)';

figure;

subplot(1, 2, 1);

imshow(img_double);

title('Original Image');

subplot(1, 2, 2);
imshow(compressed_img);

title(['Compressed Image (k = ' num2str(k) ')']);

OutPut:

7.image substraction
Program:
image1=imread('flower.jpg');

image2=imread('flower.jpg');

image1=double(image1);

image2=double(image2);

subtracted_image=image1-image2;

subplot(2,2,1);

imshow(uint8(image1));

title('flower.jpg');

subplot(2,2,2);
imshow(uint8(image2));

title('flower.jpg');

subplot(2,2,3);

imshow(uint8(subtracted_image));

title('subtracted image');

colormap(gca,'gray');

Output:

8.Boundary extraction using morphology


Program:
A=imread('apple2.jpg');

C=rgb2gray(A);

C(C<225)=0;
s=strel('disk',4,0);

D=~im2bw(C);

F=imerode(D,s);

figure,imshow(A);title('Original Image');

figure,imshow(D);title('Binary Image');

figure,imshow(D-F);title('Boundary ectracted Image');

Output:
9.Image segmentation
Program:
k = imread('Lena.jpg');

subplot(2, 4, 1);

imshow(k);

title('Original Image');

k1 = im2bw(k, graythresh(k));
subplot(2, 4, 2);

imshow(k1);

title('Gray Image');

SE = strel('disk', 7, 4);

k2 = max(k,[],3);

subplot(2, 4, 3 );

imshow(k2);

title('Masked Image');

k3 = imopen(k1, SE);

subplot(2, 4, 4);

imshow(k3);

title('Opened Image');

b = bwlabel(k3);

subplot(2, 4, 5);

imshow(b, []);

title('Labeled Image');

b(b ~= 9) = 0;

subplot(2, 4, 6);

imshow(b, []);

title('Region of Interest');

k4 = imclose(b, strel('disk', 18));

subplot(2, 4, 7);

imshow(k4);

title('Closed Image');

Output:

You might also like