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

J
Jason · Feb 7, 2024 · 1.9K views
Question
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  
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 28, 2026

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;

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!