Image Processing Toolbox User's Guide |
Compute 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
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
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.
Example 1
Scale an image by a factor of 2
.
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
.
See Also
imadd
, imcomplement
, imdivide
, immultiply
, imsubtract
imimposemin | immagbox |
© 1994-2005 The MathWorks, Inc.