加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[数字图像处理学习]幂律(伽马)变换

(2014-10-13 20:27:59)
标签:

杂谈

分类: 图像工程

幂律变换的基本形式:

http://s9/middle/002OBL7Wzy6MMOK0yW438&690

其中,c和γ为正常数。注:r和s取值范围[0,1]。

使用幂律变换进行对比度增强;灰度级压缩。

 

C/C++ Demo:

//通用

#include <iostream>

#include <stdio.h>

 

//图像操作

#include <opencv2/core/core.hpp>

#include <opencv2/imgproc/imgproc.hpp>

#include <opencv2/highgui/highgui.hpp>

 

 

using namespace :: std;

using namespace :: cv;

 

int main()

{

//图像读取

Mat image = imread("Fig0309_a.tif");

 

//判断图像读取是否有问题

if(!image.data)

{

cout << "image read is error!" << endl;

return 0;

}

 

//图像基本信息输出

cout << "image Info:Height:" << image.size().height << " Width:" << image.size().width << endl;

 

//原始图像显示

namedWindow("Original Image");

imshow("Original Image", image);

 

//处理图像

//读取gamma分别对应的数表

FILE *fp1;

fp1 = fopen("GammaData_0_95.txt","r");

 

if(fp1 == NULL)        { cout << "File Open Error!" << endl; return 0; }

 

int gamma[256];

 

for (int i = 0; i < 256; i++)

{

fscanf(fp1, "%d", &gamma[i]);

}

 

fclose(fp1);

 

//gamma变换

int nl = image.rows;

int nc = image.cols * image.channels();

if(image.isContinuous())

{

nc = nc * nl;

nl = 1;

}

int i,j;

uchar *data;

for(j = 0; j < nl; j ++)

{

uchar *data = image.ptr<uchar>(j);

for(i = 0; i < nc; i ++)

{

data[i] = gamma[data[i]];

//cout << data[i];

}

}

cout << endl;

 

//显示图像

namedWindow("Process Image");

imshow("Process Image", image);

 

//保存图像

 

waitKey(0);

 

return 0;

}

 

Matlab Demo(用来产生数表):

 

file1 = fopen('D:\Working\OpenCV\OpenCV\GammaData_0_3.txt', 'wt+');

 

for i = 0 : 255

    value1 = ((i / 256)^0.3) * 256;

   

    if(value1 > 255)   value1 = 255; end

   

    fprintf(file1, '%d ', round(value1));

end

 

fclose(file1);

 

原图:

original

 

Gamma = 3.0:

result 

 

Gamma = 4.0:

result

 

Gamma = 5.0:

result

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有