[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: thresholding/color question

David Fanning wrote:

> Alex Schuster (alex@pet.mpin-koeln.mpg.de) writes:
> > Isn"t the usage of WHERE discouraged because of being slow?
> If it is, it's news to me. :-)

Hey! I think I read this here in this newsgroup.

> > I always use direct matrix operation for this, like:
> >
> > redmask = scaledImage GT threshold
> > scaledImage = scaled_Image * (1B-redmask) + byte(!D.Table_Size-2) *
> > redmask
> I don't doubt there are speed advantages in matrix operations,
> but unless you had a huge image I doubt very much you
> would notice. And even then, the increase in speed would probably
> be more than offset by the additional memory usage.

Okay, I just tried it out. Indeed, not much of a difference, both
algorithms take about the same time. It depends on how big your index
list will get. Here's my test program:

pro test, dim

	b = bindgen( dim )
	starttime = systime( 1 )
	index = where( b ge 200B )
	if ( index[0] ne -1L ) then b[index] = 255B
	print, 'Time using index list:', systime( 1 ) - starttime,$

	b = bindgen( dim )
	starttime = systime( 1 )
	mask = b ge 100B
	b = temporary( b ) * (1B-mask) + mask * 255B
	print, 'Time using mask array:', systime(1) - starttime,$


An array of dimension 10,000,000 takes about two seconds to compute,
with the index method being slightly faster here. When lowering the
threshold, my method becomes faster.

> Plus, I don't have a clue what this code is doing when I
> read it! Simple things for simple folk, is my motto. :-)

Well, believe me or not, I think my approach _is_ simple :)  Finding out
all those red values, putting them together into a list and then
assigning a new value to each pixel in this list, wow, that's a lot of
work. So I just multiply some arrays :)
Okay, I must admit, it also makes the source code look _cooler_.

> P.S. If my memory serves, Alex, aren't you the one with
> the 10 quadrillion Megs of RAM on your machine? Perhaps
> matrix operations *are* the best thing for you. :-)

Not really, I must admit. Just tested it with a size of 100,000,000, and
the mask method took 300 seconds, compared to 40 using the index list.
Hm, strange. This was a machione with 400 MB memory. On an UltraSparc
with 512 MB (not 10 quadrillion megs), it takes 32 / 37 seconds. Looks
like a constant ratio, unless swapping begins.

test, 1000000000000LLL is still running, can't say anything about that
yet... I will post the results to this newsgroup, if there still is such
a thing as newsgroups when it's finished.

  Alex Schuster     Wonko@weird.cologne.de          PGP Key available