How to match pixel locations to blob identity with region props
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am using regionprops to identify blobs in a binary image. I am able to detect a couple of blobs, get their centroids and all the properties using the function regionprops.
I would like now to estimate/calculate the direction of the objects. Since they are not simmetrical but more like "comet shaped", I thought one way to go would be to get all pixels of each blob (using the PixelList property) and calculate how many of them are below or above the minor axis of the blob....basically where most pixels are, that's where the front part of the objecft is (perhaps there are better methods but this is the simplest one I could think of).
To do so, I would need to determine which pixels belong to each blob, which is not given by any property of the function regionprops.
Maybe is just a matter of finding an easy nearestneighbor search but so far I was not lucky.
this is my code
%% these lines just import an image and subtract background in order to detect the objects
I = imread('image1.png');
B = imread('bknd.png');
D = imabsdiff(I,B);
Db = im2bw(D,[],0.07); % image is thresholded and binarized
Db2 = bwareaopen(Db, 5); % remove objects having less than 5 pixels
se = strel('disk',6,6); % shape used to dilate objects
Db3 = imdilate(Db2,se);
f= figure();
[labeledImage, numSpots] = bwlabel(Db3);
boundaries=bwboundaries(labeledImage); % coordinates of blob boundaries: I initially thought to use them but they are kind of offset relative to the blobs which makes them useless
stats = regionprops('struct',Db3,'Centroid','PixelList','PixelIdxList','Orientation','MajorAxisLength','MinorAxisLength');
centers = vertcat(stats.Centroid); % [stats(1).Centroid(1), stats(1).Centroid(2);stats(2).Centroid(1), stats(2).Centroid(2)];
angles = horzcat(stats.Orientation);
pixels = stats.PixelList;
pixel_idx = stats.PixelIdxList;
diameters = mean([stats.MajorAxisLength stats.MinorAxisLength],2);
radii = diameters/2;
Major_axes = horzcat(stats.MajorAxisLength);
Minor_axes = horzcat(stats.MinorAxisLength);
imshow(labeledImage)
%% find centroid axes
hold on
scatter(centers(:,1),centers(:,2),'r','filled')
0 comentarios
Respuestas (1)
Shashank Gupta
el 18 de Nov. de 2020
Hi,
regionprops function have one property which finds orientations of the blobs, you could directly use them to find the direction of the blobs, I did see that you calculated the orientation but you are not using them anywhere. can you elaborate why orientation property will not help you out? Because what I understood is you want to know the direction of the object and orientation will give you the angle that the major axis of the blob makes it with x-axis, which I think is the way to find the direction of the object. Correct me If I am wrong here.
Ver también
Categorías
Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!