Method: Magick::Image#channel_mean

Defined in:
ext/RMagick/rmimage.cpp

#channel_mean(channel = Magick::AllChannels) ⇒ Array<Float> #channel_mean(*channels) ⇒ Array<Float>

Returns the mean and standard deviation values for the specified channel or channels.

Overloads:

  • #channel_mean(channel = Magick::AllChannels) ⇒ Array<Float>

    Parameters:

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

      a ChannelType arguments.

  • #channel_mean(*channels) ⇒ Array<Float>

    Parameters:

    • *channels (Magick::ChannelType)

      one or more ChannelType arguments.

Returns:

  • (Array<Float>)

    The first element in the array is the mean value. The second element is the standard deviation.



2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
# File 'ext/RMagick/rmimage.cpp', line 2550

VALUE
Image_channel_mean(int argc, VALUE *argv, VALUE self)
{
    Image *image;
    ChannelType channels;
    ExceptionInfo *exception;
    double mean, stddev;
    VALUE ary;

    image = rm_check_destroyed(self);

    channels = extract_channels(&argc, argv);

    // Ensure all arguments consumed.
    if (argc > 0)
    {
        raise_ChannelType_error(argv[argc-1]);
    }

    exception = AcquireExceptionInfo();
#if defined(IMAGEMAGICK_7)
    BEGIN_CHANNEL_MASK(image, channels);
    GVL_STRUCT_TYPE(GetImageMean) args = { image, &mean, &stddev, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageMean), &args);
    END_CHANNEL_MASK(image);
#else
    GVL_STRUCT_TYPE(GetImageChannelMean) args = { image, channels, &mean, &stddev, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageChannelMean), &args);
#endif
    CHECK_EXCEPTION();

    DestroyExceptionInfo(exception);

    ary = rb_ary_new2(2);
    rb_ary_store(ary, 0, rb_float_new(mean));
    rb_ary_store(ary, 1, rb_float_new(stddev));

    RB_GC_GUARD(ary);

    return ary;
}