imcomplement function (Negative of an image)
imcomplement computes the complement of the image IM. IM can be a binary, intensity, or RGB image. IM2 has the same class and size as IM.
first the highest intensity value is computer for a pixel which is 255 and then the pixel value is subtracted from that highest values.
General Example
>> A = uint8([5 6 9 11 13]); >> B = imcomplement(A) B = 250 249 246 244 242
Operation on images as
>> oimgRGB = imread('Desert.jpg'); >> gImg = rgb2gray(oimgRGB); >> imgCompl = imcomplement(gImg); >> subplot(1,2,1),imshow(gImg) >> subplot(1,2,2),imshow(imgCompl)
Output
Example with color images
>> oimgRGB = imread('sampleImage.jpg'); >> imgCompl = imcomplement(oimgRGB); >> subplot(1,2,1),imshow(oimgRGB) >> subplot(1,2,2),imshow(imgCompl)