Inserting zero intensity value in a patch of an digital image.
2 views (last 30 days)
Show older comments
My question is how to insert zero intensity value in a patch of an digital image with the help of MATLAB code ? Suppose it is a 16 by 16 patch. Also how to make a curve line or any arbitrary shape having zero intensity value within a digital image ?? Please help me with some easy codes along with an example.
0 Comments
Accepted Answer
Matt J
on 22 Mar 2021
Edited: Matt J
on 22 Mar 2021
Suppose it is a 16 by 16 patch.
For a rectangular region, you can just use simple subscript indexing to set those pixels to zero. Here's an example with a 4x4 patch.
Image=rand(10);
Image(1:4,1:4)=0
For more general region shapes, you can use regionfill
3 Comments
Matt J
on 22 Mar 2021
You're welcome, but please Accept-click whichever of the answers you deem to have resolved your question.
More Answers (1)
DGM
on 22 Mar 2021
Edited: DGM
on 22 Mar 2021
If you want something interactive that works with color images, the MIMT toolbox has a mask editing GUI that supports freehand, polygon, elliptical and rectangular selections. It's awkward, but it works.
inpict=imread('sources/table.jpg');
% launch the GUI
% select the manual selection type (freehand, polygon, etc) from the dropdown
% select the selection mode (replace, add, etc) from the dropdown
% hit 'start manual selection', click on the image to start
% make selection, repeat as necessary
% when done, use the box at the top of the sidebar to export it to the
% workspace (here, i exported it to the variable "mask"
immask('inpict')
This is what the GUI looks like during selection:
% since we're using MIMT, these functions are available
% this uses the mask to change the ROI to a specified color tuple
outpict=replacepixels([0 0 0],inpict,mask);
% view the image
imshow2(outpict,'tools');
This yields the resultant picture:
Of course, if you want something programmatic, this isn't going to help. I'm pretty sure that there are other mask generation GUI tools out there too. EDIT: yeah, regionfill() would be good too.
MIMT is here:
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!