用煤渣转换成灰度

时间:2014-02-15 20:40:20

标签: c++ colors cinder

我正在关注Cinder上的教程,您可以在其中加载并将图像显示为cinder::gl::Texture个对象。这个类没有convert2Grayscale方法,所以 我可以自己实现这样的东西吗? 我是否可以访问separete像素,我可以应用a simple algorithm? (访问像素实际上更重要,因为我想将它用于另一个项目)

2 个答案:

答案 0 :(得分:2)

每个像素由3D矢量[R,G,B]表示 其中R是红色通道的[0,1]中的值,G是绿色通道的[0,1]中的值,B是蓝色通道的[0,1]中的值。将3D RGB像素转换为标量Y的最简单方法是使用以下公式表示[0,1]中的光强度(即灰度):

Y = .2126 * R ^ gamma + .7152 * G ^ gamma + .0722 * B ^ gamma

大多数系统中的伽玛等于2.2

现在,只要它涉及在cinder中访问图像像素,就必须在Surface对象上加载图像。 cinder中的Surface对象具有用于访问各个像素的接口函数。请参阅这个惊人的教程,了解如何操作:http://www.creativeapplications.net/tutorials/images-in-cinder-tutorials-cinder/

答案 1 :(得分:1)

更简单的方法,如Cinder网站上的“Hello, Cinder”教程所示:

  1. 将图像加载到Channel对象中,默认情况下会立即将其转换为灰度。
  2. 使用该Channel对象初始化可在draw()方法中使用的Surface对象,如:

    void MyApp :: setup() {

    Url url( "http://libcinder.org/media/tutorial/paris.jpg" );
    
    mChannel = Channel32f( loadImage( loadUrl( url ) ) );
    mTexture = mChannel;
    mDrawImage = true;
    

    }

    void TutorialApp :: draw()

    {

    gl::clear( Color( 0, 0, 0 ), true );
    
    if( mDrawImage )
    {
      mTexture.enableAndBind();
      gl::draw( mTexture, getWindowBounds() );
    }
    

    }