Skip to content

Commit

Permalink
Port hist_find_ndim
Browse files Browse the repository at this point in the history
  • Loading branch information
n0vad3v committed Nov 10, 2024
1 parent 97b5fbf commit bba2167
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
12 changes: 12 additions & 0 deletions vips/arithmetic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
}
Expand Down
36 changes: 36 additions & 0 deletions vips/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions vips/arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
19 changes: 18 additions & 1 deletion vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit bba2167

Please sign in to comment.