You are on page 1of 6

Experiment – 03

FIP LAB
Experiment 3: Spatial domain Image enhancement
3.1 WAP to perform complement, logarithmic and power law transformation on image.
(Consider, C = 50 for logarithmic transformation, gamma = 1.2 for power law
transformation)
MATLAB CODE
originalImage = imread('block_1.pngblock_649.png');
complementImage = 255 - originalImage;
C = 50;
logarithmicImage = C * log(1 + double(originalImage));

gamma = 1.2;
powerLawImage = 255 * (double(originalImage) / 255).^gamma;

% Display the original and transformed images


subplot(2, 2, 1);
imshow(originalImage);
title('Original Image');

subplot(2, 2, 2);
imshow(complementImage, []);
title('Complement Transformation');

subplot(2, 2, 3);
imshow(uint8(logarithmicImage), []);
title('Logarithmic Transformation');

subplot(2, 2, 4);
imshow(uint8(powerLawImage), []);
title('Power Law Transformation');

OUTPUT
3.2 WAP to find the histogram of different images (e.g. cameraman.tif, pout.tif,
coins.png). Also, Create a 'user defined function()' for imhist().
MATLAB CODE
cameraman = imread('cameraman.tif');
pout = imread('pout.tif');
coins = imread('coins.png');

histogram_cameraman = myImhis(cameraman);
histogram_pout = myImhis(pout);
histogram_coins = myImhis(coins);

figure;

subplot(3, 1, 1);
stem(0:255, histogram_cameraman, 'Marker', 'none');
title('Histogram of cameraman.tif');

subplot(3, 1, 2);
stem(0:255, histogram_pout, 'Marker', 'none');
title('Histogram of pout.tif');

subplot(3, 1, 3);
stem(0:255, histogram_coins, 'Marker', 'none');
title('Histogram of coins.png');

image = imread('block_1.pngblock_649.png');

function histogram = myImhis(image)


histogram = zeros(256, 1);

[rows, cols] = size(image);


for i = 1:rows
for j = 1:cols
pixel_value = image(i, j);
histogram(pixel_value + 1) = histogram(pixel_value + 1) + 1;
end
end
end
OUTPUT
3.3 WAP to clip image through thresholding two gray levels from both ends (low/high
intensity), and plot their histogram. (Take ‘’Cameraman.tif’’.When pixel intensity is
greater than 150, make it 255. When pixel intensity is less than 100, make it 0.)
MATLAB CODE
image = imread('cameraman.tif');

thresholded_image = image;
thresholded_image(thresholded_image > 150) = 255;
thresholded_image(thresholded_image < 100) = 0;

subplot(2, 2, 1);
imshow(image);
title('Original Image');

subplot(2, 2, 2);
imhist(image);
title('Histogram of Original Image');

subplot(2, 2, 3);
imshow(thresholded_image);
title('Thresholded Image');

subplot(2, 2, 4);
imhist(thresholded_image);
title('Histogram of Thresholded Image');

OUTPUT
3.4 WAP to clip image i.e to highlight intensity range between A & B and make others
zero. (Choose A and B from histogram)
MATLAB CODE

image = imread('cameraman.tif');

histogram = imhist(image);

A = find(histogram > 0, 1, 'first');


B = find(histogram > 0, 1, 'last');

binary_mask = (image >= A) & (image <= B);

clipped_image = uint8(binary_mask) .* image;

subplot(2, 2, 1);
imshow(image);
title('Original Image');

subplot(2, 2, 2);
imhist(image);
title('Histogram of Original Image');

subplot(2, 2, 3);
imshow(clipped_image);
title('Clipped Image');

subplot(2, 2, 4);
imhist(clipped_image);
title('Histogram of Clipped Image');

OUTPUT
3.5 WAP to clip image i.e to highlight intensity range between A & B without changing
other pixels. (Choose A and B from histogram)
MATLAB CODE
image = imread('cameraman.tif');

histogram = imhist(image);
A = find(histogram > 0, 1, 'first');
B = find(histogram > 0, 1, 'last');
binary_mask = (image >= A) & (image <= B);

clipped_image = image;
clipped_image(~binary_mask) = image(~binary_mask);

subplot(1, 2, 1);
imshow(image);
title('Original Image');

subplot(1, 2, 2);
imshow(clipped_image);
title('Clipped Image');

OUTPUT
3.6 WAP for enhancement of an image using histogram equalization (pout.tif). Hint: use
'histeq()'.
MATLAB CODE
pout = imread('pout.tif');
enhanced_pout = histeq(pout);
subplot(1, 2, 1);
imshow(pout);
title('Original Image (pout.tif)');

subplot(1, 2, 2);
imshow(enhanced_pout);
title('Enhanced Image (Histogram Equalization)');

figure;

subplot(2, 1, 1);
imhist(pout);
title('Histogram of Original Image');

subplot(2, 1, 2);
imhist(enhanced_pout);
title('Histogram of Enhanced Image');

OUTPUT

NAME: Master Bibek Kumar Mohanty


ID : B220029, ETC, 7TH SEMESTER

You might also like