Documentation Center

  • Trial Software
  • Product Updates

imcomplement

Complement image

Syntax

IM2 = imcomplement(IM)
gpuarrayIM2 = imcomplement(gpuarrayIM)

Description

IM2 = imcomplement(IM) computes the complement of the image IM. IM can be a binary, grayscale, or RGB image. IM2 has the same class and size as IM.

In the complement of a binary image, zeros become ones and ones become zeros; black and white are reversed. In the complement of an intensity or RGB image, each pixel value is subtracted from the maximum pixel value supported by the class (or 1.0 for double-precision images) and 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.

gpuarrayIM2 = imcomplement(gpuarrayIM) computes the complement of the image on a GPU. The input image gpuarrayIM and the return values are gpuArrays. gpuarrayIM2 is a gpuArray with the same underlying class and size as gpuarrayIM. This syntax requires the Parallel Computing Toolbox™.

Code Generation

imcomplement supports the generation of efficient, production-quality C/C++ code from MATLAB. When generating code, imcomplement does not support int64 and uint64 data types. To see the complete list of toolbox functions that support code generation, see List of Supported Functions with Usage Notes.

    Tip   If IM is a grayscale or RGB image of class double, you can use the expression 1-IM instead of this function.

    If IM is a binary image, you can use the expression ~IM instead of this function.

Examples

Create the complement of a uint8 array

X = uint8([ 255 10 75; 44 225 100]);
X2 = imcomplement(X)
X2 =
     0   245   180
   211    30   155

Reverse black and white in a binary image

bw = imread('text.png');
bw2 = imcomplement(bw);
subplot(1,2,1),imshow(bw)
subplot(1,2,2),imshow(bw2)

Create the complement of an intensity image

I = imread('glass.png');
J = imcomplement(I);
imshow(I), figure, imshow(J)

Create the complement of an intensity image on a GPU

 I = gpuArray(imread('glass.png'));
 J = imcomplement(I);
 figure, imshow(I), figure, imshow(J)

See Also

| | | | |

Was this topic helpful?