필터 지우기
필터 지우기

Using Linear indicies to create new image

조회 수: 3 (최근 30일)
Theodore
Theodore 2023년 11월 30일
댓글: DGM 2023년 12월 1일
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
Mathieu NOE 2023년 11월 30일
it would certainly be more efficient if you could share your code

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
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
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
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

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by