IMAGE PROCESSING ASSIGNMENT - 2
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:
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:
OUTPUT:
5. Write and execute programs to remove noise using spatial filters. Use 3x3
Mask for low pass filter and high pass filter.
PROGRAM:
OUTPUT:
OUTPUT:
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: