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

Home » Public Forums » archive » Help requested in eradicating 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
Help requested in eradicating FOR loops [message #57539] Fri, 14 December 2007 08:06 Go to previous message
dplatten is currently offline  dplatten
Messages: 32
Registered: December 2007
Member
Dear IDL users,

I would really appreciate some help in removing a nested FOR loop.

FOR x=0, image_width-1 DO BEGIN
FOR y=0, image_height-1 DO BEGIN
; Write the current pixel value
results[(x*mtf_region_height)+y, 1] = image[x,y]
; Calculate the distance of the current pixel from the
line defined
by the
; two points (x1, y1) and (x2, y2).
results[(x*image_height)+y, 0] = ( (y1-y2)*x + (x2-
x1)*y + (x1*y2 -
x2*y1) ) / SQRT( (x2-x1)^2 + (y2-y1)^2 )
ENDFOR
ENDFOR

'image' is a 2d image array
I want to work out the distance of each pixel from a line that is
defined by the two points (x1, y1), (x2, y2) and store this distance,
together with the pixel value in a 'results' array. The 'results'
array has the dimensions [(image_height*image_width), 2].

The above bit of code works but is a bit slow.

Any advice would be much appreciated.

Thanks,

David
Northampton, UK
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: iTools problem
Next Topic: Starting a for loop within an if loop

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

Current Time: Sat Oct 11 14:35:15 PDT 2025

Total time taken to generate the page: 0.32446 seconds