Assign 1
Assign 1
Submitted by
Kanish Mahato
21103070
CSE
1/13
1. Create a chessboard image with 64 blocks consisting of white and
black squares with 50-pixel width and height. Save the image as
chess.jpg. Read the image and display it.
Code :-
pixel = 50;
chess = repmat(eye(2), 4, 4);
chess_image = kron(chess, ones(pixel));
imwrite(chess_image, 'chess.jpg');
image = imread('chess.jpg');
figure;
imshow(image);
colormap(gray);
title('Chessboard');
Output:-
2/13
2. Read a gray scale image and verify that the image is a 256-level image.
Display the image in gray levels 128, 64, 32, 16, 8, 4, 2. What are your
observations regarding the outputs produced?
Code:-
image = imread('girl.png');
image = im2gray(image)
if max(image(:)) <= 255 && min(image(:)) >= 0
disp('The image is a 256-level grayscale image.');
else
disp('The image is not a 256-level grayscale image.');
end
figure;
subplot(3, 3, 1);
imshow(image);
title('256 Levels');
3/13
image128 = uint8(floor(double(image) / 2) * 2);
subplot(3, 3, 2);
imshow(image128);
title('128 Levels');
My Obervation:-
4/13
Output:-
a. Image Negative
b. Power law with gamma = 0.2
c. Histogram Equalization
Code:-
5/13
image = imread('girl.png');
if size(image, 3) == 3
image = rgb2gray(image);
else
disp('The image is already grayscale.');
end
figure;
subplot(2, 2, 1);
imshow(image);
title('Original Image');
subplot(2, 2, 2);
imshow(imageNegative);
title('Negative Image');
subplot(2, 2, 3);
imshow(imagePowerLaw);
title('Power Law (Gamma = 0.2)');
subplot(2, 2, 4);
imshow(imageHistEq);
title('Histogram Equalization');
figure;
imhist(imageHistEq);
title('Histogram of Equalized Image');
figure;
imhist(image);
title('Histogram of Original Image');
6/13
Output:-
7/13
8/13
4. Read a gray scale image and apply Gaussian low pass filter and
Laplacian high pass filter on the image in the spatial domain. What is
your observation regarding the output?
Code:-
image = imread('girl.png');
if size(image, 3) == 3
image = rgb2gray(image);
else
disp('The image is already grayscale.');
end
figure;
subplot(3, 1, 1);
imshow(image);
title('Original Image');
subplot(3, 1, 2);
imshow(imageGaussian);
title('Gaussian Low-Pass Filter');
subplot(3, 1, 3);
imshow(imageLaplacian, []);
title('Laplacian High-Pass Filter');
The image is already grayscale.
Output:-
9/13
My Observation :
5. Read a gray scale image and apply Gaussian low pass filter and
Laplacian high pass filter on the image in the frequency domain. What
is your observation regarding the output?
10/13
Code:-
img = imread('girl.png');
if size(img, 3) == 3
img = rgb2gray(img);
end
img = double(img);
[M, N] = size(img);
F = fft2(img);
Fshift = fftshift(F);
D0 = 30;
[x, y] = meshgrid(-N/2:N/2-1, -M/2:M/2-1);
H = exp(-(x.^2 + y.^2) / (2 * D0^2));
H = double(H);
G = H .* Fshift;
G_ishift = ifftshift(G);
img_gaussian_filtered = ifft2(G_ishift);
img_gaussian_filtered = abs(img_gaussian_filtered);
L = Hlaplacian_freq .* Fshift;
L_ishift = ifftshift(L);
img_laplacian_filtered = ifft2(L_ishift);
img_laplacian_filtered = abs(img_laplacian_filtered);
figure;
subplot(3, 1, 1);
imshow(img, []);
title('Original Image');
11/13
subplot(3, 1, 2);
imshow(img_gaussian_filtered, []);
title('Gaussian Low Pass Filtered');
subplot(3, 1, 3);
imshow(img_laplacian_filtered, []);
title('Laplacian High Pass Filtered');
Output:-
My Observation :-
12/13
Laplacian High Pass Filter:
13/13