MATLAB Answers


Display each object in a binary image separately

Asked by Joaquim on 23 Mar 2017
Latest activity Commented on by 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?


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.
I used this instead
[L,num] = bwlabel(BW);
for i=1:num
I dont know how to use regionprops, although I know that it may use less memory.
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.

1 Answer

Answer by Image Analyst
on 23 Mar 2017
 Accepted Answer

Or, simply use ismember() to extract the blob you want. For example
[L, num] = bwlabel(BW);
for k = 1 : num
thisBlob = ismember(L, k);
imshow(thisBlob, []);


I don't know what "calculating each oject" means. Can you describe the steps involved with that?
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!
You can use xcorr2:
outputImage = xcorr2(binaryImage, flippedBinaryImage);

Sign in to comment.