Top |

## Functions

int | vips_maplut () |

int | vips_percent () |

int | vips_stdif () |

int | vips_hist_cum () |

int | vips_hist_norm () |

int | vips_hist_equal () |

int | vips_hist_plot () |

int | vips_hist_match () |

int | vips_hist_local () |

int | vips_hist_ismonotonic () |

int | vips_hist_entropy () |

int | vips_case () |

## Description

Histograms and look-up tables are 1xn or nx1 images, where n is less than 256 or less than 65536, corresponding to 8- and 16-bit unsigned int images. They are tagged with a VipsInterpretation of VIPS_INTERPRETATION_HISTOGRAM and usually displayed by user-interfaces such as nip2 as plots rather than images.

These functions can be broadly grouped as things to find or build
histograms (`vips_hist_find()`

, `vips_hist_find_indexed()`

,
`vips_hist_find_ndim()`

, `vips_buildlut()`

, `vips_identity()`

),
operations that
manipulate histograms in some way (`vips_hist_cum()`

, `vips_hist_norm()`

),
operations to apply histograms (`vips_maplut()`

), and a variety of utility
operations.

A final group of operations build tone curves. These are useful in pre-press work for adjusting the appearance of images. They are designed for CIELAB images, but might be useful elsewhere.

## Functions

### vips_maplut ()

int vips_maplut (,`VipsImage *in`

,`VipsImage **out`

,`VipsImage *lut`

);`...`

Optional arguments:

: apply one-band`band`

to this band of`lut`

`in`

Map an image through another image acting as a LUT (Look Up Table). The lut may have any type and the output image will be that type.

The input image will be cast to one of the unsigned integer types, that is, VIPS_FORMAT_UCHAR, VIPS_FORMAT_USHORT or VIPS_FORMAT_UINT.

If * lut*
is too small for the input type (for example, if

*is VIPS_FORMAT_UCHAR but*

`in`

*only has 100 elements), the lut is padded out by copying the last element. Overflows are reported at the end of computation. If*

`lut`

*is too large, extra values are ignored.*

`lut`

If * lut*
has one band and

*is -1 (the default), then all bands of*

`band`

*pass through*

`in`

*. If*

`lut`

*is >= 0, then just that band of*

`band`

*passes through*

`in`

*and other bands are just copied.*

`lut`

If * lut*
has same number of bands as

*, then each band is mapped separately. If*

`in`

*has one band, then*

`in`

*may have many bands and the output will have the same number of bands as*

`lut`

*.*

`lut`

See also: `vips_hist_find()`

, `vips_identity()`

.

[method]

### vips_percent ()

int vips_percent (,`VipsImage *in`

,`double percent`

,`int *threshold`

);`...`

vips_percent() returns (through the * threshold*
parameter) the threshold
below which there are

*values of*

`percent`

*. For example:*

`in`

1 2 |
$ vips precent k2.jpg 90 214 |

Means that 90% of pixels in `k2.jpg`

have a value less than 214.

The function works for uchar and ushort images only. It can be used to threshold the scaled result of a filtering operation.

See also: `vips_hist_find()`

, `vips_profile()`

.

[method]

### vips_stdif ()

int vips_stdif (,`VipsImage *in`

,`VipsImage **out`

,`int width`

,`int height`

);`...`

Optional arguments:

: weight of new mean`a`

: target mean`m0`

: weight of new deviation`b`

: target deviation`s0`

vips_stdif() preforms statistical differencing according to the formula given in page 45 of the book "An Introduction to Digital Image Processing" by Wayne Niblack. This transformation emphasises the way in which a pel differs statistically from its neighbours. It is useful for enhancing low-contrast images with lots of detail, such as X-ray plates.

At point (i,j) the output is given by the equation:

1 2 |
vout(i,j) = @a * @m0 + (1 - @a) * meanv + (vin(i,j) - meanv) * (@b * @s0) / (@s0 + @b * stdv) |

Values * a*
,

*,*

`m0`

*and*

`b`

*are entered, while meanv and stdv are the values calculated over a moving window of size*

`s0`

*,*

`width`

*centred on pixel (i,j).*

`height`

*is the new mean,*

`m0`

*is the weight given to it.*

`a`

*is the new standard deviation,*

`s0`

*is the weight given to it.*

`b`

Try:

1 |
vips stdif $VIPSHOME/pics/huysum.v fred.v 0.5 128 0.5 50 11 11 |

The operation works on one-band uchar images only, and writes a one-band uchar image as its result. The output image has the same size as the input.

See also: `vips_hist_local()`

.

[method]

### vips_hist_cum ()

int vips_hist_cum (,`VipsImage *in`

,`VipsImage **out`

);`...`

Form cumulative histogram.

See also: `vips_hist_norm()`

.

[method]

### vips_hist_norm ()

int vips_hist_norm (,`VipsImage *in`

,`VipsImage **out`

);`...`

Normalise histogram. The maximum of each band becomes equal to the maximum index, so for example the max for a uchar image becomes 255. Normalise each band separately.

See also: `vips_hist_cum()`

.

[method]

### vips_hist_equal ()

int vips_hist_equal (,`VipsImage *in`

,`VipsImage **out`

);`...`

Optional arguments:

: band to equalise`band`

Histogram-equalise * in*
. Equalise using band

*, or if*

`bandno`

*is -1, equalise bands independently. The output format is always the same as the input format.*

`bandno`

See also:

[method]

### vips_hist_plot ()

int vips_hist_plot (,`VipsImage *in`

,`VipsImage **out`

);`...`

Plot a 1 by any or any by 1 image file as a max by any or any by max image using these rules:

*unsigned char* max is always 256

*other unsigned integer types* output 0 - maxium
value of * in*
.

*signed int types* min moved to 0, max moved to max + min.

*float types* min moved to 0, max moved to any
(square output)

[method]

### vips_hist_match ()

int vips_hist_match (,`VipsImage *in`

,`VipsImage *ref`

,`VipsImage **out`

);`...`

Adjust * in*
to match

*. If*

`ref`

*and*

`in`

*are normalised cumulative histograms,*

`ref`

*will be a LUT that adjusts the PDF of the image from which*

`out`

*was made to match the PDF of*

`in`

*'s image.*

`ref`

See also: `vips_maplut()`

, `vips_hist_find()`

, `vips_hist_norm()`

,
`vips_hist_cum()`

.

[method]

### vips_hist_local ()

int vips_hist_local (,`VipsImage *in`

,`VipsImage **out`

,`int width`

,`int height`

);`...`

Optional arguments:

: maximum brightening`max_slope`

Performs local histogram equalisation on * in*
using a
window of size

*by*

`width`

*centered on the input pixel.*

`height`

The output image is the same size as the input image. The edge pixels are created by mirroring the input image outwards.

If * max_slope*
is greater than 0, it sets the maximum value for the slope of
the cumulative histogram, that is, the maximum brightening that is
performed. A value of 3 is often used. Local histogram equalization with
contrast limiting is usually called CLAHE.

See also: `vips_hist_equal()`

.

[method]

### vips_hist_ismonotonic ()

int vips_hist_ismonotonic (,`VipsImage *in`

,`gboolean *out`

);`...`

Test * in*
for monotonicity.

*is set non-zero if*

`out`

*is monotonic.*

`in`

[method]

### vips_hist_entropy ()

int vips_hist_entropy (,`VipsImage *in`

,`double *out`

);`...`

Estimate image entropy from a histogram. Entropy is calculated as:

1 |
-sum( p * log2( p ) ) |

where p is histogram-value / sum-of-histogram-values.

[method]

### vips_case ()

int vips_case (,`VipsImage *index`

,`VipsImage **cases`

,`VipsImage **out`

,`int n`

);`...`

Use values in * index*
to select pixels from

*.*

`cases`

* index*
must have one band.

*can have up to 256 elements. Values in*

`cases`

*greater than or equal to*

`index`

*use the final image in*

`n`

*. The images in*

`cases`

*must have either one band or the same number of bands. The output image is the same size as*

`cases`

*. Images in*

`index`

*are expanded to the smallest common format and number of bands.*

`cases`

Combine this with `vips_switch()`

to make something like a case statement or
a multi-way `vips_ifthenelse()`

.

See also: `vips_maplut()`

, `vips_switch()`

, `vips_ifthenelse()`

.

[method]