0% found this document useful (0 votes)
6 views

Image Processing Lab

The document outlines a series of experiments conducted in an Image Processing Lab, detailing various image processing techniques implemented using MATLAB. Each experiment includes an aim, algorithm, source code, and results, covering topics such as mirror image creation, filtering methods, image segmentation, and edge detection. The document serves as a comprehensive guide for students to understand and apply image processing concepts practically.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Image Processing Lab

The document outlines a series of experiments conducted in an Image Processing Lab, detailing various image processing techniques implemented using MATLAB. Each experiment includes an aim, algorithm, source code, and results, covering topics such as mirror image creation, filtering methods, image segmentation, and edge detection. The document serves as a comprehensive guide for students to understand and apply image processing concepts practically.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

IMAGE PROCESSING LAB

IMAGE PROCESSING LAB APRIL 2025

S.NO DATE PROGRAM NAME PAGENO

1. CREATION OF MIRROR IMAGE 03

2. ARITHMETIC MEAN FILTER 06

3. GEOMETRIC MEAN FILTER 09

4. BLURRED IMAGE 12

5. DE-BLURRED IMAGE 14

6. IMAGE MORPHOLOGY 17

7. SALT AND PEPPER METHOD 20

8. IMAGE SEGMENTATION 23

9. IMAGE EDGE DETECTION 27

10. IMAGE RGB COLOUR 29

11. BOUNDARY EXTRACTION 33


ALGORITHM

12. IMAGE AND ITS HISTOGRAM 35

13. IMAGE RESTORATION 37

14. CLOCKWISE IMAGE 40

15. DOUBLE-SIZE IMAGE 43

16. ZOOMING AN IMAGE 46

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:01
CREATION OF MIRROR IMAGE

AIM:
To implement the spatial image enhancement functions on a bitmap image – mirroring
(Inversion) using Mathlab Compiler.

ALGORITHM:

1) Start the Program.


2) Open Octave Online-Compiler (Cloud IDE Compatible with MATHLAB).
3) Create new File and Save the file with extension .m.
4) Declare variables ‘img’ for storing the image data,’x’,’y’,’z’for dimensions,’plane’for
iterating through color planes,’i’ for rows,’j’ for columns,and ‘len’ for storing the
length of each row.
5) Loop through each color plane and iterative over each pixel in the image.
6) If the column index ‘j’ is less than half of the image width ‘y/2’,swap the pixel values
between the current column ‘j’ and its corresponding column on the other
half(‘len’)for each row ‘i’.
7) Next step is to upload images using upload File option.
8) Run the program.
9) Stop the program.

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

img=imread('6.jpg'); imshow(img);
title('Original image');
I = imread('6.jpg');
figure imshow(I)
[x, y, z] =size(img); for plane = 1:
z for i = 1 : x len = y; for j = 1 : y
if j<y/2 temp = img(i, j, plane);
img(i, j, plane) = img(i, len, plane);

img(i, len, plane) =temp;

len = len - 1;
end
end
end
end
imshow(img);

title('Mirror image');

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:02
ARITHMETIC MEAN FILTER

AIM:

To implement Arithmetic mean filter using Mathlab Compiler.

ALGORITHM:

1. Run the program.


2. Declare variables for image matrix, filter size, and result matrix.
3. Define the condition to iterate through each pixel of the image.
4. Within the loop, compute the arithmetic mean of pixel values within the filter window.
5. Assign the mean value to the corresponding pixel in the result matrix.
6. Repeat steps 3-5 for all pixels in the image.
7. Stop the program

5 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:
close all

mygrayimg = imread('4.jpg');

scaledimageA = imresize(mygrayimg,[256, 256]);

subplot(2, 2, 1);

imshow(scaledimageA, []); title('Original image A');

d = imcomplement(scaledimageA);

subplot(2, 2, 4);

mygrayimg1 = imread('5.jpg');

scaledimageB = imresize(mygrayimg1,[256, 256]);

subplot(2, 2, 3);

imshow(d, []); title('Image Complement');

d = imcomplement(scaledimageA);

subplot(2, 2, 2);

imshow(scaledimageB, []); title('Original image B');

d = imcomplement(scaledimageB);

subplot(2, 2, 4);

imshow(d, []); title('Image Complement');

d = imcomplement(scaledimageB);

subplot(2, 2, 2);

6 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

7 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:03

AIM:
To implement Geometric mean filter using Mathlab Compiler.

ALGORITHM:
1. Start the Program.
2. Declare variables for image matrix, filter size, and output matrix.
3. Check if filter size is odd and greater than 1.
4. Iterate over each pixel of the image.
5. Calculate geometric mean within the filter window.
6. Assign the calculated mean to the corresponding pixel in the output matrix.
7. Stop the program.

8 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:
clc
close all
f = imread('image.jpg');
g1 = imresize(f, [256, 256], 'nearest');
g = rgb2gray(g1);
subplot(2, 2, 1);
imshow(g); title('original gray image');
t = [1 0 0; 0 1 0; 50 100 1];
tform = maketform('affine', t);
translateimg = imtransform(f, tform);
subplot(2, 2, 2);
imshow(translateimg), title('Translated image');
subplot(2, 2, 3);
t = pi/6;
r = [cos(t) sin(t) 0; -sin(t) cos(t) 0; 0 0 1];
tform = maketform('affine', r);
rotimg = imtransform(f, tform);
imshow(rotimg), title('Rotated image');
subplot(2, 2, 4);
h = imrotate(f, -45, 'linear');
imshow(h); title('Rotated by 45 degrees in clockwise direction');

9 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:04
BLURRED IMAGE

AIM:
To write a Program to perform blurring on an image using Mathlab Compiler.

ALGORITHM:
1. Start the program.
2. Declare variables for image loading and processing.
3. Apply a blurring filter to the image.
4. Set a condition to check if blurring is successful.
5. Display the blurred image.
6. Stop the program.

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

I = imread('image.jpg');
figure;imshow(I);title("Original Image");
text(size(I,2),size(I,1)+15, ...
"Image courtesy of Massachusetts Institute of Technology", …
"FontSize",7,"HorizontalAlignment","right");
PSF = fspecial("gaussian",7,10);
Blurred = imfilter(I,PSF,"symmetric","conv");
imshow(Blurred)
title("Blurred Image")

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:05

DE-BLURRED IMAGE

AIM:

To write a Program to Perform De-blurring on an image using Mathlab Compiler.

ALGORITHM:
1. Start the program.
2. Declare the blurred image.
3. Declare the kernel for deblurring.
4. Convolve the blurred image with the kernel.
5. Apply a deblurring algorithm.
6. Display the deblurred image.
7. Stop the program..

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:
I = imread('5.jpg');

I = I(60+[1:256],222+[1:256],:); % crop the image figure;


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

LEN = 31;
THETA = 11;
PSF = fspecial('motion',LEN,THETA); % create PSF
Blurred = imfilter(I,PSF,'circular','conv'); figure;
imshow(Blurred); title('De-Blurred Image');

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:06
IMAGE MORPHOLOGY

AIM:
To implement a function for image morphology using Mathlab Compiler.

ALGORITHM:
1. Start the Program.

2. Declare structuring element and input image.


3. Apply erosion operation: if pixel value is 1 and at least one surrounding pixel is 0, set the pixel
to 0.
4. Apply dilation operation: if pixel value is 0 and at least one surrounding pixel is 1, set the pixel
to 1.
5. Repeat erosion and dilation operations for desired iterations.
6. Stop the program.

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE :

I = imread("image.jpg");
subplot(2, 3, 1), imshow(I);
title("Original image");
se = strel("line", 7, 7);
dilate = imdilate(I, se);
subplot(2, 3, 2), imshow(dilate);
title("Dilated image");
erode = imerode(I, se);
subplot(2, 3, 3), imshow(erode);
title("Eroded image");
open = imopen(I, se);
subplot(2, 3, 4), imshow(open);
title("Opened image");
close = imclose(I, se);
subplot(2, 3, 5), imshow(close);
title("Closed image");

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

1 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:07

SALT AND PEPPER METHOD

AIM:
To write a Program for salt and pepper noise in an image using Mathlab Compiler.

ALGORITHM:

1. Start the program.


2. Read the image named "6.jpg".
3. Display the original image.
4. Introduce salt and pepper noise to the original image with a noise density of 2%.
5. Display the image with salt and pepper noise.

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:
I= imread('6.jpg'); figure
imshow(I)
J= imnoise(I,'salt & pepper',0.02);
figure imshow(J)

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:08
IMAGE SEGMENTATION

AIM:
To implement a function for image segmentation using Mathlab Compiler.

ALGORITHM:
1. Run the program.
2. Declare the input image.
3. Apply preprocessing techniques if needed.
4. Implement segmentation algorithm .
5. Define stopping condition for segmentation.
6. Generate segmented regions or boundaries.
7. Stop the program.

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:
clc;
close all;
clear all;
a = imread('3.jpg');
a = rgb2gray(a);
subplot(3, 3, 1);
imshow(a); title('Original image');
level = 0.3;
subplot(3, 3, 2);
segimage1 = im2bw(a, level);
imshow(segimage1); title('Simple thresholing at 0.3');
subplot(3, 3, 3);
imshow(a > 153); title('Simple thresholding at 0.6');
tmp = a;
[m n] = find(<26);
for j =1: length(m)
tmp(m(j), n(j)) = 0;
end
[m n] = find(a>26 & a <= 230);
for j =1: length(m)
tmp(m(j), n(j)) = 0.8;
end
[m n] = find(a>230);
for j =1: length(m)
tmp(m(j), n(j)) = 0;
end
subplot(3, 3, 4);
segimage2 = im2bw(tmp,0);
imshow(segimage2); title('Multiple threshoding(between 27-230)');
level = graythresh(a);
subplot(3, 3, 5);
segimage = im2bw(a, level);
imshow(segimage); title('Otsu - optimal segmented image');
b = imread('3.jpg');
subplot(3, 3, 6);
imshow(b); title('Badly illuminated image');

level = graythresh(b);
subplot(3, 3, 7);
segimage = im2bw(b, level);

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

imshow(segimage); title('Otsu - Segmentation for bad illuminated image');


b = imread('3.jpg);
b = rgb2gray(b);
avgfilt = ones(13, 13);
adaptfiltmask = avgfilt/sum(avgfilt);
im = imfilter(b, adaptfiltmask, 'replicate');
im1= medfilt2(b, [20 20]);

thresh = im + 18;
adaptthreshimg = b -thresh;
subplot(3, 3, 8);
imshow(adaptthreshimg > 0); title('Adaptive threshold = 18');

thresh1 = im1 + 2;
adaptthreshimg = b - thresh1;
subplot(3, 3, 9);
imshow(adaptthreshimg > 0); title('Adaptive threshold = 2');

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:09
IMAGE EDGE DETECTION

AIM:
To implement Edge detection using Mathlab Compiler.

ALGORITHM:
1) Start the Program.
2) Run the program.
3) Declare the input image.
4) Apply preprocessing techniques if needed.
5) Implement segmentation algorithm .
6) Define stopping condition for segmentation.
7) Generate segmented regions or boundaries.
8) Stop the program.

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

i= imread('image.jpg');
g=rgb2gray(i);
subplot(2,2,1);
imshow(i);
title('Original Image');
subplot(2,2,2);
imshow(g);
title('Gray Image');
c=edge(g,'canny');
subplot(2,2,3);
imshow(c);
title('Edge detection');

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

2 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:10

AIM:

To write a program to display RGB Colour using Mathlab compiler.

ALGORITHM:

1) Run the program.


2) Declare variables for red, green, and blue color channels.
3) Read the RGB values of each pixel from the image.
4) Apply any required processing or transformations to the RGB values.
5) Update the image with the modified RGB values.
6) Display or save the processed image.

7) Stop the program.

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

I = imread('1111.jpg');
r = size(I, 1);
c = size(I, 2);
R = zeros(r, c, 3);
G = zeros(r, c, 3);
B = zeros(r, c, 3);
R(:, :, 1) = I(:, :, 1);
G(:, :, 2) = I(:, :, 2);
B(:, :, 3) = I(:, :, 3);

figure, imshow(uint8(R)); figure,


imshow(uint8(G)); figure,
imshow(uint8(B));

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

RESULT:
The above program has been executed successfully and the output was verified.

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO:11
BOUNDARY EXTRACTION ALGORITHM

AIM:
To implement Boundary Extraction Algorithm using Mathlab Compiler.

ALGORITHM:

1. Start the program.


2. Declare variables for image input and output.
3. Set conditions to identify boundary pixels.
4. Iterate through each pixel in the image.
5. Check if the pixel is part of the object boundary.
6. If the condition is met, mark the pixel in the output image.

7. Stop the program.

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

A=imread('1111.jpg');

s=strel('disk',2,0);

F=imerode(A,s);

figure,

subplot(2,1,1);

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

subplot(2,1,2);

imshow(A-F);title('Boundary extracted Image');

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO: 12
IMAGE AND ITS HISTOGRAM

AIM:
To write a program to display image and its histogram using Mathlab Compiler.

ALGORITHM:

1) Start the program.


2) Read the image named "image.jpg".
3) Display the original image in the first subplot.
4) Display the histogram of the image with 64 bins in the second subplot.
5) Stop the program.

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:
I = imread('image.jpg');
subplot(1,2,1)
imshow(I)
subplot(1,2,2)
imhist(I,64)

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

3 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO: 13
IMAGE RESTORATION

AIM:

To implement Image Restoration using Mathlab Compiler.

ALGORITHM:
1. Start the Program.
2. Declare variables for storing the degraded image and reference image.
3. Set conditions to identify degraded areas in the image.
4. Apply suitable restoration techniques such as noise reduction or interpolation.
5. Evaluate the effectiveness of restoration using metrics like PSNR or visual
inspection.
6. Adjust parameters or algorithms if necessary for better results.
7. Stop the program.

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

mygrayimg = imread('1.jpg');
mygrayimg = imresize(mygrayimg, [256 256]);
subplot(3, 3, 1), imshow(mygrayimg), title('Original image');

noisyimg = imnoise(mygrayimg, 'Salt & Pepper',0.5);


subplot(3, 3, 2), imshow(noisyimg);
title('Noisy image');

wienerimg = wiener2(noisyimg, [5, 5]);


subplot(3, 3, 4), imshow(wienerimg);
title('Wiener filter with 5*5 mask');

gausspsf = fspecial('gaussian', [64, 64], 5);


subplot(3, 3, 5), imshow(gausspsf, []);
title('Gaussian PSF');

motionpsf = fspecial('motion', 64, 64);


subplot(3, 3, 6), imshow(motionpsf, []);
title('Motion PSF');

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO: 14
CLOCKWISE IMAGE

AIM:
To write a program to display clockwise image using Mathlab Compiler.

ALGORITHM:
1. Start the Program.

2. Read the image named "9.png".


3. Display the original image.
4. Create a new image by flipping the original image both vertically and horizontally
(clockwise rotation).
5. Display the flipped image.
6. Stop the program.

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

a = imread("9.png");
imshow(a);
i = a(end:-1 : 1, end:-1 : 1);
figure, imshow(i);

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO: 15
DOUBLE-SIZE IMAGE

AIM:
To write a program to display Double size image using Mathlab Compiler.

ALGORITHM:
1. Start the Program.
2. Read the image named "k.jpg".
3. Resize the original image using nearest neighbor interpolation with a scaling
factor of 0.9.
4. Display the original image with the title "Original Image".
5. Display the resized image with the title "Resized Image Using Nearest
Neighbor Interpolation"

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:
I = imread('k.jpg');
J = imresize(I,0.9,'nearest');
imshow(I)
title('Original Image')
imshow(J)
title('Resized Image Using Nearest Neighbor Interpolation')

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

EX.NO: 16
ZOOMING AN IMAGE

AIM:
To write a program to display Zooming of an image using Mathlab Compiler.

ALGORITHM:

1. Start the Program.


2. Read the image named "k.jpg".
3. Resize the original image using nearest neighbor interpolation with a scaling
factor of 0.9.
4. Display the original image with the title "Original Image".
5. Display the resized image with the title "Resized Image Using Nearest
Neighbor Interpolation"

4 SACWC
IMAGE PROCESSING LAB APRIL 2025

SOURCE CODE:

clear all;
close all;
clc;
b=imread('1.jpg');
s=size(b);
c=[];
d=[];
zoom=input('enter zooming factor');

for n=1:s(1,1)
for p=1:zoom
c=[c;b(n,:)];
end
end

for m=1:s(1,2)
for p=1:zoom
d=[d,c(:,m)];
end
end
imshow(d);

5 SACWC
IMAGE PROCESSING LAB APRIL 2025

OUTPUT:

RESULT:
The above program has been executed successfully and the output was verified.

5 SACWC

You might also like