【问题标题】:convert to grayscale with cinder用煤渣转换为灰度
【发布时间】:2014-03-15 05:31:48
【问题描述】:

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

【问题讨论】:

    标签: c++ colors cinder


    【解决方案1】:

    每个像素都由一个 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

    大多数系统中的 gamma 等于 2.2

    现在就 cinder 中图像像素的访问而言,您必须将图像加载到 Surface 对象上。 cinder 中的表面对象具有用于访问单个像素的接口函数。请参阅这个惊人的教程来了解如何做到这一点:http://www.creativeapplications.net/tutorials/images-in-cinder-tutorials-cinder/

    【讨论】:

      【解决方案2】:

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

      1. 将图像加载到 Channel 对象中,默认情况下会一次性将其全部转换为灰度。
      2. 使用该 Channel 对象来初始化一个 Surface 对象,该对象可以在您的 draw() 方法中使用,类似于:

        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() );
        }
        

        }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-08
        • 2020-04-29
        • 2020-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-07
        • 2010-10-15
        相关资源
        最近更新 更多