0

I'm trying to do the following in MATLAB:

  • Select some region of interest
  • Give the pixels in that region the value 1 for instance

I'm not sure, would imfreehand be a starting point here for selecting the region of interest. What then?

How can this be done in MATLAB?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

2

Here is a short sample. Since you mentioned imfreehand, I included that but depending on what type of ROI you want to create, impoly or imrect may do a better job:

img = im2double(imread('cameraman.tif'));
imshow(img);
roi = imfreehand;
img2 = img;
img2(roi.createMask) = 1;
imshow(img2);
Bee
  • 2,472
  • 20
  • 26
  • Thanks for your reply and nice answer. We can use `roi = imfreehand`, right? Is there a purpose of using `gca` in `roi = imfreehand(gca);`? – Simplicity Aug 22 '13 at 09:52
  • You are right. `gca` is the default value when omitted. My previous Matlab program dealing with ROI had multiple sets of axes, which forced me to specify which axes `imrect` had to use. In this simple case, there is no need to specify that. I changed the code to reflect your suggestion. – Bee Aug 22 '13 at 15:24