Borrar filtros
Borrar filtros

Inserting zero intensity value in a patch of an digital image.

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Matt J
Matt J el 22 de Mzo. de 2021
Editada: Matt J el 22 de Mzo. de 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
Image = 10×10
0 0 0 0 0.9870 0.3867 0.8483 0.5475 0.5680 0.4397 0 0 0 0 0.0793 0.5693 0.9440 0.1365 0.5194 0.8375 0 0 0 0 0.4427 0.1354 0.8680 0.7052 0.5171 0.8107 0 0 0 0 0.3621 0.1729 0.1086 0.4782 0.8807 0.2058 0.8458 0.2652 0.9007 0.0565 0.0319 0.4286 0.7780 0.5752 0.2605 0.4845 0.6946 0.2953 0.1541 0.1434 0.8681 0.7628 0.2763 0.9849 0.8964 0.9619 0.4103 0.8696 0.8096 0.1311 0.4722 0.5807 0.9439 0.6320 0.8722 0.4546 0.7041 0.4157 0.6656 0.5574 0.2076 0.0993 0.8457 0.9928 0.9888 0.4718 0.1108 0.6539 0.8086 0.8826 0.2074 0.6357 0.5550 0.8345 0.3979 0.1675 0.6162 0.8855 0.3046 0.6586 0.2301 0.9258 0.2280 0.7135 0.0947 0.3604
For more general region shapes, you can use regionfill
  3 comentarios
Matt J
Matt J el 22 de Mzo. de 2021
You're welcome, but please Accept-click whichever of the answers you deem to have resolved your question.
Arghya Pathak
Arghya Pathak el 22 de Mzo. de 2021
I have accepeted Sir. The answer has resolved my issue to some extent. Thank you very much .

Iniciar sesión para comentar.

Más respuestas (1)

DGM
DGM el 22 de Mzo. de 2021
Editada: DGM el 22 de Mzo. de 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:
  1 comentario
Arghya Pathak
Arghya Pathak el 23 de Mzo. de 2021
Editada: Arghya Pathak el 23 de Mzo. de 2021
Thank you very much for your kind help and valuable suggestions.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by