Visual Studio 2013 Express
 Visual C++( アンマネージドコード )
 OpenCV 3.1

■258.OpenCV ポスタリゼーション Prev Top Next
関連ページ:

今回はポスタリゼーションです。ルックアップテーブルを使用して階調変更を行います。


---main.cpp---

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#pragma comment( lib, "opencv_world300d.lib" )

int main(int argc, const char* argv[])
{
   int hr = -1;
   
   try
   {
      cv::Mat src, dst;

      src = cv::imread("D:/TEMP/MaverickProj/Image/OpenCV/20/Texture.png", cv::IMREAD_COLOR);

      // ルックアップテーブルを作成する
      uchar lut[256];
      int cnt = _countof(lut);
      int tone = 64;    // 4階調
      for (int i = 0; i < cnt; i++)
      {
         lut[i] = (float)(i / tone) / (float)( 255 / tone ) * 255.0f;
      }

      cv::LUT(src, cv::Mat(cv::Size( 256, 1 ), CV_8U, lut), dst);

      // 元画像のウィンドウ表示
      cv::namedWindow("Source", 1);
      imshow("Source", src);

      cv::namedWindow("posterize", 1);
      imshow("posterize", dst);

      cv::waitKey(0);

     hr = 0;
   }
   catch (cv::Exception ex)
   {
      std::cout << ex.err << std::endl;
   }

   // ウィンドウの破棄
   cv::destroyAllWindows();

   return hr;
}


元画像

ポスタリゼーション

Prev Top Next
inserted by FC2 system