Main Content

imdivide

Divide one image into another or divide image by constant

Description

example

Z= imdivide(X,Y)divides each element in the arrayXby the corresponding element in arrayYand returns the result in the corresponding element of the output arrayZ.

Examples

collapse all

This example shows how to divide twouint8arrays.

X = uint8([ 255 0 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]);

Divide each element inXby the corresponding element inY. Note that fractional values greater than or equal to 0.5 are rounded up to the nearest integer.

Z = imdivide(X,Y)
Z =2x3 uint8 matrix5 0 2 1 5 2

Divide each element inYby the corresponding element inX. Note that when dividing by zero, the output is truncated to the range of the integer type.

W = imdivide(Y,X)
W =2x3 uint8 matrix0 255 1 1 0 1

Read a grayscale image into the workspace.

I = imread('rice.png');

估计背景。

background = imopen(I,strel('disk',15));

Divide out the background from the image.

J = imdivide(I,background);

Display the original image and the processed image.

imshow(I)

Figure contains an axes object. The axes object contains an object of type image.

figure imshow(J,[])

Figure contains an axes object. The axes object contains an object of type image.

Read an image into the workspace.

I = imread('rice.png');

Divide each value of the image by a constant factor of 2.

J = imdivide(I,2);

Display the original image and the processed image.

imshow(I)

Figure contains an axes object. The axes object contains an object of type image.

figure imshow(J)

Figure contains an axes object. The axes object contains an object of type image.

Input Arguments

collapse all

First array, specified as a numeric array or logical array of any dimension.

Second array (divisor) to be divided fromX, specified as a numeric or logical array of the same size and class asX, or a numeric scalar of typedouble.

Output Arguments

collapse all

Quotient, returned as a numeric array of the same size asX.Zis the same class asXunlessXis logical, in which caseZis data typedouble. IfXis an integer array, elements of the output that exceed the range of the integer type are truncated, and fractional values are rounded.

Version History

Introduced before R2006a