Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > IDL > Help requested ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 205 of 228
Post > Topic >>

Help requested in eradicating FOR loops

by dplatten@[EMAIL PROTECTED] Dec 12, 2007 at 08:40 AM

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
 




 1 Posts in Topic:
Help requested in eradicating FOR loops
dplatten@[EMAIL PROTECTED  2007-12-12 08:40:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:54:21 CDT 2008.