Opencv— — Bias and Gain
2016-02-24 11:25
363 查看
// 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" #include "math.h" using namespace std; using namespace cv; void Show_Image(Mat&, const string &); #endif // PS_ALGORITHM_H_INCLUDED /* Adjust bias and gain. */ #include "PS_Algorithm.h" float Bias(float a, float b); float Gain(float a, float b); int main() { string Image_name("4.jpg"); Mat Img=imread(Image_name.c_str()); Mat Img_out(Img.size(), CV_32FC3); float gain_val = 0.75; // 0-1 float bias_val = 0.25; // 0-1 int width=Img.cols; int height=Img.rows; float val; for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { for (int k=0; k<3; k++) { val=(float)Img.at<Vec3b>(y, x)[k]/255; val=Gain(val, gain_val); Img_out.at<Vec3f>(y, x)[k]=Bias(val, bias_val); } } } Show_Image(Img_out, "New_img"); cout<<"All is well."<<endl; waitKey(); } float Bias(float a, float b) { float y; a=pow(a, log(b)/log(0.5)); y=a/((1.0f/b-2)*(1.0f-a)+1); return y; } float Gain(float a, float b) { /* float p = log(1.0 - b) / log(0.5); if (a < .001) return 0.0f; else if (a > .999) return 1.0f; if (a < 0.5) return pow(2 * a, p) / 2; else return 1.0f - pow(2 * (1. - a), p) / 2; */ float c = (1.0f/b-2.0f) * (1.0f-2.0f*a); if (a < 0.5) return a/(c+1.0f); else return (c-a)/(c-1.0f); } // 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); }
图像效果可以参考:
http://blog.csdn.net/matrix_space/article/details/46790171
相关文章推荐
- rndc: connect failed 解决
- Google Map,Baidu Map,latitude,longitude
- looking for domain authoritative name server and domain name location
- Leetcode 70 Climbing Stairs 递推
- IP address '172.172.200.88' could not be resolved: Temporary failure in name resolution
- DataInputStream类和RandomAccessFile类的使用方法
- (23)odoo中的domain表达式
- Async/Await - Best Practices in Asynchronous Programming z
- #define+do{} while(0)+peeror的思考
- 1106. Lowest Price in Supply Chain (25)
- 解决MyEclipe出现An error has occurred,See error log for more details的错误
- 解决MyEclipe出现An error has occurred,See error log for more details的错误
- Develop -- Training(九) -- 分享简单数据
- FZU 1978 Repair the brackets
- [leetcode Q9] Container With Most Water
- 17996 Daily Cool Run
- linker command failed with exit code 1 (use -v to see invocation)
- hdu 1021 Fibonacci Again
- 【SPOJ-MAIN75】BST again【计数DP】【记忆化搜索】
- studio调用百度MAP的JNI发生的问题: No implementation found for long com.baidu.platform.comjni.map.commonmemcach