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

Re: thresholding/color question




Alex Schuster <alex@pet.mpin-koeln.mpg.de> writes:
> David Fanning wrote:
> 
> > Then, I'd scale my image data like this:
> > 
> >    scaledImage = BytScl(image, Top=!D.Table_Size-4)
> > 
> > I'd find the red pixels and assign them like this:
> > 
> >    redPixels = Where(image GT threshold, count)
> >    IF count GT 0 THEN scaledImage[redPixels] = !D.Table_Size-2
> 
> Isn"t the usage of WHERE discouraged because of being slow? 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'm not sure the masking technique will always be faster.  If you do
an operation count, then you can see that the masking operation costs
4*N operations, where N is the number of pixels. (operations are "GT",
"*" (twice) and "-" (once))

The WHERE technique involves somewhere between N and 2*N operations,
depending on how many pixels are above threshold (one to do the "GT"
operation, and then between 0 and N to do the scatter operation on
scaledImage).  However, I will grant that the scatter operation is
probably slower than a flat-out matrix multiply.

Therefore, I would argue that for large images with few red pixels,
the WHERE operation would be superior (and as David says, use less
memory).  Anybody care to bring this into the real world?

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------