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

Home » Public Forums » archive » Does IDL has histogram matching function?
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
Does IDL has histogram matching function? [message #32803] Thu, 07 November 2002 22:36 Go to next message
tianyf_cn is currently offline  tianyf_cn
Messages: 19
Registered: November 2002
Junior Member
I want to do a histogram matching work between two images with several bands.
But IDL does not provide such functions or procudures.
How can I achieve this?

Thanks in advance.

Sincerely,
Tian.
Re: Does IDL has histogram matching function? [message #32955 is a reply to message #32803] Mon, 18 November 2002 15:49 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul Sorenson (aardvark62@msn.com) writes:

> There is an undocumented keyword to HIST_EQUAL that looks like it
> might do the same thing as Davids HistoMatch. Here is an example:
>
> filename = filepath('ctscan.dat', subdir=['examples', 'data'])
> image = read_binary(filename, data_dims=[256, 256])
>
> desired_hist = histogram(hist_equal(image), min=0, max=255)
>
> window, xsize=3*256, ysize=256
> tv, image, 0
> tv, hist_equal(image), 1
> tv, hist_equal(image, fcn=total(desired_hist, /cumulative)), 2
> end

I think this is probably right, but I think
both this function and the code that I threw off
in a couple of minutes earlier in the week suffers
from a deficiency.

As it happens, I need a histogram-match-by-region
capability. In other words, the user wants to select
a region in an image, and use the histogram of that
region to adjust the histogram of the entire image.

This example and my previous code work if the histograms
are taken from images of the same size. They do not work
correctly (I think) if the histograms use images of different
sizes. In that case, you must normalize the histograms to the
same "total number" of pixels. I'll probably have this on
my web page soon, with the corrections in it. I just didn't
want anyone getting too far down the wrong road here. :-)

Cheers,

David


--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Does IDL has histogram matching function? [message #32997 is a reply to message #32803] Thu, 21 November 2002 15:57 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul Sorenson (aardvark62@msn.com) writes:

> I'm not sure if the implementation of FCN is correct. I'm still thinking
> about it.

I don't know. According to what I read about this,
the method is -- at best -- an approximation
with digital images. It seems to be doing approximately
what I expect it to. Close enough for government work,
anyway.

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Does IDL has histogram matching function? [message #33001 is a reply to message #32955] Thu, 21 November 2002 14:23 Go to previous messageGo to next message
Paul Sorenson is currently offline  Paul Sorenson
Messages: 48
Registered: May 2002
Member
I'm not sure if the implementation of FCN is correct. I'm still thinking
about it. Here is an example:

pro histogram_test

filename = filepath('ctscan.dat', subdir=['examples', 'data'])
image = read_binary(filename, data_dims=[256, 256])

x = findgen(256)/255. ;Ramp from 0 to 1.
y = exp(-((x-.5)/.2)^2) ;Gaussian curve

fcn = total(y, /cumulative)
gauss_image = hist_equal(image, fcn=fcn)

d = total(histogram(gauss_image, min=0, max=255), /cum) ;density
function

device, decomp=0
loadct, 39
;
;When we request a custom distribution curve, the result (in white)
;doesn't touch the ideal curve (in red). Is this an indication
;that the implementation of keyword FCN is incorrect?
;
! p.multi = [0, 2, 1]
plot, bytscl(d)
oplot, bytscl(fcn), color=254 ;red

uniform_image = hist_equal(image)

d = total(histogram(uniform_image, min=0, max=255), /cum) ;density
function
;
;When we request the default uniform distribution, the result (in white)
;touches the ideal curve (in red).
;
plot, bytscl(d)
oplot, bindgen(256), color=254 ;red

end


"David Fanning" <david@dfanning.com> wrote in message
news:MPG.18432a801e0db738989a2e@news.frii.com...
> Paul Sorenson (aardvark62@msn.com) writes:
>
>> There is an undocumented keyword to HIST_EQUAL that looks like it
>> might do the same thing as Davids HistoMatch. Here is an example:
>>
>> filename = filepath('ctscan.dat', subdir=['examples', 'data'])
>> image = read_binary(filename, data_dims=[256, 256])
>>
>> desired_hist = histogram(hist_equal(image), min=0, max=255)
>>
>> window, xsize=3*256, ysize=256
>> tv, image, 0
>> tv, hist_equal(image), 1
>> tv, hist_equal(image, fcn=total(desired_hist, /cumulative)), 2
>> end
>
> I think this is probably right, but I think
> both this function and the code that I threw off
> in a couple of minutes earlier in the week suffers
> from a deficiency.
>
> As it happens, I need a histogram-match-by-region
> capability. In other words, the user wants to select
> a region in an image, and use the histogram of that
> region to adjust the histogram of the entire image.
>
> This example and my previous code work if the histograms
> are taken from images of the same size. They do not work
> correctly (I think) if the histograms use images of different
> sizes. In that case, you must normalize the histograms to the
> same "total number" of pixels. I'll probably have this on
> my web page soon, with the corrections in it. I just didn't
> want anyone getting too far down the wrong road here. :-)
>
> Cheers,
>
> David
>
>
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155




-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Re: Does IDL has histogram matching function? [message #33070 is a reply to message #32997] Fri, 06 December 2002 13:37 Go to previous messageGo to next message
aardvark62 is currently offline  aardvark62
Messages: 6
Registered: November 2002
Junior Member
I think I have found a more accurate algorithm for the FCN keyword.
The algorithm in hist_equal.pro IDL 5.5 and 5.6 is:

if keyword_set(fcn_in) then begin
y2 = bytscl(total(histogram(bytscl(fcn_in)), /CUM), TOP=top)
p = y2[bytscl(p)]
endif else begin
p = BYTSCL(TEMPORARY(p), TOP = top)
endelse

I changed that to:

p = BYTSCL(TEMPORARY(p), TOP = top)

if keyword_set(fcn_in) then begin
y2 = bytarr(top + 1)
f = bytscl(fcn_in, top=top)
f = congrid(f, top+1)
for i=0,top do begin ;invert curve f.
y2[i] = (where(f ge i))[0]
end

p = y2[p]
endif

With that change the resulting output fits the requested FCN more
closely. I used procedure HISTOGRAM_TEST (below) to assess output.
This version of HISTOGRAM_TEST has some fixes from the previous one
that I posted in this thread (I think).

The algorithm that I am proposing yeilds images with grayscales that
don't always reach TOP. This is dictated by the shape of the FCN
curve, and by the fact that caluculations are BYTSCLed. If you really
want to reach TOP, you would have to slightly distort the curve (or
operate at a higher resolution than bytes). I have not tested this,
but one way to reach TOP might be to change...

f = bytscl(fcn_in, top=top)

...to...

f = bytscl(fcn_in, top=top-1)
f[n_elements(f)-1] = top

...which distorts the curve a little.

-Paul Sorenson

pro histogram_test, top=top
;
;Purpose: visually examine the output of HIST_EQUAL by plotting
;cumulative distribution functions.
;
filename = filepath('ctscan.dat', subdir=['examples', 'data'])
image = read_binary(filename, data_dims=[256, 256])

x = findgen(256)/255. ;Ramp from 0 to 1.
y = exp(-((x-.5)/.2)^2) ;Gaussian curve

fcn = total(y, /cumulative)
gauss_image = hist_equal(image, fcn=fcn, top=top) ;Request custom
dist.

d = total(histogram(gauss_image), /cum) ;Resulting distribution.

device, decomp=0
window, /free
loadct, 39
;
;Comepare the ideal requested distribution curve (in red) to the
actual
;resulting distribution curve (in white).
;
!p.multi = [0, 2, 1]
xrange = [0, top+10] ; Somewhat arbitrary.
;xrange = [0, 80] ; An interesting alternative.
plot, bytscl(d), xrange=xrange
oplot, bytscl(congrid(fcn, top+1)), color=254 ;red

print, 'max(gauss_image) = ', max(gauss_image)

uniform_image = hist_equal(image, top=top) ;Request uniform
distribution.

d = total(histogram(uniform_image), /cum) ;Resulting distribution.
;
;Comepare the ideal requested distribution curve (in red) to the
actual
;resulting distribution curve (in white).
;
plot, bytscl(d), xrange=xrange
oplot, bytscl(bindgen(top + 1)), color=254 ;red

end

David Fanning <david@dfanning.com> wrote in message news:<MPG.184720e7d16d5cd5989a41@news.frii.com>...
> Paul Sorenson (aardvark62@msn.com) writes:
>
>> I'm not sure if the implementation of FCN is correct. I'm still thinking
>> about it.
>
> I don't know. According to what I read about this,
> the method is -- at best -- an approximation
> with digital images. It seems to be doing approximately
> what I expect it to. Close enough for government work,
> anyway.
>
> Cheers,
>
> David
Re: Does IDL has histogram matching function? [message #33189 is a reply to message #32803] Thu, 12 December 2002 15:20 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul Sorenson (aardvark62@msn.com) writes:

> There are some things in that Gonzalez and Woods book that really hurt my
> brain. On page 96, they say that G(z) = T(r). Get out of town! :-) How
> can this be? They don't *look* the same in the plots shown on page 98
> (Figure 3.19).

Well, they both are set equal to "s". :-)

> G(z) is the desired cumulative distribution and T(r) is the
> cumulative distribution of the input image. All of this appears in their
> discussion of Histogram Matching.

Yeah, it hurts my brain, too. But I've e-mailed Dr. Gonzales
a couple of times when I've been really stuck, and he is always
nice enough to explain to me where I'm going wrong. (I've even
discovered a couple of errors no one else had yet pointed
out. This could be one of them.)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Does IDL has histogram matching function?
Next Topic: Re: POLYSHADE-like object graphics?

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

Current Time: Wed Oct 08 18:54:06 PDT 2025

Total time taken to generate the page: 0.00680 seconds