MATLAB Answers

Display each object in a binary image separately

23 views (last 30 days)
Joaquim
Joaquim on 23 Mar 2017
Commented: Image Analyst on 27 Mar 2017
Hello everybody,
I have an image, with undefined number of objects, just like the image below.
I want to create an image for each one of the objects. For this case, I want to create 4 images each one with only one object. The new images should have the same size as the original image.
Is there anyone who could help me?
Cheers,
Joaquim

  3 Comments

Rik
Rik on 23 Mar 2017
You can look into regionprops. This will identify the number of objects and give you an idea about how to proceed. If you can't make sense of the usage of this function, do get back and we will try to help you.
Joaquim
Joaquim on 23 Mar 2017
I used this instead
[L,num] = bwlabel(BW);
[sx,sy]=size(BW);
a=L;
element=zeros(sx,sy,num);
for i=1:num
a(L~=i)=0;
a(L==i)=1;
element(:,:,i)=a(:,:);
a=L;
end
I dont know how to use regionprops, although I know that it may use less memory.
Rik
Rik on 23 Mar 2017
As long as it gets the job done it usually doesn't matter how efficient your code is in terms of memory (in most of my cases anyway).

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 23 Mar 2017
Or, simply use ismember() to extract the blob you want. For example
[L, num] = bwlabel(BW);
for k = 1 : num
thisBlob = ismember(L, k);
figure
imshow(thisBlob, []);
end

  6 Comments

Show 3 older comments
Image Analyst
Image Analyst on 26 Mar 2017
I don't know what "calculating each oject" means. Can you describe the steps involved with that?
Joaquim
Joaquim on 27 Mar 2017
Sorry, I'll try to be clearer. 1st: Separate each object in a binary image. (done) 2nd: Flip each object along the x-axis. (done) 3rd: calculate the cross correlation between the flipped object and each one of the other objects (each object in the original image, except the object that was flipped) 4th: Identify, for each flipped object, the object in the original image wich has the maximum of correlation with the flipped object. ( additional steps)
5th- if the maximum correlated object has more than 10 voxels, hold the object. Otherwise set the value of the original object to 0. Last step: return an image with all the original objects that follow the two criteria 9maximum correlation and overlapping of more than 10 voxels).
I dont know if I explained well the last two steps, but what I really need is the other steps. If you could help me I would be very grateful!
Image Analyst
Image Analyst on 27 Mar 2017
You can use xcorr2:
outputImage = xcorr2(binaryImage, flippedBinaryImage);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!