Re: Can I do this without using loops? [message #6301] |
Sat, 08 June 1996 00:00 |
bowman
Messages: 121 Registered: September 1991
|
Senior Member |
|
|
In article <4pcm41$64r@vixen.cso.uiuc.edu>, santanu@glibm5.cen.uiuc.edu (S
Bhattacharyya) wrote:
> Regarding loops, I am kinda in the same boat. My advisor
> keeps complaining about how slow our code runs...We don't seem to
> know any better around here :-)
>
> Q1) I have a generic array foo(x,y). I'd like to divide each column
> by its max. Can this be done without looping ?
>
> Q2) I have a generic array foo=fltarr(a,b). I'd like to copy findgen(b)
> into every column. Any way of doing this without loops ?
It is always the *innermost* loop that you need to worry about. Of course
you want to avoid taking large strides in memory in the innermost loop, as
well as using array syntax. A2 (below) should run very fast. I'm using
the first quadrant convention for subscripts (i.e., (i,j) corresponds to
(x,y), so to me a column is the second subscript. You may need to reverse
that.
A1)
FOR i = 0, ni-1 DO foo(i,*) = foo(i,*)/MAX(foo(i,*))
A2)
FOR j = 0, nj-1 DO foo(*,j) = FLOAT(j)
Regards, Ken Bowman
--
Kenneth P. Bowman, Assoc. Prof. 409-862-4060
Department of Meteorology 409-862-4132 fax
Texas A&M University bowman@csrp.tamu.edu
College Station, TX 77843-3150
Satellite ozone movies on CD-ROM --> http://www.lenticular.com/
|
|
|
Re: Can I do this without using loops? [message #6303 is a reply to message #6301] |
Sat, 08 June 1996 00:00  |
santanu
Messages: 8 Registered: March 1996
|
Junior Member |
|
|
Regarding loops, I am kinda in the same boat. My advisor
keeps complaining about how slow our code runs...We don't seem to
know any better around here :-)
Q1) I have a generic array foo(x,y). I'd like to divide each column
by its max. Can this be done without looping ?
Q2) I have a generic array foo=fltarr(a,b). I'd like to copy findgen(b)
into every column. Any way of doing this without loops ?
Any pointers greatly appreciated.
Regards,
Santanu
|
|
|
Re: Can I do this without using loops? [message #6308 is a reply to message #6301] |
Thu, 06 June 1996 00:00  |
Bruce E Thomason
Messages: 6 Registered: March 1996
|
Junior Member |
|
|
Re: Finding larger of pixel set.
try:
x = image_1
y = image_2
bigger_of_x_y = x > y
or
bigger_of_x_y = y > x
This seems to work in Wave - not sure about IDL.
Cheers - Bruce
--
{!}
/~~~~~\....:
{(o)-(o)}
----------------------------------OOo----(_)----oOO--------- ---------
Dynamic System Solutions Real-Time System Developers
331 Franklin St. Specializing In Test & Measurement &
Columbus, IN 47201 Scientific Visualization
|
|
|
Re: Can I do this without using loops? [message #6321 is a reply to message #6308] |
Wed, 05 June 1996 00:00  |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
In article <31B59C2D.C@dundee.ac.uk>, Peter Clinch <p.j.clinch@dundee.ac.uk> writes:
> Can't quite see how, but I have a feeling there's a Better Way...
>
> I have a couple of images, same size, and I need to compare the two and
> take a result which has the highest value from either of the inputs. Ay
> the mo. I'm just using loops through all the pixels using an if greater
> than comparison, and it takes ages... :(
That is an easy one, just use the > operator.
IDL> a = [[1,2,3],[1,2,3],[1,2,3]]
IDL> b = [[3,2,1],[3,2,1],[3,2,1]]
IDL> print, a
1 2 3
1 2 3
1 2 3
IDL> print, b
3 2 1
3 2 1
3 2 1
IDL> print, a>b
3 2 3
3 2 3
3 2 3
____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
|
|
|
Re: Can I do this without using loops? [message #6322 is a reply to message #6321] |
Wed, 05 June 1996 00:00  |
peter
Messages: 80 Registered: February 1994
|
Member |
|
|
Peter Clinch (p.j.clinch@dundee.ac.uk) wrote:
: Can't quite see how, but I have a feeling there's a Better Way...
: I have a couple of images, same size, and I need to compare the two and
: take a result which has the highest value from either of the inputs. Ay
: the mo. I'm just using loops through all the pixels using an if greater
: than comparison, and it takes ages... :(
result = a > b
will place the greater of a and b in result, on a pixel=by-pixel basis.
Even if the > function didn't exist, the following would do it without
loops
test = a gt b
result = a*test + b*(1-test)
Peter
|
|
|