Inserting zero intensity value in a patch of an digital image.
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt J
2021-3-22
编辑:Matt J
2021-3-22
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 个评论
Matt J
2021-3-22
You're welcome, but please Accept-click whichever of the answers you deem to have resolved your question.
更多回答(1 个)
DGM
2021-3-22
编辑:DGM
2021-3-22
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/558167/image.png)
% 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/558172/image.jpeg)
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:
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!