尽管现在都还不懂,先记录一下
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:
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 );
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:
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:
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: