Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save agaikwad123/d1324f96cf703598b99c956238d17bda to your computer and use it in GitHub Desktop.
Save agaikwad123/d1324f96cf703598b99c956238d17bda to your computer and use it in GitHub Desktop.
Study of Gray level transformations on an image using MATLAB
a= input (Enter the path of the image:); % accept image path from user
b= imread (a); % read the image
[x,y]=size (b); % store the image in matrix form
d=max (max (b)); % find he max value in the matrix
for i=1:x
for j=1:y
if(b(i,j))<=50
f(i,j)= 0.2*(b(i,j));
elseif (50<=(b(i,j))<=150)
f(i,j)=2*(b(i,j)); %formula for contrast stretching;
elseif 150<=b(i,j)<=d
f(i,j)= 0.3*(b(i,j));
end
end
end
figure
subplot(1,2,1)
imshow(b) % show original image
title(Original image)
subplot(1,2,2)
imshow(f) % show transformed image
title(Contrast Stretching)
% Log Transformation
clc; clear all; close all;
a= input (Enter the path of the image:); % accept image path from user
[x,y]=size (b);
b= imread (a); % read the image
e=im2double(b);
for i=1:x
for j=1:y
S(i,j)= 1*(1+log10(e(i,j))); % formula for log transformation
end
end
figure
subplot(1,2,1)
imshow(b) % show original image
title(Original image;)
subplot(1,2,2)
imshow(S) %Show log transformed image
title(Log transformed Image&)
% Power law transformation
clc; clear all; close all;
a= input (Enter the path of the image:); % accept image path from user
b= imread (a); % read the image
[x,y]=size (b); % store the image in matrix form
d=max (max (b)); % find he max value in the matrix
r=input(Enter value of r:)
for i= 1:x
for j= 1:y
a= input (Enter the path of the image:); % accept image path from user
b= imread (a); % read the image
[x,y]=size (b); % store the image in matrix form
d=max (max (b)); % find he max value in the matrix
1] Negative Transform
clc; clear all; close all;
% Negative transformation
a= input (Enter the path of the image:); % accept image path from user
b= imread (a); % read the image
[x,y]=size (b); % store the image in matrix form
d=max (max (b)); % find he max value in the matrix
for i=1:x
for j=1:y
fn(i,j)=d-b(i,j); %formula for negative transform of image
end
end
figure
subplot(1,2,1)
imshow(b) ; % show original image
title(Original image)
subplot(1,2,2)
imshow(fn) % show –ve transform of image
title(Negative image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment