Using Linear indicies to create new image
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Image Analyst
2023-11-30
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 个评论
DGM
2023-12-1
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])
Matt J
2023-11-30
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!