MyMainScript

Contents

Q2(a)

tic;
figure;
im = imread('../data/barbara.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myLinearContrastStretching(im);
displayImage(output_im_he, 'Linear Contrast Enhanced Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Linear Contrast Enhanced Image Histogram');

figure;
im = imread('../data/TEM.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myLinearContrastStretching(im);
displayImage(output_im_he, 'Linear Contrast Enhanced Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Linear Contrast Enhanced Image Histogram');

figure;
im = imread('../data/retina.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myLinearContrastStretching(im);
displayImage(output_im_he, 'Linear Contrast Enhanced Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Linear Contrast Enhanced Image Histogram');

figure;
im = imread('../data/canyon.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myLinearContrastStretching(im);
displayImage(output_im_he, 'Linear Contrast Enhanced Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Linear Contrast Enhanced Image Histogram');

figure;
im = imread('../data/church.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myLinearContrastStretching(im);
displayImage(output_im_he, 'Linear Contrast Enhanced Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Linear Contrast Enhanced Image Histogram');

% Liner contrast stretching isn't effective here because
% the histogram of the original image is already distributed on the whole range
% of intensities. So the linear contrast enhancement does not have much effect
% on it when we apply max-min normalization;

% Formula
% new_pixel = ((old_pixel - low) / (high - low) ) * 255

toc;
Elapsed time is 3.472349 seconds.

Q2(b)

tic;
figure;
im = imread('../data/barbara.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myHE(im);
displayImage(output_im_he, 'Histogram Equalized Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Histogram Equalized Histogram');

figure;
im = imread('../data/TEM.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myHE(im);
displayImage(output_im_he, 'Histogram Equalized Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Histogram Equalized Histogram');

figure;
im = imread('../data/retina.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myHE(im);
displayImage(output_im_he, 'Histogram Equalized Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Histogram Equalized Histogram');

figure;
im = imread('../data/canyon.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myHE(im);
displayImage(output_im_he, 'Histogram Equalized Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Histogram Equalized Histogram');

figure;
im = imread('../data/church.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_he = myHE(im);
displayImage(output_im_he, 'Histogram Equalized Image');
subplot(2,2,3);
displayHist(im, 'Original Image - Histogram');
subplot(2,2,4);
displayHist(output_im_he, 'Histogram Equalized Histogram');

% Histogram Equalization will be preferred for Image 5. It works better
% becuause of non linear mapping. It stretches the area with high
% intensities and compresses the area with low intensities.

toc;
Elapsed time is 27.906404 seconds.

Q2 (c)

tic;
figure;
im = imread('../data/retina.png');
subplot(2,3,1);
displayImage(im, 'Original Image');
subplot(2,3,2);
output_im_he = myHE(im);
displayImage(output_im_he, 'Histogram Equalized Image');
subplot(2,3,3);
output_im_hm = myHM();
displayImage(output_im_hm, 'Histogram Matched Image');
subplot(2,3,4);
displayHist(im, 'Original Image Histogram');
subplot(2,3,5);
displayHist(output_im_he, 'Histogram Equalized Image Histogram');
subplot(2,3,6);
displayHist(output_im_hm, 'Histogram Matched Image Histogram');
toc;
Elapsed time is 31.720353 seconds.

Q2 (d)

tic;
figure;
im = imread('../data/barbara.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_window_51 = myAHE(im, 51);
displayImage(output_im_window_51, 'AHE with window size 51');
subplot(2,2,3);
output_im_window_5 = myAHE(im, 5);
displayImage(output_im_window_5, 'AHE with window size 5');
subplot(2,2,4);
output_im_window_151 = myAHE(im, 151);
displayImage(output_im_window_151, 'AHE with window size 151');


figure;
im = imread('../data/canyon.png');
subplot(1,2,1);
displayImage(im, 'Original Image');
subplot(1,2,2);
output_im_window_51 = myAHE(im, 51);
displayImage(output_im_window_51, 'AHE with window size 51');
% subplot(2,2,3);
% output_im_window_5 = myAHE(im, 5);
% displayImage(output_im_window_5, 'AHE with window size 5');
% subplot(2,2,4);
% output_im_window_151 = myAHE(im, 151);
% displayImage(output_im_window_151, 'AHE with window size 151');

figure;
im = imread('../data/TEM.png');
subplot(1,2,1);
displayImage(im, 'Original Image');
subplot(1,2,2);
output_im_window_51 = myAHE(im, 51);
displayImage(output_im_window_51, 'AHE with window size 51');
% subplot(2,2,3);
% output_im_window_5 = myAHE(im, 5);
% displayImage(output_im_window_5, 'AHE with window size 5');
% subplot(2,2,4);
% output_im_window_151 = myAHE(im, 151);
% displayImage(output_im_window_151, 'AHE with window size 151');

toc;
Elapsed time is 189.925439 seconds.

Q2 (e)

tic;
figure;
im = imread('../data/barbara.png');
subplot(2,2,1);
displayImage(im, 'Original Image');
subplot(2,2,2);
output_im_window_75_clip_0_5 = myCLAHE(im, 75, 0.5);
displayImage(output_im_window_75_clip_0_5, 'CLAHE with window size 75 and clip 0.5');
subplot(2,2,3);
output_im_window_75_clip_0_25 = myCLAHE(im, 75, 0.25);
displayImage(output_im_window_75_clip_0_25, 'CLAHE with window size 75 and clip 0.25');

figure;
im = imread('../data/canyon.png');
subplot(1,2,1);
displayImage(im, 'Original Image');
subplot(1,2,2);
output_im_window_75_clip_0_5_canyon = myCLAHE(im, 75, 0.5);
displayImage(output_im_window_75_clip_0_5_canyon, 'CLAHE with window size 75 and clip 0.5');

figure;
im = imread('../data/TEM.png');
subplot(1,2,1);
displayImage(im, 'Original Image');
subplot(1,2,2);
output_im_window_75_clip_0_5_tem = myCLAHE(im, 75, 0.5);
displayImage(output_im_window_75_clip_0_5_tem, 'CLAHE with window size 75 and clip 0.5');

toc;
Warning: The value of local variables may have been changed to match the
globals.  Future versions of MATLAB will require that you declare a variable to
be global before you use that variable. 
Warning: The value of local variables may have been changed to match the
globals.  Future versions of MATLAB will require that you declare a variable to
be global before you use that variable. 
Warning: The value of local variables may have been changed to match the
globals.  Future versions of MATLAB will require that you declare a variable to
be global before you use that variable. 
Warning: The value of local variables may have been changed to match the
globals.  Future versions of MATLAB will require that you declare a variable to
be global before you use that variable. 
Elapsed time is 214.099782 seconds.