| Image Processing Toolbox | ![]() |
Subtract one image from another, or subtract a constant from an image
Syntax
Description
Z = imsubtract(X,Y) subtracts each element in array Y from the corresponding element in array X and returns the difference in the corresponding element of the output array Z. X and Y are real, nonsparse numeric arrays of the same size and class, or Y is a double scalar. The array returned, Z, has the same size and class as X.
If X is an integer array, then elements of the output that exceed the range of the integer type are truncated, and fractional values are rounded.
If X and Y are double arrays, then you can use the expression X-Y instead of this function.
Examples
Subtract two uint8 arrays. Note that negative results are rounded to 0.
X = uint8([ 255 10 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]); Z = imadd(X,Y) Z = 205 0 25 0 175 50
Estimate and subtract the background of the rice image:
I = imread('rice.tif'); blocks = blkproc(I,[32 32],'min(x(:))'); background = imresize(blocks,[256 256],'bilinear'); Ip = imsubtract(I,background); imshow(Ip,[])
Subtract a constant value from the rice image:
See also
imabsdiff, imadd, imcomplement, imdivide, imlincomb, immultiply
| imshow | imtophat | ![]() |