Azzera filtri
Azzera filtri

Using Linear indicies to create new image

3 visualizzazioni (ultimi 30 giorni)
Theodore
Theodore il 30 Nov 2023
Commentato: DGM il 1 Dic 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 Commento
Mathieu NOE
Mathieu NOE il 30 Nov 2023
it would certainly be more efficient if you could share your code

Accedi per commentare.

Risposte (2)

Image Analyst
Image Analyst il 30 Nov 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 Commento
DGM
DGM il 1 Dic 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])

Accedi per commentare.


Matt J
Matt J il 30 Nov 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

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by