PART B
1. Demonstrate different image transformation like Negative, Logarithmic
and Power-Law (gamma) techniques
%% Read and Display image
I0=imread('[Link]');
I=rgb2gray(I0);
montage({I0,I},'Size',[1 2]);
title('color image grayscale image');
%%image negative
I_neg=imcomplement(I);
montage({I,I_neg},'Size',[1 2]);
title('original image negative image');
%%Log transformation
Id=im2double(I);
I_log2=2.*log(1+Id);
I_log3=3.*log(1+Id);
I_log4=4.*log(1+Id);
subplot(2,2,1),imshow(Id), title('original image');
subplot(2,2,2),imshow(I_log2), title('log factor 2');
subplot(2,2,3),imshow(I_log3), title('log fator 3');
subplot(2,2,4),imshow(I_log3), title('log fator 4');
%%Gamma transformation
I_gamma3=1*Id.^3;
I_gamma4=1*Id.^4;
I_gamma5=1*Id.^5;
subplot(2,2,1),imshow(Id), title('original image');
subplot(2,2,2),imshow(I_gamma3), title('gamma factor3');
subplot(2,2,3),imshow(I_gamma4), title('gamma factor4');
subplot(2,2,4),imshow(I_gamma5), title('gamma factor5');
2. Demonstrate histogram equalization, contrast stretching and bit-plane
slicing for a low contrast 2D image.
%%image histogram and histogram equalization
Img=imread("[Link]");
subplot(1,2,1),imshow(Img),title('original image');
subplot(1,2,2),imhist(Img),title('histogram');
J=histeq(Img);
subplot(1,2,1),imshow(J),title('histogram equalized image');
subplot(1,2,2),imhist(J),title('histogram of equalized image')
%%
%%Contrast stretching
I0=imread('[Link]');
I=rgb2gray(I0);
I=imadd(I,100);
J= imadjust(I,stretchlim(I),[0.01 0.99]);
montage({I,J},'Size',[1 2]);
title('original image contrast stretched image');
%%
%%Bitplane slicing
I1=imread("[Link]");
subplot(3,3,1),imshow(I1), title('original image');
B=bitget(I1,1);%lowest order bit of all pixels
subplot(3,3,2),imshow(logical(B)), title('bitplane 1');
B=bitget(I1,2);
subplot(3,3,3),imshow(logical(B)), title('bitplane 2');
B=bitget(I1,3);%lowest order bit of all pixels
subplot(3,3,4),imshow(logical(B)), title('bitplane 3');
B=bitget(I1,4);%lowest order bit of all pixels
subplot(3,3,5),imshow(logical(B)), title('bitplane 4');
B=bitget(I1,5);%lowest order bit of all pixels
subplot(3,3,6),imshow(logical(B)), title('bitplane 5');
B=bitget(I1,6);%lowest order bit of all pixels
subplot(3,3,7),imshow(logical(B)), title('bitplane 6');
B=bitget(I1,7);%lowest order bit of all pixels
subplot(3,3,8),imshow(logical(B)), title('bitplane 7');
B=bitget(I1,8);%lowest order bit of all pixels
subplot(3,3,9),imshow(logical(B)), title('bitplane 8');
%%