This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

createMask

Create mask within image

createMask is not recommended. Use the createMask method associated with the ROI classes instead, described in ROI Creation Overview.

Syntax

BW = createMask(h)
BW = createMask(h,himage)

Description

BW = createMask(h) returns a mask, or binary image, with 1s inside the ROI object h and 0s everywhere else. The input image must be contained within the same axes as the ROI object.

Create Binary Mask from Ellipse

BW = createMask(h,himage) returns a mask the same size as the image himage, with 1s inside the ROI object h and 0s everywhere else. This syntax is required when the axes that contains the ROI holds more than one image.

Examples

Create Binary Mask from Ellipse

Create an ellipse ROI.

imshow('coins.png');
e = imellipse;

Use the mouse to reshape and reposition the ellipse. Then, create a binary mask from the ROI. Pixels inside the ROI have the value 1, and pixels outside the ROI have the value 0. Display the mask in a new figure.

BW = createMask(e);
figure; imshow(BW)

Input Arguments

collapse all

ROI object, specified as an imellipse, imline, impoint, impoly, or imrect object.

Handle to one image, specified as a handle.

Output Arguments

collapse all

Mask, returned as a binary matrix. The mask is the same size as the input image contained in the same axes as h, or the image himage.

Introduced in R2008a