Image Processing Lab
Image Processing Lab
4. BLURRED IMAGE 12
5. DE-BLURRED IMAGE 14
6. IMAGE MORPHOLOGY 17
8. IMAGE SEGMENTATION 23
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:
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);
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:
ALGORITHM:
5 SACWC
IMAGE PROCESSING LAB APRIL 2025
SOURCE CODE:
close all
mygrayimg = imread('4.jpg');
subplot(2, 2, 1);
d = imcomplement(scaledimageA);
subplot(2, 2, 4);
mygrayimg1 = imread('5.jpg');
subplot(2, 2, 3);
d = imcomplement(scaledimageA);
subplot(2, 2, 2);
d = imcomplement(scaledimageB);
subplot(2, 2, 4);
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:
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');
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.
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
AIM:
To write a Program for salt and pepper noise in an image using Mathlab Compiler.
ALGORITHM:
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
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:
ALGORITHM:
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);
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:
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);
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:
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:
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');
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.
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:
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