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

1 回表示 (過去 30 日間)
Jason
Jason 2019 年 8 月 13 日
コメント済み: Image Analyst 2019 年 8 月 13 日
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
position=wait(h)
p = h.getPosition();
position=[p(1) p(2) p(3) p(4)]; % [xmin ymin width height]
delete(h);
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

採用された回答

Image Analyst
Image Analyst 2019 年 8 月 13 日
Use = to assign, not == which is a comparison.
Raw(p(2):(p(2)+p(4)), p(1):(p(1)+p(3))) = 0;
or
mask = h.createmask();
Raw(mask) = 0;
  3 件のコメント
Jason
Jason 2019 年 8 月 13 日
Ah, it because I delete(h) earlier
Jason
Image Analyst
Image Analyst 2019 年 8 月 13 日
Sorry, it's actually createMask, not createmask.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by