Implementing Digital Negative of Image in MATLAB

a = imread('D:\lh.jpg');
a =rgb2gray(a);
r1 = input('Enter lower gray level:');
r2 = input('Enter upper gray level:');
b = a;
s = size(a);
for i=1:s(1)
for j=1:s(2)
if a(i,j)>r1
if a(i,j)>r2
b(i,j)=255;
end;
end;
end;
end;

c = a;
for i=1:s(1)
for j=1:s(2)
if a(i,j)>r1
if a(i,j)>r2
c(i,j) = 255;
else
c(i,j) = 0;
end;
end;
end;
end;

subplot(1,3,1);
imshow(a);
subplot(1,3,2);
imshow(b)
subplot(1,3,3);
imshow(c)

Output

Enter lower gray level:20
Enter upper gray level:50
Output

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.