({{, (RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[{(Subscript[x, 1]),(Subscript[x, 2]),…}] 
finds a function f so that the transformed values f((Subscript[x, i])) are distributed nearly uniformly.}, {, (RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[{(Subscript[x, 1]),(Subscript[x, 2]),…},dist]
finds f so that f((Subscript[x, i])) are distributed with distribution dist.}, {, (RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[image,…]
finds a function that reshapes the histogram of image.}})

OpenersNotesSection(Spacer1)Details

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[data,dist] finds a function that interpolates between the quantiles of data and dist.

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation]) gives results in terms of (RefLink[InterpolatingFunction, paclet:ref/InterpolatingFunction]) objects.

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation]) works with 3D as well as 2D images, and also with lists of arbitrary rank datasets.

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[{(Subscript[data, 1]),(Subscript[data, 2]),…},…] gives a list of functions that correspond to each dataset.

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[{(Subscript[data, 1]),(Subscript[data, 2]),…,(Subscript[data, n])},ref] finds a function so that the transformed datasets would have nearly the same distribution as a reference dataset or image ref. If ref is an image it should have either 1 or n channels.

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[data] is equivalent to (RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[data,(RefLink[UniformDistribution, paclet:ref/UniformDistribution])[{0,1}]].

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[source,ref,n] finds an interpolating function with n equally spaced quantiles.

(RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[image,ref] is equivalent to (RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[image,ref,256].

With (RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation])[data,ref,(RefLink[Automatic, paclet:ref/Automatic])], the number of quantiles is the same as the number of bins used in (RefLink[Histogram, paclet:ref/Histogram])[data].

OpenersPrimaryExamplesSection(Spacer1)Examples  (9)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Find a function that distributes samples in a given dataset uniformly:

data=RandomVariate[RayleighDistribution[1],2000];
func=HistogramTransformInterpolation[data]

Histogram/@{data,func[data]}

Reshape the histogram of a dataset to match the PDF of a normal distribution:

data=RandomVariate[RayleighDistribution[1],2000];
Histogram[data]

dist=NormalDistribution[0,.2];
func=HistogramTransformInterpolation[data,dist]

Histogram[func[data],Automatic,"PDF"]

Find a function that equalizes the histogram of an image:

HistogramTransformInterpolation[img=]

ImageApply[%,img]

Find a function that equalizes the histogram of a 3D image:

img=;

HistogramTransformInterpolation[img]

ImageApply[%,img]

OpenersExampleSection1(Spacer1)Scope  (3)

Find equalizing functions for a list of datasets:

HistogramTransformInterpolation[
Table[RandomVariate[dist,1000],{dist,{NormalDistribution[.5,.2],UniformDistribution[{0,1}]}}]]

Plot[Quiet[#[t]]&/@%,{t,0,1}]

Find histogram reshaping functions for each color channel:

funs=HistogramTransformInterpolation[img=]

Apply the functions channel by channel:

MapThread[ImageApply,{funs,ColorSeparate@img}]//ColorCombine

Use a different number of quantiles when finding the transformation function:

data=RandomVariate[NormalDistribution[],1000];
funs=Table[HistogramTransformInterpolation[data,UniformDistribution[{0,1}],n],{n,{4,8,16,32}}];

Histogram[#[data]]&/@funs

OpenersExampleSection3(Spacer1)Applications  (1)

OpenersExampleSubsection0(Spacer1)Locally Adaptive Histogram Equalization  (1)

A full locally adaptive histogram equalization may give more appealing results for images with a variety of intensity levels, but takes much more time:

img=;
radius=10;

Timing[
center=radius+1;
full=ImageFilter[
HistogramTransformInterpolation[Flatten@#][#[[center,center]]]&,img,radius]]

{full,ImageApply[HistogramTransformInterpolation[img],img]}

Bilinear interpolation between the equalization functions computed for non-overlapping blocks is a faster approximation:

HistogramTransformationWeightedLocalAdaptive[img_,radius_]:=
Module[{funs,nodes,w,h,f,fun,fi},
funs=Map[HistogramTransformInterpolation,ImagePartition[img,{2*radius+1}],{2}];
{w,h}=ImageDimensions@img;
nodes=Map[
Mean@Flatten[N@ImageData[#,Automatic],1]&,
ImagePartition[
Image[Array[{#1,#2}&,{h,w}],"Bit16"],
{2*radius+1}],
{2}];
nodes=ArrayPad[nodes,{{1,1},{1,1}},"Fixed"];
nodes[[All,{1,-1},2]]={1,w};
nodes[[{1,-1},All,1]]={1,h};
funs=ArrayPad[funs,1,"Fixed"];
fi=Interpolation[Thread[{Round@Flatten[nodes,1],Table[f[#],{f,Flatten@funs}]}],InterpolationOrder->1];
fun[v_,{r_,c_}]:=Evaluate[fi[r,c]]&[v];
Quiet@ImageApplyIndexed[fun,img]
];

Timing[
partial=HistogramTransformationWeightedLocalAdaptive[img,radius]]

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

The result of (RefLink[HistogramTransformInterpolation, paclet:ref/HistogramTransformInterpolation]) approximates the closed-form solution when it exists:

dist1=TruncatedDistribution[{0,1},NormalDistribution[.5,.2]];
dist2=WeibullDistribution[1.5,1];
exact=Composition[InverseCDF[dist2],CDF[dist1]];

fun=HistogramTransformInterpolation[RandomVariate[dist1,10000],dist2];

Plot[exact[x]-Quiet@fun[x],{x,0,1}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[HistogramTransform, paclet:ref/HistogramTransform])  ▪  (RefLink[Histogram, paclet:ref/Histogram])  ▪  (RefLink[BinCounts, paclet:ref/BinCounts])  ▪  (RefLink[ImageApply, paclet:ref/ImageApply])  ▪  (RefLink[ImageHistogram, paclet:ref/ImageHistogram])  ▪  (RefLink[ImageLevels, paclet:ref/ImageLevels])  ▪  (RefLink[Quantile, paclet:ref/Quantile])  ▪  (RefLink[PDF, paclet:ref/PDF])  ▪  (RefLink[UniformDistribution, paclet:ref/UniformDistribution])  ▪  (RefLink[HistogramDistribution, paclet:ref/HistogramDistribution])  ▪  (RefLink[TransformedDistribution, paclet:ref/TransformedDistribution])  ▪  (RefLink[Interpolation, paclet:ref/Interpolation])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Color Processing, paclet:guide/ColorProcessing])}})}})