Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Binary-Images: labeling object edges w/o using bwlabel

207 views
Skip to first unread message

Shal

unread,
Nov 30, 2009, 10:20:23 PM11/30/09
to
Hello there,

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

ImageAnalyst

unread,
Nov 30, 2009, 10:39:13 PM11/30/09
to
Shalini
I didn't go into your code in detail, but if you want to find
perimeters, you can use bwperim() or bwboundaries(). If you don't
like bwlabel(), use its successor bwconncomp(). All of these
functions are in the Image Processing Toolbox.
Regards,
ImageAnalyst

Shal

unread,
Dec 1, 2009, 10:25:09 AM12/1/09
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <58bdb194-2050-4c0e...@p33g2000vbn.googlegroups.com>...


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

ImageAnalyst

unread,
Dec 1, 2009, 4:01:39 PM12/1/09
to
On Dec 1, 10:25 am, "Shal" <shalini_pr...@yahoo.co.in> wrote:
> 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
--------------------------------------------------------------------------
Is there an implied question in this somewhere?
Otherwise, good luck with it.

Shal

unread,
Dec 1, 2009, 7:05:18 PM12/1/09
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <53d6d801-2708-40ae...@j4g2000yqe.googlegroups.com>...

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

ImageAnalyst

unread,
Dec 1, 2009, 9:56:59 PM12/1/09
to
Why don't you just find the perimeter of your binary object by
subtracting the eroded object from the original? Both are fast. Then
just do standard connected components labelling on what's left (the
perimeters). You can find code for that somewhere I'm sure. No need
to calculate distance like you're doing.
0 new messages