参考算法:

闲人阿发伯的博客

// define head function
#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; void Show_Image(Mat&, const string &); #endif // PS_ALGORITHM_H_INCLUDED /*
This program will transform
the color image to Black-whithe
image. */ #include "PS_Algorithm.h"
#include <time.h> using namespace std;
using namespace cv; int main(void)
{
string Img_name("9.jpg");
Mat Img_in;
Img_in=imread(Img_name);
Show_Image(Img_in, Img_name); Mat Img_out(Img_in.size(), CV_32FC3);
Img_in.convertTo(Img_out, CV_32FC3); Mat R(Img_in.size(),CV_32FC1);
Mat G(Img_in.size(),CV_32FC1);
Mat B(Img_in.size(),CV_32FC1); Mat I(Img_in.size(),CV_32FC1); Mat BW_out(Img_in.size(), CV_32FC1); Mat rgb[]={B, G, R};
cv::split(Img_out, rgb); I=B+G+R; float maxVal, minVal, midVal; float color_ratio[6]={0.4,0.6,0.4,0.6,0.2,0.8};
float r_max_mid, r_max;
int Ind; for(int i=0; i<I.rows; i++)
{
for(int j=0; j<I.cols; j++)
{
maxVal=std::max(R.at<float>(i,j), std::max(G.at<float>(i,j),
B.at<float>(i,j)));
minVal=std::min(R.at<float>(i,j), std::min(G.at<float>(i,j),
B.at<float>(i,j)));
midVal=I.at<float>(i,j)-maxVal-minVal; if(minVal==R.at<float>(i,j))
{
Ind=0;
}
else if(minVal==G.at<float>(i,j))
{
Ind=2;
}
else
{
Ind=4;
}
r_max_mid=color_ratio[(Ind+3)%6+1]; if(maxVal==R.at<float>(i,j))
{
Ind=1;
}
else if(maxVal==G.at<float>(i,j))
{
Ind=3;
}
else
{
Ind=5;
} r_max=color_ratio[Ind]; BW_out.at<float>(i,j)=(maxVal-midVal)*r_max+(midVal-minVal)
*r_max_mid+minVal; }
} BW_out=BW_out/255;
Show_Image(BW_out, "out"); imwrite("out.jpg", BW_out*255); waitKey();
cout<<"All is well."<<endl; } // define the show image
#include "PS_Algorithm.h"
#include <iostream>
#include <string> using namespace std;
using namespace cv; void Show_Image(Mat& Image, const string& str)
{
namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);
imshow(str.c_str(), Image); }

原图

效果图

OpenCV——黑白调整的更多相关文章

  1. Opencv学习笔记4:Opencv处理调整图片亮度和对比度

    一.理论基础 在数学中我们学过线性理论,在图像亮度和对比度调节中同样适用,看下面这个公式: 在图像像素中其中: 参数f(x)表示源图像像素. 参数g(x) 表示输出图像像素. 参数a(需要满足a> ...

  2. OpenCV尺寸调整

    #include<cv.h> #include<highgui.h> int main(int argc, char** argv) { IplImage* img = cvL ...

  3. OpenCV——饱和度调整

    参考: 闲人阿发伯的博客 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED ...

  4. PS 图像调整算法——黑白

    这个算法是参考自 阿发伯 的博客: http://blog.csdn.net/maozefa 黑白调整 Photoshop CS的图像黑白调整功能,是通过对红.黄.绿.青.蓝和洋红等6种颜色的比例调节 ...

  5. UI设计师需要熟记的45个快捷键Windows、Mac

    大家都知道PS快捷键很多,其实没必要都记住,今天为大家整理了45个比较实用的,别忘了收藏. 图层 填充图层 MAC: Alt+Backspace (前景) or Cmd+Backspace (背景) ...

  6. Delphi图像处理 -- 文章索引

    转载:http://blog.csdn.net/maozefa/article/details/7188354 本文对已发布<Delphi图像处理>系列文章进行索引链接,以方便阅读和查找. ...

  7. qt使用中的一些问题(linux)

    ui_xxx.h的问题 工程中(工作空间)中包含的ui_xxx.h文件是系统自动生成的.这个是xxx.ui的创建文件来的,xxx.ui界面上的都是ui_xxx.h在控制的,在项目里是不显示这个头文件的 ...

  8. OpenCV-Python 直方图-2:直方图均衡 | 二十七

    目标 在本节中, 我们将学习直方图均衡化的概念,并利用它来提高图像的对比度. 理论 考虑这样一个图像,它的像素值仅局限于某个特定的值范围.例如,较亮的图像将把所有像素限制在高值上.但是一幅好的图像会有 ...

  9. 用OpenCV实现Photoshop算法(三): 曲线调整

    http://blog.csdn.net/c80486/article/details/52499919 系列文章: 用OpenCV实现Photoshop算法(一): 图像旋转 用OpenCV实现Ph ...

随机推荐

  1. Swift_4_闭包(Blocks)

    import Foundation println("Hello, World!") var arr = [1,2,4,6,74,2] func hasClosure(list:[ ...

  2. EF之POCO应用系列3——延迟加载

    EF之POCO应用系列4——延迟加载 当我们进行查询的时候,哪些关系的数据将会被加载到内存呢?所有相关的对象都需要吗?在一些场合可能有意义,例如,当查询的实体仅仅拥有一个相关的子实体,但是,多数情况下 ...

  3. iOS与JS开发交互总结

    hybrid.jpg 前言 Web 页面中的 JS 与 iOS Native 如何交互是每个 iOS 猿必须掌握的技能.而说到 Native 与 JS 交互,就不得不提一嘴 Hybrid. Hybri ...

  4. Surpassing Human-Level Face Verification Performance on LFW with GaussianFace

    Face verification remains a challenging problem in very complex conditions with large variations suc ...

  5. 【python】-- IO多路复用(select、poll、epoll)介绍及实现

    IO多路复用(select.poll.epoll)介绍及select.epoll的实现 IO多路复用中包括 select.pool.epoll,这些都属于同步,还不属于异步 一.IO多路复用介绍 1. ...

  6. ZOJ - 3537 Cake (凸包+区间DP+最优三角剖分)

    Description You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut t ...

  7. java上传文件,下载文件

    1.上传文件 1 protected int doTask(BaseForm form) throws AppException, FatalException, NoExistsException, ...

  8. 中国移动OneNet平台上传GPS数据JSON格式

    最终目的输出 POST /devices/3225187/datapoints HTTP/1.1 api-key: R9xO5NZm6oVI4YBHvCPKEqtwYtMA Host: api.hec ...

  9. LeetCode:删除排序链表中的重复元素【83】

    LeetCode:删除排序链表中的重复元素[83] 题目描述 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示 ...

  10. hd acm1018

    Problem Description In many applications very large integers numbers are required. Some of these app ...