Method: Magick::Image#random_threshold_channel

Defined in:
ext/RMagick/rmimage.cpp

#random_threshold_channel(geometry_str, channel = Magick::AllChannels) ⇒ Magick::Image #random_threshold_channel(geometry_str, *channels) ⇒ Magick::Image

Changes the value of individual pixels based on the intensity of each pixel compared to a random threshold. The result is a low-contrast, two color image.

Overloads:

  • #random_threshold_channel(geometry_str, channel = Magick::AllChannels) ⇒ Magick::Image

    Parameters:

    • geometry_str (Magick::Geometry, String)

      A geometry string containing LOWxHIGH thresholds.

    • channel (Magick::ChannelType) (defaults to: Magick::AllChannels)

      a ChannelType arguments.

  • #random_threshold_channel(geometry_str, *channels) ⇒ Magick::Image

    Parameters:

    • geometry_str (Magick::Geometry, String)

      A geometry string containing LOWxHIGH thresholds.

    • *channels (Magick::ChannelType)

      one or more ChannelType arguments.

Returns:

See Also:



11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
# File 'ext/RMagick/rmimage.cpp', line 11366

VALUE
Image_random_threshold_channel(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    ChannelType channels;
    char *thresholds;
    VALUE geom_str;
    ExceptionInfo *exception;

    image = rm_check_destroyed(self);

    channels = extract_channels(&argc, argv);

    // There must be 1 remaining argument.
    if (argc == 0)
    {
        rb_raise(rb_eArgError, "missing threshold argument");
    }
    else if (argc > 1)
    {
        raise_ChannelType_error(argv[argc-1]);
    }

    // Accept any argument that has a to_s method.
    geom_str = rb_String(argv[0]);
    thresholds = StringValueCStr(geom_str);

    new_image = rm_clone_image(image);

    exception = AcquireExceptionInfo();

#if defined(IMAGEMAGICK_7)
    BEGIN_CHANNEL_MASK(new_image, channels);
    {
        GeometryInfo geometry_info;

        ParseGeometry(thresholds, &geometry_info);
        GVL_STRUCT_TYPE(RandomThresholdImage) args = { new_image, geometry_info.rho, geometry_info.sigma, exception };
        CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RandomThresholdImage), &args);
    }
    END_CHANNEL_MASK(new_image);
#else
    GVL_STRUCT_TYPE(RandomThresholdImageChannel) args = { new_image, channels, thresholds, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RandomThresholdImageChannel), &args);
#endif
    rm_check_exception(exception, new_image, DestroyOnError);

    DestroyExceptionInfo(exception);

    RB_GC_GUARD(geom_str);

    return rm_image_new(new_image);
}