MATLAB Answers


How to select a roi in greyscale image and put values to zero

Asked by Jason
on 13 Aug 2019
Latest activity Commented on by Image Analyst
on 13 Aug 2019
Hello, i have a 12bit greyscale image (tiff) which I want to be able to draw a rectangular roi and fill these values to zero (i.e. black)
This is my code, I cannot see where I am going wrong
Raw=getimage(handles.axes1); % get image from axes component (im using GUIDE)
h = imrect(handles.axes1); % User definable rectangle
p = h.getPosition();
position=[p(1) p(2) p(3) p(4)]; % [xmin ymin width height]
Raw(p(2):(p(2)+p(4)),p(1):(p(1)+p(3)))==0; % put user specified roi to 0 (black)
axes(handles.axes1); cla reset; % Clear current axes
imshow(Raw) % Draw modified image


Sign in to comment.

1 Answer

Answer by Image Analyst
on 13 Aug 2019
 Accepted Answer

Use = to assign, not == which is a comparison.
Raw(p(2):(p(2)+p(4)), p(1):(p(1)+p(3))) = 0;
mask = h.createmask();
Raw(mask) = 0;


Hi IA, thanks for your reply.
I've not used createmask before and tried but got:
Unrecognized method, property, or field 'createmask' for class 'imrect'.
Error in myGUI>pushbutton16_Callback (line 1565)
mask = h.createmask();
Ah, it because I delete(h) earlier
Sorry, it's actually createMask, not createmask.

Sign in to comment.