Method: Magick::Image#adaptive_threshold

Defined in:
ext/RMagick/rmimage.cpp

#adaptive_threshold(width = 3, height = 3, bias = 0) ⇒ Magick::Image

Selects an individual threshold for each pixel based on the range of intensity values in its local neighborhood. This allows for thresholding of an image whose global intensity histogram doesn’t contain distinctive peaks.

Returns a new image.

Parameters:

  • width (Numeric) (defaults to: 3)

    the width of the local neighborhood.

  • height (Numeric) (defaults to: 3)

    the height of the local neighborhood.

  • bias (Numeric) (defaults to: 0)

    the mean offset

Returns:



602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# File 'ext/RMagick/rmimage.cpp', line 602

VALUE
Image_adaptive_threshold(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    unsigned long width = 3, height = 3;
    double bias = 0;
    ExceptionInfo *exception;

    image = rm_check_destroyed(self);

    switch (argc)
    {
        case 3:
            bias = NUM2DBL(argv[2]);
        case 2:
            height = NUM2ULONG(argv[1]);
        case 1:
            width  = NUM2ULONG(argv[0]);
        case 0:
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc);
    }

    exception = AcquireExceptionInfo();
    GVL_STRUCT_TYPE(AdaptiveThresholdImage) args = { image, width, height, bias, exception };
    new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AdaptiveThresholdImage), &args);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);

    return rm_image_new(new_image);
}