图像处理算法

尽管现在都还不懂,先记录一下

1.锐化(sharpen)

Let us consider the issue of an image contrast enhancement method.
Basically we want to apply for every pixel of the image the following
formula:

Sharpen

The first notation is by using a formula, while the second is a
compacted version of the first by using a mask. You use the mask by
putting the center of the mask matrix (in the upper case noted by the
zero-zero index) on the pixel you want to calculate and sum up the
pixel values multiplied with the overlapped matrix values. It’s the
same thing, however in case of large matrices the latter notation is a
lot easier to look over.

    Mat kernel = (Mat_<char>(3,3) <<  0, -1,  0,
                                   -1,  5, -1,
                                    0, -1,  0);
    filter2D( src, dst1, src.depth(), kernel );

tutorial_mat_mask_operations

2. Linear Blend

From our previous tutorial, we know already a bit of Pixel operators.
An interesting dyadic (two-input) operator is the linear blend
operator:

linear blending

By varying α from 0→1 this operator can be used to perform a temporal
cross-dissolve between two images or videos, as seen in slide shows
and film productions (cool, eh?)

   double alpha = 0.5; double beta; 
   beta = ( 1.0 - alpha );
   addWeighted( src1, alpha, src2, beta, 0.0, dst);

3 调整亮度和对比度

3.1

Two commonly used point processes are multiplication and addition with
a constant:
g(x)=αf(x)+β
The parameters α>0 and β are often called the gain and bias parameters;
sometimes these parameters are said to control contrast and brightness respectively.
You can think of f(x) as the source image pixels and g(x) as the output image pixels. Then,
more conveniently we can write the expression as:
g(i,j)=α⋅f(i,j)+β
where i and j indicates that the pixel is located in the i-th row and j-th column.

for( int y = 0; y < image.rows; y++ ) {
    for( int x = 0; x < image.cols; x++ ) {
        for( int c = 0; c < image.channels(); c++ ) {
            new_image.at<Vec3b>(y,x)[c] =
              saturate_cast<uchar>( alpha*image.at<Vec3b>(y,x)[c] + beta );
        }
    }
}

更简便的实现

image.convertTo(new_image, -1, alpha, beta);

3.2 Gamma correction

Gamma correction can be used to correct the brightness of an image by
using a non linear transformation between the input values and the
mapped output values:

gamma correction

As this relation is non linear, the effect will not be the same for
all the pixels and will depend to their original value.

    Mat lookUpTable(1, 256, CV_8U);
    uchar* p = lookUpTable.ptr();
    for( int i = 0; i < 256; ++i)
        p[i] = saturate_cast<uchar>(pow(i / 255.0, gamma_) * 255.0);
    Mat res = img.clone();
    LUT(img, lookUpTable, res);

4 离散傅立叶变换(Discrete Fourier Transform DFT )

The Fourier Transform will decompose an image into its sinus and
cosines components. In other words, it will transform an image from
its spatial domain to its frequency domain. The idea is that any
function may be approximated exactly with the sum of infinite sinus
and cosines functions. The Fourier Transform is a way how to do this.
Mathematically a two dimensional images Fourier transform is:
The Fourier Transform

code example

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值