Image thresholding [message #15382] |
Mon, 17 May 1999 00:00  |
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   |
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   |
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 #15473 is a reply to message #15382] |
Mon, 17 May 1999 00:00   |
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 #15555 is a reply to message #15382] |
Fri, 21 May 1999 00:00  |
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
>
>
|
|
|