[Numpy-discussion] binary thinning
Bob Klimek
klimek at grc.nasa.gov
Tue Dec 7 15:19:17 CST 2004
Hi,
I've been playing around with the binary_hit_or_miss function in the
nd_image and it seems to work well in general. I understand that binary
thinning can be generated by using hit_or_miss, however I can't seem to
get it to work right. Anyone have a code snippet that does the job?
I follow the procedure at:
http://homepages.inf.ed.ac.uk/rbf/HIPR2/thin.htm
My implementation is as follows:
## from HIPR2 web site
## [0,0,0]
## [x,1,x]
## [1,1,1]
struct1 = numarray.array(
[[0, 0, 0],
[0, 1, 0],
[1, 1, 1]])
struct2 = numarray.array(
[[1, 1, 1],
[0, 0, 0],
[0, 0, 0]])
## [x,0,0]
## [1,1,0]
## [x,1,x]
struct3 = numarray.array(
[[0, 0, 0],
[1, 1, 0],
[0, 1, 0]])
struct4 = numarray.array(
[[0, 1, 1],
[0, 0, 1],
[0, 0, 0]])
b = []
for i in range(4):
temp = ND.binary_hit_or_miss(a, struct1, struct2)
b.append(temp)
temp = ND.binary_hit_or_miss(a, struct3, struct4)
b.append(temp)
struct1 = ND.rotate(struct1, 90)
struct2 = ND.rotate(struct2, 90)
struct3 = ND.rotate(struct3, 90)
struct4 = ND.rotate(struct4, 90)
result = b[0]
for i in range(7):
result = numarray.logical_or(result, b[i+1])
result = a - result
Bob
More information about the Numpy-discussion
mailing list