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

IMAGE PROCESSING ASSIGNMENT - 2

The document outlines an image processing assignment that includes various tasks such as performing image arithmetic and logical operations, histogram calculation and equalization, gray level slicing, noise removal, and spatial filtering using MATLAB. Each task is accompanied by sample MATLAB code demonstrating the implementation of the specified operations. The assignment aims to provide hands-on experience with image processing techniques and their applications.

Uploaded by

sudvik07
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 views

IMAGE PROCESSING ASSIGNMENT - 2

The document outlines an image processing assignment that includes various tasks such as performing image arithmetic and logical operations, histogram calculation and equalization, gray level slicing, noise removal, and spatial filtering using MATLAB. Each task is accompanied by sample MATLAB code demonstrating the implementation of the specified operations. The assignment aims to provide hands-on experience with image processing techniques and their applications.

Uploaded by

sudvik07
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

IMAGE PROCESSING ASSIGNMENT - 2

SUDHIR VIKASH S
(715522106049)

1. Write and execute programs for image arithmetic operations and image logical
operations.
I. Addition of two images.
II. Subtract one image from other image.
III. Calculate mean value of image.
IV. AND operation between two images, OR operation between two
images
V. NOT operation (Negative image)
Program:

Program:
image1 = imread('image1.jpg');
image2 = imread('image2.jpg');
image1 = imresize(rgb2gray(image1), [256, 256]);
image2 = imresize(rgb2gray(image2), [256, 256]);
addition_result = imadd(image1, image2);
subtraction_result = imsubtract(image1, image2);
mean_value_image1 = mean(image1(:));
and_result = bitand(image1, image2);
or_result = bitor(image1, image2);
not_result = imcomplement(image1);
figure;
subplot(2,3,1); imshow(image1); title('Image 1');
subplot(2,3,2); imshow(image2); title('Image 2');
subplot(2,3,3); imshow(addition_result); title('Addition Result');
subplot(2,3,4); imshow(subtraction_result); title('Subtraction Result');
subplot(2,3,5); imshow(and_result); title('AND Operation');
subplot(2,3,6); imshow(or_result); title('OR Operation');
disp(['Mean value of Image1: ', num2str(mean_value_image1)]);
figure;
imshow(not_result); title('NOT Operation (Negative Image)');

OUTPUT:
2. Write a MATLAB program for histogram calculation and equalization.
20 20 20 18 16
15 15 16 18 15
15 15 19 15 17
16 17 19 18 16
20 18 17 20 15
PROGRAM:

clc;clear all; close all;


input_image = [20 20 20 18 16; 15 15 16 18 15; 15 15 19 15 17; ...
16 17 19 18 16; 20 18 17 20 15];
input_image = uint8(input_image);
original_hist_values = imhist(input_image);
equalized_image = histeq(input_image);
equalized_hist_values = imhist(equalized_image);
figure;
subplot(2,2,1); imshow(input_image, []); title('Original Image');
subplot(2,2,2); bar(original_hist_values); title('Original Histogram');
subplot(2,2,3); imshow(equalized_image, []); title('Equalized Image');
subplot(2,2,4); bar(equalized_hist_values); title('Equalized Histogram');

OUTPUT:
3. Implement Gray level slicing (Intensity level slicing) to read cameraman
image.
I. Read an 8 bit image and see the effect of each bit on the image.
II. Read an image and extract 8 different planes i.e. ‘bit plane slicing.”

PROGRAM:
clc;clear all; close all;
image = imread('cameraman.tif');
low = 50; high = 150;
gray_level_sliced = uint8((image >= low & image <= high)) .* image;
bit_planes = cell(1, 8);
for i = 1:8
bit_planes{i} = bitget(image, i) * 2^(i-1);
end
figure;
subplot(3,3,1); imshow(image); title('Original Image');
subplot(3,3,2); imshow(gray_level_sliced, []); title('Gray Level Slicing');
for i = 1:8
subplot(3,3,i+2); imshow(bit_planes{i}, []); title(['Bit Plane ',
num2str(i)]);
end

OUTPUT:
4. Write a MATLAB program to
i) Remove Salt and Pepper Noise.
ii) Minimize Gaussian noise

PROGRAM:

clc;clear all; close all;


original_image = imread('image1.jpg');
if size(original_image, 3) == 3
original_image = rgb2gray(original_image);
end
noisy_image = imnoise(original_image, 'salt & pepper', 0.02);
median_filtered = medfilt2(noisy_image, [3, 3]);
gaussian_noisy_image = imnoise(original_image, 'gaussian', 0.01);
gaussian_filtered = imgaussfilt(double(gaussian_noisy_image), 2);
figure;
subplot(2,3,1); imshow(original_image); title('Original Image');
subplot(2,3,2); imshow(noisy_image); title('Salt & Pepper Noisy Image');
subplot(2,3,3); imshow(median_filtered); title('Median Filtered Image');
subplot(2,3,4); imshow(gaussian_noisy_image); title('Gaussian Noisy Image');
subplot(2,3,5); imshow(uint8(gaussian_filtered)); title('Gaussian Filtered
Image');

OUTPUT:
5. Write and execute programs to remove noise using spatial filters. Use 3x3
Mask for low pass filter and high pass filter.

PROGRAM:

clc;clear all; close all;


image = imread('image1.jpg');
image = rgb2gray(imresize(image, [256, 256]));
low_pass_filter = fspecial('average', [3 3]);
high_pass_filter = fspecial('laplacian', 0.2);
low_pass_result = imfilter(image, low_pass_filter);
high_pass_result = imfilter(image, high_pass_filter);
figure;
subplot(1,3,1); imshow(image); title('Original Image');
subplot(1,3,2); imshow(low_pass_result); title('Low Pass
Filter');
subplot(1,3,3); imshow(high_pass_result); title('High Pass
Filter');

OUTPUT:

OUTPUT:

6. I.Write a MATLAB code for chain code


II. Write a MATLAB Program for Lossy Predictive coding of
an Image.
PROGRAM:
clc;clear all; close all;
binary_image = zeros(10, 10);
binary_image(3:7, 4) = 1;
binary_image(3, 4:8) = 1;
binary_image(7, 4:8) = 1;
binary_image(3:7, 8) = 1;
figure;
imshow(binary_image, 'InitialMagnification', 'fit');
title('Binary Image');
disp('Binary Image Matrix:');
disp(binary_image);
boundary = bwboundaries(binary_image, 'noholes');
boundary = boundary{1};
6. I.Write a MATLAB code for chain code
II. Write a MATLAB Program for Lossy Predictive coding of an Image.

PROGRAM:
clc;clear all; close all;
binary_image = zeros(10, 10);
binary_image(3:7, 4) = 1;
binary_image(3, 4:8) = 1;
binary_image(7, 4:8) = 1;
binary_image(3:7, 8) = 1;
figure;
imshow(binary_image, 'InitialMagnification', 'fit');
title('Binary Image');
disp('Binary Image Matrix:');
disp(binary_image);
boundary = bwboundaries(binary_image, 'noholes');
boundary = boundary{1};

OUTPUT:

You might also like