如何创建具有电视效果的图像?

时间:2013-07-17 07:18:48

标签: c++ opencv

我需要处理带有电视效果的图像。以下是示例处理图像http://www.codeproject.com/KB/graphics/RedMatterLibrary/village_waves_1.jpg

的链接

有人可以告诉我openCV库是否可以这样做?还是有其他我可以用于此目的的图书馆?

1 个答案:

答案 0 :(得分:1)

不确定。您可以操纵像素。所以你只需要自己编写这样的过滤器。 这是我想出来的。也许你可以把它调整到你的喜欢。

它需要一个图像,稍微去饱和颜色,然后根据垂直正弦函数增加蓝色部分。

#include <opencv2/opencv.hpp>
#include <highgui.h> 
#include <cmath>

double wavelength = 40;
double intensity = 0.5;

double decolorisation = 0.7;

int main(int argc, char** argv)
{
    cv::Mat img = imread(argv[1]);
    cv::Mat outImg = img.clone();

    for(int i=0; i<img.rows; i++)
        for(int j=0; j<img.cols; j++)
        {
            // desaturate the image
            double meanColor = (img.at<cv::Vec3b>(i,j)[0] + img.at<cv::Vec3b>(i,j)[1] + img.at<cv::Vec3b>(i,j)[3]) / 3.0;
            cv::Vec3b newColor;
            newColor[0] = (1-decolorisation)*img.at<cv::Vec3b>(i,j)[0] + decolorisation*meanColor; 
            newColor[1] = (1-decolorisation)*img.at<cv::Vec3b>(i,j)[1] + decolorisation*meanColor; 
            newColor[2] = (1-decolorisation)*img.at<cv::Vec3b>(i,j)[2] + decolorisation*meanColor; 

            // boost the blue channel
            double coeff = 0.5 + sin((2*M_PI*i)/wavelength)/2.0;
            newColor[0] = newColor[0] + intensity * coeff * (255-newColor[0]);

            outImg.at<cv::Vec3b>(i,j) = newColor;
        }

    cv::imshow("Original",img);
    cv::imshow("Televised",outImg);
    waitKey(0);          
}
相关问题