comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Thinning algorithm without for loops
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Thinning algorithm without for loops [message #55285 is a reply to message #55193] Wed, 08 August 2007 00:33 Go to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
[...]
>
> This code implements the first iteration of Zhang-Suen thinning
> without a single for loop!
>

You are shifting "img" too many times... you only need to compute
your neighbors values p1... p8 first, and then you can have the
next statements use that values instead, for instance

tot=p1+p2+...+p8

and so on for the other conditions.


Ciao,
Paolo

> PRO zsthin,img,thinimg
>
> siz=size(img)
>
> ;Array to hold the sums we're looking for
> tot=lonarr(siz[1],siz[2])
>
> tot+=shift(img,1,0)
> tot+=shift(img,1,1)
> tot+=shift(img,1,-1)
> tot+=shift(img,0,1)
> tot+=shift(img,0,-1)
> tot+=shift(img,-1,0)
> tot+=shift(img,-1,1)
> tot+=shift(img,-1,-1)
>
> cond3=intarr(siz[1],siz[2])
>
> cond3[*,*]=1
>
> cond3*=shift(img,1,0)
> cond3*=shift(img,-1,0)
> cond3*=shift(img,0,-1)
>
> ;4. If P[1]*P[3]*P[5]=0
>
> cond4=intarr(siz[1],siz[2])
> cond4[*,*]=1
>
> cond4*=shift(img,0,1)
> cond4*=shift(img,1,0)
> cond4*=shift(img,0,-1)
>
> ;2. The number of 0-1 transitions in the ordered sequence
> ;P[1],P[2],...,P[8],P[1] Is exactly 1
>
>
> p1=shift(img,0,1)
> p2=shift(img,1,1)
> p3=shift(img,1,0)
> p4=shift(img,1,-1)
> p5=shift(img,0,-1)
> p6=shift(img,-1,-1)
> p7=shift(img,-1,0)
> p8=shift(img,-1,1)
>
> cond2=intarr(siz[1],siz[2])
>
> p=[[[p1]],[[p2]],[[p3]],[[p4]],[[p5]],[[p6]],[[p7]],[[p8]],[ [p1]]]
>
> FOR i=0,7 DO BEGIN
> wh=where(p[*,*,i] eq 0 AND p[*,*,i+1] eq 1)
> cond2[wh]+=1
> ENDFOR
>
> tvscl,cond2
>
> wh=where(cond2 eq 1)
>
> cond2[*,*]=0
>
> cond2[wh]=1
>
> wh=where(tot GE 2 AND tot LE 6 AND cond3 eq 0 AND cond4 eq 0 AND cond2
> eq 1)
>
> wh11=intarr(siz[1],siz[2])
>
> wh11[wh]=1
>
> newimg=img-wh11
>
> newimg>=0
>
>
> END
>
>
> I'll do the second subiteration in a bit, should be too hard.
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: byte offset in POINT_LUN
Next Topic: Question regarding HDF file

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 00:03:53 PDT 2025

Total time taken to generate the page: 7.92155 seconds