KEMBAR78
DIP Lab final manual | PDF | Algorithms | Recording
0% found this document useful (0 votes)
5 views21 pages

DIP Lab final manual

digital imagr processing lab report

Uploaded by

P Sakthikumar
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)
5 views21 pages

DIP Lab final manual

digital imagr processing lab report

Uploaded by

P Sakthikumar
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/ 21

Ex No:01

IMAGE ENHANCEMENT
Date:

Aim:
To enhance the quality of an image using MATLAB by improving its visual
appearance or highlighting important features.

Procedure:
1. Start MATLAB and load the input image using imread().

2. Convert the image to grayscale if it is RGB.

3. Apply an enhancement technique such as contrast stretching or intensity

adjustment using imadjust() or histeq().

4. Display both the original and enhanced images using imshow().

5. Save and run the program.

6. Compare the visual quality before and after enhancement.

7. Display the result.

1
Program:

I=imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\baby.jpg');
figure
imshow(I);
title('original image')

figure
j=imresize(I,0.3);
imshow(j);
title('resized image')

figure
j=imcomplement(I);
imshow(j);
title('Negative Image')

figure
K=imrotate(I,60);
imshow(K);
title('Rotated Image')

2
Ex No:02
HISTOGRAM EQUALIZATION
Date:

Aim:

To improve the contrast of an image using histogram equalization in MATLAB.

Procedure:

1. Start MATLAB and load the image.

2. Convert the image to grayscale.

3. Use imhist() to display the original image histogram.

4. Apply histogram equalization using histeq().

5. Save and run the program.

6. Display the original and processed images along with their histograms.

7. Display the result.

4
Program:

I = imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\baby.jpg');
figure
imshow(I);
title('Original image');

g = rgb2gray(I);
figure
subplot(4,2,1);
imshow(g);
title('Gray image');

% Histogram and Histogram Equalization


subplot(4,2,3);
imhist(g);
title('Histogram of gray image');

m = histeq(g);
subplot(4,2,4);
imhist(m);
title('Histogram of equalized image');

subplot(4,2,2);
imshow(m);
title('Equalization Image');

5
Ex No:03
IMAGE RESTORATION
Date:

Aim:
To restore a degraded image using MATLAB by reducing noise or distortion.

Procedure:

1. Load the degraded image in MATLAB.

2. Identify the type of degradation (motion blur, Gaussian noise, etc.).

3. Apply a suitable restoration filter (e.g., Wiener filter using deconvwnr()).

4. Compare the restored image with the degraded one.

5. Save and run the program.

6. Display results side by side.

7. Display the result.

7
Program:

I=im2double(imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\cb.jp
eg'));
figure
imshow(I);
title('Original Image');

% create PSF for motion blur


psf = fspecial('motion'); % Point Spread Function

% Apply motion blur


blur = imfilter(I, psf, 'circular');
figure
imshow(blur);
title('Blurred Image');

% add noise
noise = blur + 0.005 * randn(size(I));
figure
imshow(noise);
title('Blurred & Noisy Image');

% Restore image using Wiener filter


Restore = deconvwnr(blur, psf);
figure
imshow(Restore);
title('Restored Image');

8
Ex No:04
IMAGE FILTERING
Date:

Aim:
To perform image filtering in MATLAB for noise reduction or feature
enhancement.

Procedure:

1. Load the image into MATLAB.

2. Select the type of filter (mean, median, Gaussian, etc.).

3. Use MATLAB functions like imfilter() or medfilt2() to apply the filter.

4. Save and run the program.

5. Display the original and filtered images.

6. Observe changes in noise and details.

7. Display the result.

10
Program:

i = im2double(imread('C:\Users\LENOVO\OneDrive\
Documents\MATLAB\img\ep.jpeg'));
% Implement Image Filter
g = rgb2gray(i);
subplot(3, 3, 1);
imshow(g);
title('Original Gray Image');
% Add Gaussian noise to simulate a noisy image
noise = imnoise(g, 'gaussian'); % Gaussian noise
subplot(3, 3, 2);
imshow(noise);
title('Gaussian Noise Image');

% 1. Mean Filter
mean = fspecial('average');
x = imfilter(noise, mean);
subplot(3, 3, 3);
imshow(x);
title('Mean Filtered Image');

% 2. Gaussian Filter
gaussian = fspecial('gaussian');
y = imfilter(noise, gaussian);
subplot(3, 3, 4);
imshow(y);
title('Gaussian Filtered Image');

11
% 3. Median Filter
median = medfilt2(noise);
subplot(3, 3, 5);
imshow(median);
title('Median Filtered Image');

Output:

Result:
Thus, the above program has been executed and verified successfully.

12
Ex No:05
EDGE DETECTION USING OPERATORS
Date:

Aim:
To detect edges in an image using Roberts, Prewitt, and Sobel operators in
MATLAB.

Procedure:

1. Load the grayscale image into MATLAB.

2. Apply Roberts operator using edge(I, 'roberts').

3. Apply Prewitt operator using edge(I, 'prewitt').

4. Apply Sobel operator using edge(I, 'sobel').

5. Save and run the program.

6. Display the edge-detected images for comparison.

7. Display the result.

13
Program:

img = imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\pi.jpeg');
g = rgb2gray(img);

operators = {
{'Roberts', [-1 0; 0 1], [0 1; -1 0]}
{'Prewitt', [-1 0 1; -1 0 1; -1 0 1], [-1 -1 -1; 0 0 0; 1 1 1]}
{'Sobel', [-1 0 1; -2 0 2; -1 0 1], [-1 -2 -1; 0 0 0; 1 2 1]}
};

subplot(2,2,1);
imshow(img);
title('Original Image');

for i = 1:size(operators, 1)
name = operators{i}{1};
a = operators{i}{2};
b = operators{i}{3};

x = conv2(g, a, 'same');
y = conv2(g, b, 'same');
z = sqrt(x.^2 + y.^2);

subplot(2,2,i+1);
imshow(z, []);
title([name ' Edge Detection']);
end

14
Ex No:06
IMAGE COMPRESSION
Date:

Aim:
To compress an image in MATLAB to reduce its size without significant loss of
quality.

Procedure:

1. Load the image into MATLAB.

2. Convert the image to a suitable format for compression.

3. Use transform coding methods (e.g., DCT using dct2() and idct2()).

4. Reconstruct the compressed image.

5. Save and run the program.

6. Compare sizes and quality of original vs. compressed images.

7. Display the result.

16
Program:

% Image Compression (Singular Value Decomposition)


A=
rgb2gray(imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\car.jpe
g'));

[L, D, R] = svd(double(A)); % SVD decomposition

k = 50; % Number of singular values to retain

% Reconstruct compressed image using top-k singular values


X = uint8(L(:,1:k) * D(1:k,1:k) * R(:,1:k)');

% Display original image


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

figure;

% Display compressed image


imshow(X);
title('Compressed Image');

17
Output:

Result:
Thus, the above program has been executed and verified successfully.

18
Ex No:07
IMAGE SUBTRACTION
Date:

Aim:
To subtract one image from another using MATLAB for change detection.

Procedure:

1. Load two images of the same size into MATLAB.

2. Convert to grayscale if needed.

3. Use simple subtraction: result = imsubtract(I1, I2).

4. Save and run the program.

5. Display the original images and the subtracted result.

6. Highlight areas of change.

7. Display the result.

19
Program:

% Subtract background from original image


I = imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\rise.jpg'); %
Read input image

bg = imopen(I, strel('disk', 20));


J = imsubtract(I, bg);

subplot(1,2,1);
imshow(I);
title('Original Image');

subplot(1,2,2);
imshow(J);
title('Subtracted Image');

20
Output:

Result:
Thus, the above program has been executed and verified successfully.

21
Ex No:08
BOUNDARY EXTRACTION
Date:

Aim:
To extract the boundary of an object from an image using morphological
operations in MATLAB.

Procedure:

1. Load the binary image into MATLAB.

2. Perform erosion using imerode() with a suitable structuring element.

3. Subtract the eroded image from the original to get the boundary.

4. Save and run the program.

5. Display both original and boundary images.

6. Compare the results visually.

7. Display the result

22
Program:

% Read and convert to grayscale


I = imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\pi.jpeg');
gray = rgb2gray(I);
% Convert to binary (for older MATLAB versions)
bw = im2bw(gray, graythresh(gray)); % Use Otsu's method

% Define structuring element


SE = strel('disk', 1);
% Erode the binary image
eroded = imerode(bw, SE);
% Subtract eroded image from original binary image to get boundary
boundary = bw - eroded;

% Display result
subplot(2,2,1);
imshow(I);
title('Original RGB Image');
subplot(2,2,2);
imshow(bw);
title('Binary Image');
subplot(2,2,3);
imshow(eroded);
title('Eroded Image');
subplot(2,2,4);
imshow(boundary);
title('Extracted Boundary');

23
Ex No:09
IMAGE SEGMENTATION
Date:

Aim:
To segment an image into meaningful regions using MATLAB.

Procedure:

1. Load the image into MATLAB.

2. Convert it to grayscale if needed.

3. Choose a segmentation technique (thresholding, clustering, watershed, etc.).

4. Apply the segmentation method (e.g., imbinarize() for thresholding).

5. Save and run the program.

6. Display the segmented image alongside the original.

7. Display the result.

25
Program:

% Load image
I = imread('C:\Users\LENOVO\OneDrive\Documents\MATLAB\img\pen.jpeg');
% Include file extension
gray = rgb2gray(I); % Convert to grayscale
subplot(2, 2, 1);
imshow(I);
title('Original Image');

% Apply thresholding using im2bw for older versions


thresh = graythresh(gray); % Otsu's method
bw = im2bw(gray, thresh); % Convert grayscale to binary

% Remove noise
bw = bwareaopen(bw, 100); % Remove small objects
subplot(2, 2, 2);
imshow(bw);
title('Segmented Image');

26

You might also like