Welcome to the Harris Geospatial documentation center. Here you will find reference guides and help documents.
﻿

>  Docs Center  >  IDL Reference  >  Math - Statistical Tools  >  HIST_2D

### HIST_2D

HIST_2D

The HIST_2D function returns the two dimensional density function (histogram) of two variables.

This routine is written in the IDL language. Its source code can be found in the file hist_2d.pro in the lib subdirectory of the IDL distribution.

Note: The data type of the values specified for BIN1, BIN2, MAX1, MAX2, MIN1, and MIN2 should match the data type of the V1 and V2 arguments. Since these keyword values are converted to the data type of V1 and V2, specifying mismatched data types may produce undesired results. For example, if you have two byte images as inputs, but you want to use a fractional binsize, you should convert your input arrays to floating-point before calling HIST_2D.

## Examples

; Read an RGB image of a rose.
file = FILE_WHICH('rose.jpg')
rose = READ_IMAGE(file)

; Compare the red versus green bands of the image,
; in 5 x 5 bins.
red_band = rose[0,*,*]
green_band = rose[1,*,*]
h2d = HIST_2D(red_band, green_band, bin1=5, bin2=5)

; Resize (with nearest-neighbor sampling) the
; output array of bins to the original range of
; intensities in the red and green bands, [0-255].
h2d = CONGRID(h2d, MAX(red_band), MAX(green_band))

; Squash peaks by displaying logs of bins.
h2d = BYTSCL(ALOG10(h2d > 1))

; Plot the 2D histogram.
ct = COLORTABLE(0, /REVERSE)
g0 = IMAGE(h2d, RGB_TABLE=ct, AXIS_STYLE=2, MARGIN=0.1, $  XTITLE='Red band pixel intensity',$

## Version History

 Pre 4.0 Introduced