diff --git a/vips/arithmetic.c b/vips/arithmetic.c index 557f613c..824ee673 100644 --- a/vips/arithmetic.c +++ b/vips/arithmetic.c @@ -28,6 +28,14 @@ int average(VipsImage *in, double *out) { return vips_avg(in, out, NULL); } +int maxpos(VipsImage *in, double *out) { + return vips_max(in, out, NULL); +} + +int minpos(VipsImage *in, double *out) { + return vips_min(in, out, NULL); +} + int find_trim(VipsImage *in, int *left, int *top, int *width, int *height, double threshold, double r, double g, double b) { @@ -58,6 +66,10 @@ int hist_find(VipsImage *in, VipsImage **out) { return vips_hist_find(in, out, NULL); } +int hist_find_ndim(VipsImage *in, VipsImage **out) { + return vips_hist_find_ndim(in, out, NULL); +} + int hist_cum(VipsImage *in, VipsImage **out) { return vips_hist_cum(in, out, NULL); } diff --git a/vips/arithmetic.go b/vips/arithmetic.go index 3bdf5baa..0a60a467 100644 --- a/vips/arithmetic.go +++ b/vips/arithmetic.go @@ -139,6 +139,42 @@ func vipsHistFind(in *C.VipsImage) (*C.VipsImage, error) { return out, nil } +// https://www.libvips.org/API/current/libvips-arithmetic.html#vips-hist-find-ndim +func vipsHistFindNdim(in *C.VipsImage) (*C.VipsImage, error) { + incOpCounter("histFindNdim") + var out *C.VipsImage + + if err := C.hist_find_ndim(in, &out); err != 0 { + return nil, handleImageError(out) + } + + return out, nil +} + +// https://www.libvips.org/API/current/libvips-arithmetic.html#vips-max +func vipsMax(in *C.VipsImage) (float64, error) { + incOpCounter("max") + var out C.double + + if err := C.maxpos(in, &out); err != 0 { + return 0, handleVipsError() + } + + return float64(out), nil +} + +// https://www.libvips.org/API/current/libvips-arithmetic.html#vips-min +func vipsMin(in *C.VipsImage) (float64, error) { + incOpCounter("min") + var out C.double + + if err := C.minpos(in, &out); err != 0 { + return 0, handleVipsError() + } + + return float64(out), nil +} + // https://www.libvips.org/API/current/libvips-histogram.html#vips-hist-norm func vipsHistNorm(in *C.VipsImage) (*C.VipsImage, error) { incOpCounter("histNorm") diff --git a/vips/arithmetic.h b/vips/arithmetic.h index 693b4fdd..17b7c42b 100644 --- a/vips/arithmetic.h +++ b/vips/arithmetic.h @@ -14,7 +14,10 @@ int find_trim(VipsImage *in, int *left, int *top, int *width, int *height, double threshold, double r, double g, double b); int getpoint(VipsImage *in, double **vector, int n, int x, int y); int stats(VipsImage *in, VipsImage **out); +int maxpos(VipsImage *in, double *out); +int minpos(VipsImage *in, double *out); int hist_find(VipsImage *in, VipsImage **out); +int hist_find_ndim(VipsImage *in, VipsImage **out); int hist_cum(VipsImage *in, VipsImage **out); int hist_norm(VipsImage *in, VipsImage **out); int hist_entropy(VipsImage *in, double *out); diff --git a/vips/image.go b/vips/image.go index 24ff6cf0..9e566460 100644 --- a/vips/image.go +++ b/vips/image.go @@ -1708,7 +1708,7 @@ func (r *ImageRef) Stats() error { return nil } -// HistogramFind find the histogram the image. +// HistogramFind find the histogram of the image. // Find the histogram for all bands (producing a one-band histogram). // char and uchar images are cast to uchar before histogramming, all other image types are cast to ushort. func (r *ImageRef) HistogramFind() error { @@ -1720,6 +1720,23 @@ func (r *ImageRef) HistogramFind() error { return nil } +func (r *ImageRef) HistogramFindNdim() error { + out, err := vipsHistFindNdim(r.image) + if err != nil { + return err + } + r.setImage(out) + return nil +} + +func (r *ImageRef) MaxPos() (float64, error) { + return vipsMax(r.image) +} + +func (r *ImageRef) MinPos() (float64, error) { + return vipsMin(r.image) +} + // HistogramCumulative form cumulative histogram. func (r *ImageRef) HistogramCumulative() error { out, err := vipsHistCum(r.image)