Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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, unless X is logical, in which case Z is X = uint8([ 255 0 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]); Z = imdivide(X,Y)double.

If X is an integer array, elements in the output that exceed the range of integer type are truncated, and fractional values are rounded.

If X and Y are numeric arrays of the same size and class, you can use the expression X./Y instead of imdivide.

Examples

collapse all

This example shows how to divide two uint8 arrays.

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

Divide each element in X by the corresponding element in Y. 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 matrix

   5   0   2
   1   5   2

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

W = imdivide(Y,X)
W = 2x3 uint8 matrix

     0   255     1
     1     0     1

Read a grayscale image into the workspace.

I = imread('rice.png');

Estimate the background.

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
imshow(J,[])

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
imshow(J)

Introduced before R2006a

Was this topic helpful?