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

Re: Histogram Hot-shots Required

In article <MPG.11f876f9f15942a98982b@news.frii.com>,
  davidf@dfanning.com (David Fanning) wrote:
> Ok you histogram cowboys. Let's see what ya got!
OK, I grew up on a ranch and I work with histograms so I qualify.

> I don't know if it's early on-set Alzheimers, or
> I'm just pressing with a long soccer weekend coming
> up, or I just haven't had enough beers yet, but
> this one is stumping me. I thought I'd give you
> folks a chance to see if you can explain something
> simply enough that even I can understand it. :-)
I also love challenges! (Must be the Klingon in me)

<lots cut ot>

> In any case, I'm fresh out of ideas as well as beer. So
> I thought I'd turn it over to you. Any ideas will be
> *gratefully* accepted. I'm sure it has something to do
> with that Reverse_Indices keyword, but whatever it is
> escapes me. :-)

You got it! Reverse indices will help you.  Turn to my book on pages
2-53 and 7-163 for the write up on Reverse Indices. But here is how I
would do it.

Given an array created by dist(250) find all the pixels that equal 100.

z = dist(250)
h = histogram(z,reverse=r)
top = n_elements(r)
;r is a run length encoded array where the beginning of the array is an
;index into the rest of the array.
;Have to worry about the case where a pixel value  might equal the
;So create a two arrays from r. The first of the indexes, the second of
;the values.
index = where(r eq top,count)
if count eq 0 then print, 'something wrong'
indices = r[0:index[0]] ;indices of the values
values = r[index[0]+1:*] ;the values only
binIndex = where(values eq 100,count) ;find the pixel value=100
if count eq 0 then print, 'something wrong'
realIndex = binIndex + index[0] ;get the "real" index of it.
;now we have to find where this value falls into the indices.  The r
;array only has begin and end points into the array.
bottom = where( realIndex[0] gt indices,count)
if count eq 0 then print, 'something wrong'
;count is the bottom index of the values. To get all the pixels that
;equal 100 do
binPixels =  r[r[count]:r[count+1]]
print, n_elements(binPixels)
;And just to make sure

Hope this helps!


Ronn Kling
Ronn Kling Consulting

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.