Sorry this may be a bit lengthy post.
I wish to label the edges of objects in an image without the use of bwlabel. I tried the following code, but it does not give me quite the results I want. It is also slow, probably since I am using recursion.
PixInfo= is a struct type with three fields: rowNo, colNo, and label. This data-type storage contains all the edges to the objects found in given Image.
% Code:
counter=1;
thresh=5;
for i= 1: length(PixInfo)
[counter PixInfo]= labelpix( i, counter, thresh, PixInfo);
end
%%% labelpix is a recursive function
function [counter PixInfo]= labelpix(idx, counter, thresh, PixInfo)
if (isempty(PixInfo(idx).label))
PixInfo(idx).label= counter;
counter= counter+1;
end
currentPix= [PixInfo(idx).colNo PixInfo(idx).rowNo];
for j= 1:length(PixInfo)
if (isempty(PixInfo(j).label) && j ~= idx)
tmpPix= [PixInfo(j).colNo PixInfo(j).rowNo];
dist= (currentPix(1)-tmpPix(1))^2 + (currentPix(2)-tmpPix(2))^2;
if (dist < thresh)
PixInfo(j).label= PixInfo(idx).label;
[counter PixInfo]= labelpix(j, counter, thresh, PixInfo);
end
end
end
----------
To sum up, I am calculating the distance between each edge-element and searches for other edges within the distance threshold to associate with first group and recursively repeat this edge-pair find until last edge is added to the group (in orther words the group is exhausted) and the algorithm repeats the process with next ungrouped data (edges).
Any comments will be appreciated on improving an algorithm and if there is a better approach plz advise.
Thanks!
Shalini
Thank You,
I appreciate the response. I think I understand what you mentioned with respect to bwperim and bwboundaries. Although, I wanted to write a method/ algorithm that could be used for inexpensive less computational processor, if I wish to port the same to some processor. I was using matlab to implemnet and test the approach.
--
Regards,
Shalini
So I tried working on this code further. Seems my coding method is not very efficient. It take ~95 sec to label object in one frame. But the code is working, meaning the approach is fine, threshold is a critical ans makes the difference in performance. I think i might have to code it in C to use stack and linked-list. I have never used the same concept in matlab.
--
Shal