Using Linear indicies to create new image

2 visualizaciones (últimos 30 días)
Theodore
Theodore el 30 de Nov. de 2023
Comentada: DGM el 1 de Dic. de 2023
So i have an image that I have used region props to find the pixels that are contained in certain objects.
With this function I have the linear indecies for each pixel. I want to use these indicies to create a new binary image that is the same size as the original with true (Intensity=1) pixels for each of the linear index that correlated to the computed object.
Hopefully this makes sense. I am sure there is a simple solution that would solve this but as of right now I can't figure out what that is.
  1 comentario
Mathieu NOE
Mathieu NOE el 30 de Nov. de 2023
it would certainly be more efficient if you could share your code

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 30 de Nov. de 2023
You need to label your binary image and then use ismember to extract out just certain ID(s) to a new binary image. For example
labeledImage = bwlabel(mask);
% Extract out blobs #3 and 8 to a new binary image:
mask2 = ismember(labeledImage, [3, 8]);
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
  1 comentario
DGM
DGM el 1 de Dic. de 2023
Or to just get all the masks at once
% a mask with 5 blobs
inpict = imread('blobs.png');
mask = im2gray(inpict)>64;
imshow(mask,'border','tight')
% create label image
[labeledImage nblobs] = bwlabel(mask);
% a complete set of masks as a 4D stack
maskstack = labeledImage == reshape(1:nblobs,1,1,1,[]);
% show the mask stack using montage
montage(maskstack,'bordersize',3,'backgroundcolor',[0.2 1 0.8])

Iniciar sesión para comentar.


Matt J
Matt J el 30 de Nov. de 2023
stats=regionprops(BW,'PixelIdxList');
Z0=false(size(BW));
for i=1:numel(stats)
Z=Z0;
Z(stats(i).PixelIdxList)=1;
stats(i).BW=Z; %isolated BW images of each region
end

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by