comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Image thresholding
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Image thresholding [message #15382] Mon, 17 May 1999 00:00 Go to next message
Dave Brennan is currently offline  Dave Brennan
Messages: 28
Registered: December 1998
Junior Member
Does anyone know of a fast routine or function for searching through a
3D data set and setting numbers within a predetermined range of values
to zero. i.e,

the range is 5 - 10

A data set contains [0,1,2,3,4,5,6,7,8,9]. It becomes
[0,1,2,3,4,0,0,0,0,0]

This would save me a lot of time.


Thanks

Dave Brennan
Re: Image thresholding [message #15455 is a reply to message #15382] Tue, 18 May 1999 00:00 Go to previous messageGo to next message
Struan Gray is currently offline  Struan Gray
Messages: 178
Registered: December 1995
Senior Member
Liam Gumley, Liam.Gumley@ssec.wisc.edu writes:

> With all due respect to my esteemed colleagues
> David Kastrup and David Fanning, I believe the
> fastest method is as follows:
>
> ((a lt 5) or (a gt 10)) * a


Speed is hard to pin down, and I appreciate the august company I
am keeping here, so I won't make any absolutist remarks. However, for
my sort of data on my sort of machines the HISTOGRAM function usually
works as well as or better than direct comparisons:

a = indgen(100)
hist = histogram(a, reverse_indices=r)
a(r(r(5):r(10)-1)) = 0

This is especially good for things like interactive image
thresholding because you only need to calculate the histogram once.
Also, as your datasets get larger you start to save significant
amounts of memory, since the histogram is usually much smaller than
the comparison arrays. For arbitrary data with an unknown maximum or
minimum value, there is a danger that you reference elements of the
reverse_indices array which don't exist (try the above with
a=indgen(10)), but cunning use of the BINSIZE, MAX and MIN keywords
usually solves the problem.

For one-time use further speed gains can be had by only
constructing the histogram for the data range you are interested
in, viz:

a = indgen(100)
hist = histogram(a, min=5, max=10, reverse_indices=r)
a(r(r(0):r(5)-1)) = 0


Struan
Re: Image thresholding [message #15466 is a reply to message #15382] Mon, 17 May 1999 00:00 Go to previous messageGo to next message
Brian Jackel is currently offline  Brian Jackel
Messages: 34
Registered: January 1998
Member
Given

a= [0,1,2,3,4,5,6,7,8,9]

try

b= a * ((a GT 10) OR (a LT 5))

This avoids issues with WHERE not finding a match.

Brian
Re: Image thresholding [message #15470 is a reply to message #15382] Mon, 17 May 1999 00:00 Go to previous messageGo to next message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Liam Gumley wrote:
> With all due respect to my esteemed colleagues David Kastrup and David
> Fanning, I believe the fastest method is as follows:
>
> IDL> a = findgen(10)
> IDL> print, ((a lt 5) or (a gt 10)) * a
> 0 1 2 3 4 0 0 0 0 0
>
> Love those Boolean operators....

Of course, I actually meant

IDL> a = indgen(10)

Reminder to self: Make sure you test suggestions before you post them.

---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley
Re: Image thresholding [message #15471 is a reply to message #15382] Mon, 17 May 1999 00:00 Go to previous messageGo to next message
mgs is currently offline  mgs
Messages: 144
Registered: March 1995
Senior Member
In article <MPG.11a9fd6bc48568689897a7@news.frii.com>, davidf@dfanning.com
(David Fanning) wrote:

> David Kastrup (dak@mailhost.neuroinformatik.ruhr-uni-bochum.de) writes:
>
>> You lose.
>
> I lose!? You mean I always get in trouble if I don't spell
> out every little thing. But where is the learning if people
> don't fall info (and dig themselves out of) a few holes?

That would explain why I'm in the Grand Canyon holding a spoon.

> P.S. Let's just say, without problems, there is no progress. :-)

Speaking of problems and progress. Is there any word on the next release of IDL?

--
Mike Schienle Interactive Visuals, Inc.
mgs@ivsoftware.com Remote Sensing and Image Processing
http://www.ivsoftware.com/ Analysis and Application Development
Re: Image thresholding [message #15473 is a reply to message #15382] Mon, 17 May 1999 00:00 Go to previous messageGo to next message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
David Brennan wrote:
> Does anyone know of a fast routine or function for searching through a
> 3D data set and setting numbers within a predetermined range of values
> to zero. i.e,
>
> the range is 5 - 10
>
> A data set contains [0,1,2,3,4,5,6,7,8,9]. It becomes
> [0,1,2,3,4,0,0,0,0,0]

With all due respect to my esteemed colleagues David Kastrup and David
Fanning, I believe the fastest method is as follows:

IDL> a = findgen(10)
IDL> print, ((a lt 5) or (a gt 10)) * a
0 1 2 3 4 0 0 0 0 0

Love those Boolean operators....

Cheers,
Liam.

---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
1225 W. Dayton St., Madison WI 53706, USA
Phone (608) 265-5358, Fax (608) 262-5974
http://cimss.ssec.wisc.edu/~gumley
Re: Image thresholding [message #15474 is a reply to message #15382] Mon, 17 May 1999 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
David Kastrup (dak@mailhost.neuroinformatik.ruhr-uni-bochum.de) writes:

> You lose.

I lose!? You mean I always get in trouble if I don't spell
out every little thing. But where is the learning if people
don't fall info (and dig themselves out of) a few holes?

Cheers,

David

P.S. Let's just say, without problems, there is no progress. :-)

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Image thresholding [message #15555 is a reply to message #15382] Fri, 21 May 1999 00:00 Go to previous message
REV is currently offline  REV
Messages: 1
Registered: May 1999
Junior Member
DL> c=[0,1,2,3,4,5,6,7,8,9]
IDL> b=c
IDL> c(where(c ge 5 and c le 10)) = 0
IDL> print,c
0 1 2 3 4 0 0 0 0
0


David Brennan <9147261b@clinmed.gla.ac.uk> wrote in article
<3740387C.72B259F7@clinmed.gla.ac.uk>...
> Does anyone know of a fast routine or function for searching through a
> 3D data set and setting numbers within a predetermined range of values
> to zero. i.e,
>
> the range is 5 - 10
>
> A data set contains [0,1,2,3,4,5,6,7,8,9]. It becomes
> [0,1,2,3,4,0,0,0,0,0]
>
> This would save me a lot of time.
>
>
> Thanks
>
> Dave Brennan
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL(rsi) + FORTRAN(digital) + DLL(windows nt)
Next Topic: behavior of arrays

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 23:07:13 PDT 2025

Total time taken to generate the page: 1.12034 seconds