Vous êtes sur la page 1sur 8

imadd

Add two images or add constant to image


Syntax
Z = imadd(X,Y)
Description
Z = imadd(X,Y) adds each element in array X with the corresponding element in
array Y and returns the sum in the corresponding element of the output array Z. X and
Y are real, nonsparse numeric arrays with the same size and class, or Y is a scalar
double. Z has the same size and class as X, unless X is logical, in which case Z is
double.
If X and Y are integer arrays, elements in the output that exceed the range of the
integer type are truncated, and fractional values are rounded.
Note On Intel architecture processors, imadd can take advantage of the Intel
Performance Primitives Library (IPPL), thus accelerating its execution time.
IPPL is activated if arrays X, Y, and Z are of class logical, uint8, or single and
are of the same class. IPPL is also activated if Y is a double scalar and arrays X
and Z are uint8, int16, or single and are of the same class.
Examples
Add two uint8 arrays. Note the truncation that occurs when the values exceed 255.
X = uint8([ 255 0 75; 44 225 100]);
Y = uint8([ 50 50 50; 50 50 50 ]);
Z = imadd(X,Y)
Z=

255 50 125
94 255 150
Add two images together and specify an output class.
I = imread('rice.png');
J = imread('cameraman.tif');
K = imadd(I,J,'uint16');
imshow(K,[])
Add a constant to an image.
I = imread('rice.png');
J = imadd(I,50);
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(J)
See Also
imabsdiff, imcomplement, imdivide, imlincomb, immultiply, imsubtract, ippl
Image Arithmetic:
Image arithmetic is the implementation of standard arithmetic operations, such as
addition, subtraction, multiplication, and division, on images. Image arithmetic has
many uses in image processing both as a preliminary step in more complex operations
and by itself. For example, image subtraction can be used to detect differences
between two or more images of the same scene or object.
You can do image arithmetic using the MATLAB arithmetic operators. The Image
Processing Toolbox also includes a set of functions that implement arithmetic
operations for all numeric, nonsparse data types. The toolbox arithmetic functions
accept any numeric data type, including uint8, uint16, and double, and return the
result image in the same format. The functions perform the operations in double
precision, on an element-by-element basis, but do not convert images to double-
precision values in the MATLAB workspace. Overflow is handled automatically. The
functions saturate return values to fit the data type. For details, see Image Arithmetic
Saturation Rules.
Note On Intel architecture processors, the image arithmetic functions can take
advantage of the Intel Performance Primitives Library (IPPL), thus
accelerating their execution time. IPPL is only activated, however, when the
data passed to these functions is of specific classes. See the reference pages for
the individual arithmetic functions for more information.
Image Arithmetic Saturation Rules
The results of integer arithmetic can easily overflow the data type allotted for storage.
For example, the maximum value you can store in uint8 data is 255. Arithmetic
operations can also result in fractional values, which cannot be represented using
integer arrays.
MATLAB arithmetic operators and the Image Processing Toolbox arithmetic
functions use these rules for integer arithmetic:
Values that exceed the range of the integer type are saturated to that range.
Fractional values are rounded.
For example, if the data type is uint8, results greater than 255 (including Inf) are set to
255. The following table lists some additional examples.
Result Class Truncated Value
300 uint8 255
-45 uint8 0
10.5 uint8 11
Nesting Calls to Image Arithmetic Functions
You can use the image arithmetic functions in combination to perform a series of
operations. For example, to calculate the average of two images, You
could enter:
I = imread('rice.png');
I2 = imread('cameraman.tif');
K = imdivide(imadd(I,I2), 2); % not recommended
When used with uint8 or uint16 data, each arithmetic function rounds and saturates its
result before passing it on to the next operation. This can significantly reduce the
precision of the calculation. A better way to perform this calculation is to use the
imlincomb function. imlincomb performs all the arithmetic operations in the linear
combination in double precision and only rounds and saturates the final result.
K = imlincomb(.5,I,.5,I2); % recommended

Image subtraction for real time moving object extraction


This paper studies the task of extracting moving object from static irrelevant
background. The implementation is prepared for the purpose of real time application.
Some image processing concepts related to this study are first presented and
improvement is proposed. We have obtained motion mask by applying background
subtraction and consecutive frame differencing. We also propose a reliable
background update and noise reduction operator to facilitate the result of moving
object extraction. The analysis and result are obtained by using Matlab Image
Processing Toolbox Version 6.01.

imsubtract
Subtract one image from another or subtract constant from image
Syntax
Z = imsubtract(X,Y)
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 unless
X is logical, in which case Z is double.
If X is an integer array, elements of the output that exceed the range of the integer
type are truncated, and fractional values are rounded.
Note On Intel architecture processors, imsubtract can take advantage of the
Intel Performance Primitives Library (IPPL), thus accelerating its execution
time. IPPL is activated only if array X is of class uint8, int16, or single.
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 = imsubtract(X,Y)
Z=

205 0 25
0 175 50
Estimate and subtract the background of an image:
I = imread('rice.png');
background = imopen(I,strel('disk',15));
Ip = imsubtract(I,background);
imshow(Ip,[])
Subtract a constant value from an image:
I = imread('rice.png');
Iq = imsubtract(I,50);
figure, imshow(I), figure, imshow(Iq)
See Also
imabsdiff, imadd, imcomplement, imdivide, imlincomb, immultiply, ippl

imabsdiff
Absolute difference of two images
Syntax
Z = imabsdiff(X,Y)
Description
Z = imabsdiff(X,Y) subtracts each element in array Y from the corresponding element
in array X and returns the absolute difference in the corresponding element of the
output array Z. X and Y are real, nonsparse numeric arrays with the same class and
size. Z has the same class and size as X and Y. If X and Y are integer arrays, elements
in the output that exceed the range of the integer type are truncated.
If X and Y are double arrays, you can use the expression abs(X-Y) instead of this
function.
Note On Intel architecture processors, imabsdiff can take advantage of the
Intel Performance Primitives Library (IPPL), thus accelerating its execution
time. IPPL is activated only if arrays X, Y, and Z are of class logical, uint8, or
single, and are of the same class.
Examples
Calculate the absolute difference between two uint8 arrays. Note that the absolute
value prevents negative values from being rounded to zero in the result, as they are
with imsubtract.
X = uint8([ 255 10 75; 44 225 100]);
Y = uint8([ 50 50 50; 50 50 50 ]);
Z = imabsdiff(X,Y)

Z=
205 40 25
6 175 50
Display the absolute difference between a filtered image and the original.
I = imread('cameraman.tif');
J = uint8(filter2(fspecial('gaussian'), I));
K = imabsdiff(I,J);
imshow(K,[]) % [] = scale data automatically
See Also
imadd, imcomplement, imdivide, imlincomb, immultiply, imsubtract, ippl

imcomplement
Complement image
Syntax
IM2 = imcomplement(IM)
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.
If IM is an 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)

See Also
imabsdiff, imadd, imdivide, imlincomb, immultiply, imsubtract

immultiply
Multiply two images or multiply image by constant
Syntax
Z = immultiply(X,Y)
Description
Z = immultiply(X,Y) multiplies each element in array X by the corresponding
element in array Y and returns the product in the corresponding element of the output
array Z.
If X and Y are real numeric arrays with the same size and class, then Z has the same
size and class as X. If X is a numeric array and Y is a scalar double, then Z has the
same size and class as X.
If X is logical and Y is numeric, then Z has the same size and class as Y. If X is
numeric and Y is logical, then Z has the same size and class as X.
immultiply computes each element of Z individually in double-precision floating
point. If X is an integer array, then elements of Z exceeding the range of the integer
type are truncated, and fractional values are rounded.
Note On Intel architecture processors, immultiply can take advantage of the
Intel Performance Primitives Library (IPPL), thus accelerating its execution
time. IPPL is activated only if arrays X, Y, and Z are of class logical, uint8, or
single, and are of the same class.
Example
Multiply an image by itself. Note how the example converts the class of the image
from uint8 to uint16 before performing the multiplication to avoid truncating the
results.
I = imread('moon.tif');
I16 = uint16(I);
J = immultiply(I16,I16);
imshow(I), figure, imshow(J)
Scale an image by a constant factor:
I = imread('moon.tif');
J = immultiply(I,0.5);
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(J)
See also
imabsdiff, imadd, imcomplement, imdivide, imlincomb, imsubtract, ippl

imdivide
Divide one image into another or divide image by constant
Syntax
Z = imdivide(X,Y)
Description
Z = imdivide(X,Y) divides each element in the array X by the corresponding element
in array Y and returns the result in the corresponding element of the output array Z. X
and Y are real, nonsparse numeric arrays with the same size and class, or Y can be a
scalar double. Z has the same size and class as X and Y.
If X is an integer array, elements in the output that exceed the range of integer type
are truncated, and fractional values are rounded.
Note On Intel architecture processors, imdivide can take advantage of the
Intel Performance Primitives Library (IPPL), thus accelerating its execution
time. IPPL is activated only if arrays X and Y are of class uint8, int16, or
single and are of the same size and class.
Example
Divide two uint8 arrays. Note that fractional values greater than or equal to 0.5 are
rounded up to the nearest integer.
X = uint8([ 255 10 75; 44 225 100]);
Y = uint8([ 50 20 50; 50 50 50 ]);
Z = imdivide(X,Y)
Z=
5 1 2
1 5 2
Estimate and divide out the background of the rice image.
I = imread('rice.png');
background = imopen(I,strel('disk',15));
Ip = imdivide(I,background);
imshow(Ip,[])
Divide an image by a constant factor.
I = imread('rice.png');
J = imdivide(I,2);
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(J)
See Also
imabsdiff, imadd, imcomplement, imlincomb, immultiply, imsubtract, ippl

imlincomb
Linear combination of images
Syntax
Z = imlincomb(K1,A1,K2,A2,...,Kn,An)
Z = imlincomb(K1,A1,K2,A2,...,Kn,An,K)
Z = imlincomb(..., output_class)
Description
Z = imlincomb(K1,A1,K2,A2,...,Kn,An) computes
K1*A1 + K2*A2 + ... + Kn*An
where K1, K2, through Kn are real, double scalars and A1, A2, through An are real,
nonsparse, numeric arrays with the same class and size. Z has the same class and size
as A1.
Z = imlincomb(K1,A1,K2,A2,...,Kn,An,K) computes
K1*A1 + K2*A2 + ... + Kn*An + K
where imlincomb adds K, a real, double scalar, to the sum of the products of K1
through Kn and A1 through An.
Z = imlincomb(...,output_class) lets you specify the class of Z. output_class is a string
containing the name of a numeric class.
When performing a series of arithmetic operations on a pair of images, you can
achieve more accurate results if you use imlincomb to combine the operations, rather
than nesting calls to the individual arithmetic functions, such as imadd. When you
nest calls to the arithmetic functions, and the input arrays are of an integer class, each
function truncates and rounds the result before passing it to the next function, thus
losing accuracy in the final result. imlincomb computes each element of the output Z
individually, in double-precision floating point. If Z is an integer array, imlincomb
truncates elements of Z that exceed the range of the integer type and rounds off
fractional values.
On Intel architecture processors, imlincomb can take advantage of the Intel
Performance Primitives Library (IPPL), thus accelerating its execution time. IPPL is
activated only in the following cases:
Z = imlincomb( 1.0, A1, 1.0, A2)
Z = imlincomb( 1.0, A1,-1.0, A2)
Z = imlincomb(-1.0, A1, 1.0, A2)
Z = imlincomb( 1.0 , A1, K)
where A1, A2, and Z are of class uint8, int16, or single and are of the same class.
Examples
Example 1
Scale an image by a factor of 2.
I = imread('cameraman.tif');
J = imlincomb(2,I);
imshow(J)
Example 2
Form a difference image with the zero value shifted to 128.
I = imread('cameraman.tif');
J = uint8(filter2(fspecial('gaussian'), I));
K = imlincomb(1,I,-1,J,128); % K(r,c) = I(r,c) - J(r,c) + 128
figure, imshow(K)
Example 3
Add two images with a specified output class.
I = imread('rice.png');
J = imread('cameraman.tif');
K = imlincomb(1,I,1,J,'uint16');
figure, imshow(K,[])
Example 4
To illustrate how imlincomb performs all the arithmetic operations before truncating
the result, compare the results of calculating the average of two arrays, X and Y, using
nested arithmetic functions and then using imlincomb.
In the version that uses nested arithmetic functions, imadd adds 255 and 50 and
truncates the result to 255 before passing it to imdivide. The average returned in
Z(1,1) is 128.
X = uint8([ 255 10 75; 44 225 100]);
Y = uint8([ 50 20 50; 50 50 50 ]);
Z = imdivide(imadd(X,Y),2)
Z=
128 15 63
47 128 75
imlincomb performs the addition and division in double precision and only truncates
the final result. The average returned in Z2(1,1) is 153.
Z2 = imlincomb(.5,X,.5,Y)
Z2 =
153 15 63
47 138 75
See Also
imadd, imcomplement, imdivide, immultiply, imsubtract
ippl
Check for presence of Intel Performance Primitives Library (IPPL)
Syntax
TF = ippl
[TF B] = ippl
Description
The Intel Performance Primitives Library (IPPL) provides a collection of basic
functions used in signal and image processing. The IPPL takes advantage of the
parallelism of the Single-Instruction, Multiple-Data (SIMD) instructions that make up
the core of the MMX technology and Streaming SIMD Extensions. These instructions
are available only on the Intel architecture processors. IPPL is used by some of the
Image Processing Toolbox functions to accelerate their execution time.
TF = ippl returns true (1) if IPPL is available and false (0) otherwise.
[TF B] = ippl returns an additional column cell array B. Each row of B contains a
string describing a specific IPPL module.
When IPPL is available, the Image Processing Toolbox image arithmetic functions
(imabsdiff, imadd, imsubtract, imdivide, immultiply, and imlincomb) and the imfilter
function take advantage of it. Toolbox functions that use these functions also benefit.
Notes
IPPL is utilized only for some data types and only under specific conditions. See the
help sections of the functions listed above for detailed information on when IPPL is
activated.
To disable use of the IPPL, define a system environment variable called
IPT_IPPL_OFF and set it to any value. To create an environment variable, right-click
the My Computer icon on your desktop and click Properties. On the Advanced
panel, click Environment Variables. In the System variables section, click New.
The ippl function is likely to change.
See Also
imabsdiff, imadd, imdivide, imfilter, imlincomb, immultiply, imsubtract