imcomplement
Complement image
Syntax
Description
computes the complement of the
image J
= imcomplement(I
)I
and returns the result in
J
.
Examples
Create the Complement of a uint8 Array
X = uint8([ 255 10 75; 44 225 100]); X2 = imcomplement(X)
X2 = 2x3 uint8 matrix
0 245 180
211 30 155
Reverse Black and White in a Binary Image
Create the Complement of an Intensity Image
Create the Complement of a Color Image
Read a color image into the workspace.
rgb = imread('yellowlily.jpg');
imshow(rgb)
Display the complement of the image.
c = imcomplement(rgb); imshow(c)
Each color channel of the resulting image is the complement of the corresponding color channel in the original image. Regions that were dark, such as dirt, become light. In the original image, the leaves appear green, and petals appear yellow because of a mixture of red and green signals. In the complement image, the leaves appear purple because the red and blue signals are larger than the green signal. The flower petals appear blue because the blue signal is larger than the red and green channels.
Input Arguments
I
— Input image
RGB image | grayscale image | binary image
Input image, specified as an RGB, grayscale, or binary image.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| logical
Output Arguments
J
— Image complement
RGB image | grayscale image | binary image
Image complement, specified as an RGB, grayscale, or binary image.
J
has the same size and class as the input image,
I
.
More About
Image Complement
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.
Tips
If
I
is a grayscale or RGB image of classdouble
, then you can use the expression1-I
instead of this function.If
I
is a binary image, then you can use the expression~I
instead of this function.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
imcomplement
supports the generation of C code (requires MATLAB® Coder™). For more information, see Code Generation for Image Processing.imcomplement
does not supportint64
anduint64
data types.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
imcomplement
does not supportint64
anduint64
data types.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Image Processing on a GPU.
Version History
Introduced before R2006a
See Also
imabsdiff
| imadd
| imdivide
| imlincomb
| immultiply
| imsubtract
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)