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-pvware > Re: Avoiding FO...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 22 Topic 5614 of 6457
Post > Topic >>

Re: Avoiding FOR loops (version googleplex.infinity)

by Gaurav <selfishgaurav@[EMAIL PROTECTED] > Apr 9, 2008 at 11:13 PM

Dear All,
Over the past two days I was able to think of an algorithm and it
solved my problem. And now, looking at Tom's solution above, it
appears that it is almost the same thing that I came up with.

What I did was to pad up my image with kernelSize/2 pixels all around
and then compare it with tem****ary arrays ****fted all around the
kernel by turn. Wherever the ****fted array was equal to the padded
array, I added one in the final, output array. Run this loop for the
kernel size and you are done. Now it is up to you guys to decide if it
is exactly the same as Tom's or there is some difference and as to
which would be faster. Here follows my code:

################### Code begin ################################
dims = size(img,/dimensions) ; getting the dimensions of input image
output_img = bytarr(dims(0), dims(1))

kernelSize = 5 ;define the kernel size (here, 5)
padSize = FLOOR(kernelSize /2.0) ;calculate the padding to generate
around the original image
paddedImg = bytarr(dims(0)+2*padSize, dims(1)+2*padSize) ;initialize
the padded image
paddedImg(padSize, padSize) = img ;define the padded image
tempImg = bytarr(dims(0)+2*padSize, dims(1)+2*padSize) ;will contain
the padded, final output

for x = -padSize, padSize do begin
	for y =  -padSize, padSize do begin
	if x eq 0 and y eq 0 then continue ;we do not want to compare with
the element itself
	;the x, y loops ****ft the whole image array around the kernel and
compares the ****fted image with the original
	indices = WHERE(paddedImg eq ****FT(paddedImg, x, y)) ;
	tempImg(indices) = finalImg(indices) + 1 ;increment '1' wherever an
eqality is found
	endfor
endfor
output_img = EXTRAC(tempImg, padSize, padSize, dims(0),
dims(1)) ;extract the output image from the padded output image.
################# end of code/algorithm ####################

In my case it works wonderfully well and speeds things up by a factor
of a few hundred times. Any further optimization would be highly
appreciated.

I guess, I ought to go for a manicure for my gnawed nails now.

Cheers,
Gaurav
 




 22 Posts in Topic:
Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-07 05:42:57 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-07 09:19:34 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-07 09:25:26 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-07 09:27:11 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-07 22:31:09 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-08 02:41:04 
Re: Avoiding FOR loops (version googleplex.infinity)
nathan12343 <nathan123  2008-04-08 14:33:45 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-09 05:33:46 
Re: Avoiding FOR loops (version googleplex.infinity)
MichaelT <michael.theu  2008-04-09 05:56:32 
Re: Avoiding FOR loops (version googleplex.infinity)
Tom McGlynn <tam@[EMAI  2008-04-09 08:18:15 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-09 23:13:54 
Re: Avoiding FOR loops (version googleplex.infinity)
Tom McGlynn <tam@[EMAI  2008-04-10 11:49:22 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-10 23:15:39 
Re: Avoiding FOR loops (version googleplex.infinity)
David Fanning <news@[E  2008-04-11 06:56:00 
Re: Avoiding FOR loops (version googleplex.infinity)
"R.G. Stockwell"  2008-04-11 10:15:51 
Re: Avoiding FOR loops (version googleplex.infinity)
David Fanning <news@[E  2008-04-11 10:44:55 
Re: Avoiding FOR loops (version googleplex.infinity)
Greg Hennessy <greg.he  2008-04-11 17:32:39 
Re: Avoiding FOR loops (version googleplex.infinity)
David Fanning <news@[E  2008-04-11 11:38:29 
Re: Avoiding FOR loops (version googleplex.infinity)
weitkamp@[EMAIL PROTECTED  2008-04-11 00:52:05 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-11 05:41:45 
Re: Avoiding FOR loops (version googleplex.infinity)
Tom McGlynn <tam@[EMAI  2008-04-11 08:04:09 
Re: Avoiding FOR loops (version googleplex.infinity)
Gaurav <selfishgaurav@  2008-04-14 22:46:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Wed Dec 3 21:51:48 CST 2008.