Re: Best way to move a window [message #29528] |
Wed, 27 February 2002 22:15  |
marc schellens[1]
Messages: 183 Registered: January 2000
|
Senior Member |
|
|
Ned Horning wrote:
>
> I am writing a progarm that move a 3 x 3 window through an image. From
> what I can tell IDL isn't well suited for the way I have programmed it
> but I can't figure out how to improve it. I expect I'm missing a
> fundamental concept.
>
> The way I currently have it writen is to move the window, one pixel at
> a time and process it like this:
>
> FOR y=1, num_tile_lines - 2 DO BEGIN
> out_tile[y*num_tile_samples] = 0
> FOR x=1, num_tile_samples - 2 DO BEGIN
> IF (((tile_data[x,y] gt 179.99999) AND (tile_data[x,y] lt
> 180.0001)) OR $
> ((tile_data[x+1,y] gt 179.99999) AND (tile_data[x+1,y] lt
> 180.0001)) OR $
> ((tile_data[x-1,y] gt 179.99999) AND (tile_data[x-1,y] lt
> 180.0001)) OR $
> ((tile_data[x,y+1] gt 179.99999) AND (tile_data[x,y+1] lt
> 180.0001)) OR $
> ((tile_data[x,y-1] gt 179.99999) AND (tile_data[x,y-1] lt
> 180.0001)) OR $
> ((tile_data[x+1,y+1] gt 179.99999) AND (tile_data[x+1,y+1] lt
> 180.0001)) OR $
> ((tile_data[x-1,y-1] gt 179.99999) AND (tile_data[x-1,y-1] lt
> 180.0001)) OR $
> ((tile_data[x-1,y+1] gt 179.99999) AND (tile_data[x-1,y+1] lt
> 180.0001)) OR $
> ((tile_data[x+1,y-1] gt 179.99999) AND (tile_data[x+1,y-1] lt
> 180.0001))) THEN $
> out_tile[y*num_tile_samples+x] = 0 ELSE BEGIN
>
> Is there a faster way to do this?
Indeed there is:
;;here we go ------------
kernel=bytarr(3,3)
kernel[*]=1
boolArr=bytarr(num_tile_samples,num_tile_samples)
w=where(abs(tile_data - 180.0) lt 0.0001)
;; check (if necessary)
if w[0] eq -1 then return ;; or whatever
boolArr[w]=1
res=convol(boolArr,kernel,/EDGE_TRUNCATE)
;; these are the indices you want
w1=where(res ge 1)
;; w9=where(res ge 9) ;; these are the ones if you would AND instead of
OR
;; in the example above
out_tile[w1]=0
;;finish ----------------
you may want to check out also the dilate or erode function...
cheers,
marc
|
|
|