In the code
img = im2double(imread('cameraman.tif'));
imshow(img);
roi = imfreehand(gca);
img2 = img;
img2(roi.createMask) = 1;
imshow(img2);
roi
is the handle to the object generated by imfreehand
. One of the methods (~functions) available through the object (using the handle) is createMask
, which can be accessed with the .
operator. The method generates a type logical
array of the same size as the pixel dimensions of the image. Values in the logical array are either 1
or 0
with values of 1
assigned to entries in the region corresponding to the area selected with the imfreehand
operation. The operation img2(roi.createMask) =1;
indexes into the image img2
(it picks elements in img2
) using the positions in the logical array with value 1
and assigns those elements value 1
.