Inserting zero intensity value in a patch of an digital image.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Arghya Pathak
le 22 Mar 2021
Modifié(e) : Arghya Pathak
le 23 Mar 2021
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 commentaires
Réponse acceptée
Matt J
le 22 Mar 2021
Modifié(e) : Matt J
le 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 commentaires
Matt J
le 22 Mar 2021
You're welcome, but please Accept-click whichever of the answers you deem to have resolved your question.
Plus de réponses (1)
DGM
le 22 Mar 2021
Modifié(e) : DGM
le 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:
![](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:
1 commentaire
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!