Prerequisite: RGB image representation
MATLAB stores most images as two-dimensional matrices, in which each element of the matrix corresponds to a single discrete pixel in the displayed image. Some images, such as truecolor images, represent images using a three-dimensional array. In truecolor images, the first plane in the third dimension represents the red pixel intensities, the second plane represents the green pixel intensities, and the third plane represents the blue pixel intensities.
In the complement of a binary image, zeros become ones and ones become zeros. Black and white are reversed.
In the complement of a grayscale or color image, each pixel value is subtracted from the maximum pixel value supported by the class (or 1.0 for double-precision images). The difference is used as the pixel value in the output image. In the output image, dark areas become lighter and light areas become darker. For color images, reds become cyan, greens become magenta, blues become yellow, and vice versa.
- Read the image using imread function.
- Complement the image using imcomplement function.
- Display the image using imshow.
Below is the implementation:
Complement of Binary Image:
Here in binary image 0 becomes 1, black and white are reversed.
Complement of colored Image:
Each color channel of the resulting image is the complement of the corresponding color channel in the original image. Regions that were dark, become light. In the original image, the leaves appear green, and petals appear red. In the complement image, the leaves appear magenta. The flower petals appear cyan.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- MATLAB | Complement colors in a Binary image
- MATLAB | Complement colors in RGB Image
- MATLAB | Complement colors in a Grayscale Image
- MATLAB | RGB image to grayscale image conversion
- MATLAB | Converting a Grayscale Image to Binary Image using Thresholding
- Extract bit planes from an Image in Matlab
- Image Processing in MATLAB | Fundamental Operations
- MATLAB | RGB image representation
- MATLAB | Display histogram of a grayscale Image
- LSB based Image steganography using MATLAB
- Display the red, green and blue color planes of a color image in MATLAB
- Image Resizing in Matlab
- Flip image across Secondary Diagonal in MATLAB
- Matlab | Edge Detection of an image without using in-built function
- Matlab | Erosion of an Image
- Matlab | Dilation of an Image
- Create Mirror Image using MATLAB
- How to vertically flip an Image using MATLAB
- Matlab program to rotate an image 180 degrees clockwise without using function
- MATLAB - Ideal Lowpass Filter in Image Processing
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai