Method: Magick::Image#bilevel_channel

Defined in:
ext/RMagick/rmimage.cpp

#bilevel_channel(threshold, channel = Magick::AllChannels) ⇒ Magick::Image #bilevel_channel(threshold, *channels) ⇒ Magick::Image

Changes the value of individual pixels based on the intensity of each pixel channel. The result is a high-contrast image.

Overloads:

  • #bilevel_channel(threshold, channel = Magick::AllChannels) ⇒ Magick::Image

    Parameters:

    • threshold (Numeric)

      The threshold value, a number between 0 and QuantumRange.

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

      a ChannelType arguments.

  • #bilevel_channel(threshold, *channels) ⇒ Magick::Image

    Parameters:

    • threshold (Numeric)

      The threshold value, a number between 0 and QuantumRange.

    • *channels (Magick::ChannelType)

      one or more ChannelType arguments.

Returns:



1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
# File 'ext/RMagick/rmimage.cpp', line 1466

VALUE
Image_bilevel_channel(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    ChannelType channels;
    double threshold;
#if defined(IMAGEMAGICK_7)
    ExceptionInfo *exception;
#endif

    image = rm_check_destroyed(self);
    channels = extract_channels(&argc, argv);

    if (argc > 1)
    {
        raise_ChannelType_error(argv[argc-1]);
    }
    if (argc == 0)
    {
        rb_raise(rb_eArgError, "no threshold specified");
    }

    threshold = NUM2DBL(argv[0]);
    new_image = rm_clone_image(image);

#if defined(IMAGEMAGICK_7)
    exception = AcquireExceptionInfo();
    BEGIN_CHANNEL_MASK(new_image, channels);
    GVL_STRUCT_TYPE(BilevelImage) args = { new_image, threshold, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BilevelImage), &args);
    END_CHANNEL_MASK(new_image);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);
#else
    GVL_STRUCT_TYPE(BilevelImageChannel) args = { new_image, channels, threshold };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BilevelImageChannel), &args);
    rm_check_image_exception(new_image, DestroyOnError);
#endif

    return rm_image_new(new_image);
}