随笔 - 4326,  文章 - 1,  评论 - 32,  阅读 - 281万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

// PS_Algorithm.h

#ifndef PS_ALGORITHM_H_INCLUDED

#define PS_ALGORITHM_H_INCLUDED

#include <iostream>
#include <string>
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"

#include "cxcore.hpp"

using namespace std;
using namespace cv;

#endif // PS_ALGORITHM_H_INCLUDED


/*
The program will transfor the color
image to the gray image.
The image must be color image.
*/

#include "PS_Algorithm.h"
int main()
{
    string  Image_name("2.jpg");
    Mat Image=imread(Image_name.c_str());
    Mat Image_test(Image.size(),CV_32FC3);
    Image.convertTo(Image_test, CV_32FC3);
    Mat Gray_img(Image_test.size(), CV_32FC1);
    Mat r,g,b;
    Gray_img.copyTo(r);
    g=r;
    b=r;
    Mat bgr[]={b,g,r};
    split(Image_test, bgr);
    b=bgr[0];
    g=bgr[1];
    r=bgr[2];
    Mat I1,I2,I3;
    I1=r;
    I2=r;
    I3=r;

    // I=0.299*R+0.587*G+0.144*B   方案一
    Gray_img=(0.299*r+0.587*g+0.144*b);
    I1=Gray_img/255;
    imshow("I1", I1);

    // I=(R+G+B)/3  方案二
    Gray_img=(0.333*r+0.333*g+0.333*b);
    I2=Gray_img/255;
    for(int i=100; i<105; i++)
        for(int j=100; j<105; j++)
            cout<<I2.at<float>(i,j)<<endl;
    imshow ("I2", I2);

    // I=max(R,G,B)   方案三
    float *p1,*p2,*p3,*p;
    p1=r.ptr<float>(0);
    p2=g.ptr<float>(0);
    p3=b.ptr<float>(0);
    p=I3.ptr<float>(0);
    int nums;
    nums=Gray_img.rows*Gray_img.cols;
    for (int i=0; i<nums; i++)
        p[i]=max(p1[i],max(p2[i],p3[i]))/255;
    imshow("I3",I3);

    cout<<"All is well."<<endl;
    waitKey();
}


posted on   未雨愁眸  阅读(519)  评论(0编辑  收藏  举报
编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· 软件产品开发中常见的10个问题及处理方法
· Vite CVE-2025-30208 安全漏洞
· MQ 如何保证数据一致性?
· 《HelloGitHub》第 108 期
点击右上角即可分享
微信分享提示