代码
Pro test_his
; Read a flat binary file with an image.
file = FILE_WHICH('ctscan.dat')
scan = READ_BINARY(file, DATA_DIMS=[256,256])
; Compute the image histogram, using the default bin size of 1.
pdf = HISTOGRAM(scan, LOCATIONS=xbin)
cdf = TOTAL(pdf, /CUMULATIVE) / N_ELEMENTS(scan)
; Display the image and its histogram, setting MAX_VALUE to exclude the spike
; at 0 caused by the black pixels.
pimage = IMAGE(scan, /ORDER, LAYOUT=[3,1,1], DIMENSIONS=[4*256,256], $
TITLE='Image')
phisto = PLOT(xbin, pdf, LAYOUT=[3,1,2], /CURRENT, XRANGE=[0,255], $
TITLE='Histogram', XTITLE='Pixel value', YTITLE='Frequency', $
MAX_VALUE=5e3, AXIS_STYLE=1, COLOR='red')
pcumul = PLOT(xbin, cdf, LAYOUT=[3,1,3], /CURRENT, XRANGE=[0,255], $
TITLE='Cumulative histogram', XTITLE='Pixel value', $
YTITLE='Cumulative frequency', $
AXIS_STYLE=1, COLOR='blue')
end
