Using Linear indicies to create new image
이전 댓글 표시
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
Mathieu NOE
2023년 11월 30일
it would certainly be more efficient if you could share your code
답변 (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
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
카테고리
도움말 센터 및 File Exchange에서 Region and Image Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

