0% found this document useful (0 votes)
35 views8 pages

Experiment 3: Spatial Domain Image Enhancement: MATLAB Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views8 pages

Experiment 3: Spatial Domain Image Enhancement: MATLAB Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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
I = imread('coloredChips.png');

subplot(2,2,1) imshow(I) title('Original

Image')

complemented_image = 255 - I;

subplot(2,2,2)

imshow(complemented_image);

title('Complemented Image'); C = 50;

log_transformed_image = C * log(1 + double(I));

subplot(2,2,3)

imshow(uint8(log_transformed_image));

title('LogTransformed Image'); gamma = 1.2;

power_law_image = double(I) .^ gamma;

subplot(2,2,4)

imshow(uint8(power_law_image)); title('Power

Law Transformed Image');


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:
I = imread('cameraman.tif');

[counts, binLocations] = imhist(I);

subplot(3,2,1) imshow(I)

title('Original Image')

subplot(3,2,2) bar(binLocations,

counts); title('Histogram of

Image');

xlabel('Intensity');

ylabel('Frequency'); I =

imread('pout.tif');

[counts, binLocations] = imhist(I);

subplot(3,2,3) imshow(I)
title('Original

Image')

subplot(3,2,4)

bar(binLocations, counts);

title('Histogram of

Image'); xlabel('Intensity');

ylabel('Frequency');

I = imread('coins.png');

[counts, binLocations] =

imhist(I);

subplot(3,2,5)

imshow(I) title('Original

Image')

subplot(3,2,6) bar(binLocations,

counts); title('Histogram of

Image');

xlabel('Intensity');

ylabel('Frequency');
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
I = imread('coloredChips.png'); A =

100; B = 150; clipped_image = I;

clipped_image(clipped_image < A)=

0; clipped_image(clipped_image > B)=

255; subplot(1,2,1) imshow(I)

title('Original Image') subplot(1,2,2)

imshow(thresholded_image)

; title('Thresholded Image');

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
I = imread('coloredChips.png'); A = 100; B = 200;

clipped_image = I; clipped_image(clipped_image < A

| clipped_image > B) = 0; subplot(1,2,1) imshow(I)

title('Original Image') subplot(1,2,2)

imshow(clipped_image); title('Clipped Image');


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
I=

imread('coloredChips.png'); A

= 100;

B = 200;

J = imadjust(I, [A/255, B/255], [0, 1]);

subplot(1,2,1)

imshow(I) title('Original

Image') subplot(1,2,2)

imshow(J);

title('Clipped Image');
3.6 WAP for enhancement of an image using histogram equalization (pout.tif). Hint:
use 'histeq()'.

MATLAB code
I = imread('coloredChips.png'); J =

histeq(I); subplot(2, 2, 1); imshow(I);

title('Original

Image'); subplot(2, 2, 3); imshow(J);

title('Enhanced Image (Histogram

Equalization)'); subplot(2, 2, 2); imhist(I);

title('Histogram of

Original Image'); subplot(2, 2, 4);

imhist(J); title('Histogram of Enhanced

Image');

NAME: VALLURIUDAYABHASKARA
ID- B221064

You might also like