Skip to content

Commit

Permalink
add Min function
Browse files Browse the repository at this point in the history
  • Loading branch information
steve.3282 committed Feb 24, 2025
1 parent f0969a3 commit 30bc708
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vips/arithmetic.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ int absOp(VipsImage *img, VipsImage **out) {
int project(VipsImage *in, VipsImage **col, VipsImage **row) {
return vips_project(in, col, row, NULL);
}

int minOp(VipsImage *in, double *out, int *x, int *y, int size) {
return vips_min(in, out, "x", x, "y", y, "size", size, NULL);
}
13 changes: 13 additions & 0 deletions vips/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,16 @@ func vipsProject(in *C.VipsImage) (*C.VipsImage, *C.VipsImage, error) {
}
return col, row, nil
}

// https://www.libvips.org/API/current/libvips-arithmetic.html#vips-min
func vipsMin(in *C.VipsImage) (float64, int, int, error) {
incOpCounter("min")
var out C.double
var x, y C.int

if err := C.minOp(in, &out, &x, &y, C.int(1)); err != 0 {
return 0, 0, 0, handleVipsError()
}

return float64(out), int(x), int(y), nil
}
1 change: 1 addition & 0 deletions vips/arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ int hist_entropy(VipsImage *in, double *out);
int subtract(VipsImage *in1, VipsImage *in2, VipsImage **out);
int absOp(VipsImage *img, VipsImage **out);
int project(VipsImage *in, VipsImage **col, VipsImage **row);
int minOp(VipsImage *in, double *out, int *x, int *y, int size);
5 changes: 5 additions & 0 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,11 @@ func (r *ImageRef) Project() (*ImageRef, *ImageRef, error) {
return newImageRef(col, r.format, r.originalFormat, nil), newImageRef(row, r.format, r.originalFormat, nil), nil
}

// Min finds the minimum value in an image.
func (r *ImageRef) Min() (float64, int, int, error) {
return vipsMin(r.image)
}

// Rank does rank filtering on an image. A window of size width by height is passed over the image.
// At each position, the pixels inside the window are sorted into ascending order and the pixel at position
// index is output. index numbers from 0.
Expand Down
3 changes: 3 additions & 0 deletions vips/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,9 @@ func TestImageRef_ArithmeticOperation(t *testing.T) {
orgWidth := image.Width()
orgHeight := image.Height()

_, _, _, err = image.Min()
require.NoError(t, err)

err = image2.Abs()
require.NoError(t, err)

Expand Down

0 comments on commit 30bc708

Please sign in to comment.