Thursday, March 12, 2009

Image negative

% Read a gray scale image and generate the negative of it
% Read the negative image and by taking its negative get the original image
% Extend the same technique for color image
clear all; close all; clc;
a=imread('Peppers1.png');
b=im2double(a);
[m n z]=size(b);
if z==1
for i=1:m
for j=1:n
c(i,j)= 1-b(i,j);
end
end
elseif z==3
c = 1-b;
else
disp('Input image is not a grayscale or RGB image');
end

figure,imshow(a),title('Original Image');
figure,imshow(c),title('Negative Image');

b=im2double(c);
[m n z]=size(b);
if z==1
for i=1:m
for j=1:n
c(i,j)= 1-b(i,j);
end
end
elseif z==3
c = 1-b;
else
disp('Input image is not a grayscale or RGB image');
end

figure,imshow(c),title('Negative Image');

No comments: