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

Package: images.roi

Create binary mask image from ROI

Syntax

bw = createMask(ROI)
bw = createMask(ROI,m,n)
bw = createMask(ROI,I)

Description

example

bw = createMask(ROI) returns a binary mask image with pixels inside the ROI set to true and pixels outside the ROI set to false.

bw = createMask(ROI,m,n) returns a binary mask image that is size [m,n].

bw = createMask(ROI,I) returns a binary mask image that is the size of the image I.

Examples

collapse all

Read image into the workspace and display it.

I = imread('pears.png');
imshow(I)

Draw an elliptical ROI on the image, using the Center parameter to specify the location of the ellipse and theSemiAxes parameter to specify the shape of the ellipse. The example also specifies that the edge of the ellipse is a striped line.

h = drawellipse('Center',[447 204],'SemiAxes',[78 72], ...
    'RotationAngle',287,'StripeColor','m');

Get a binary mask from the ROI. Pixels inside the ROI are true and pixels outside the ROI are false. Display the mask.

mask = createMask(h);
imshow(mask)

Input Arguments

collapse all

Row dimension of the mask image, specified as a positive integer.

Column dimension of the mask image, specified as a positive integer.

Input image, specified as a numeric array.

Output Arguments

collapse all

Binary mask image, returned as a logical array.

Data Types: logical

Tips

  • If you specify a mask size that does not match the size of the image associated with the ROI object, then createMask crops or zero-pads the mask to the specified size. The image associated with the ROI object is ROI.Parent.Children(2,1).CData.

Introduced in R2018b