当前位置:网站首页>Opencv3 6.3 reduced pixel sampling with filters
Opencv3 6.3 reduced pixel sampling with filters
2022-07-02 08:08:00 【Villanelle#】
Reduce pixel sampling
The process of reducing image accuracy is called Reduce pixel sampling (downsampling), The process of improving image accuracy is called Improve pixel sampling (upsampling).
Spatial pseudofrequency
If you want to zoom out an image , Just eliminate the middle rows and columns of the image , Then splice the remaining pixels , The image effect is often unsatisfactory .
cv::Mat image = cv::imread("boldt.jpg");
cv::Mat reduced1(image.rows / 4, image.cols / 4, CV_8UC3);
for (int i = 0; i < reduced1.rows; i++)
{
for (int j = 0; j < reduced1.cols; j++)
{
reduced1.at<cv::Vec3b>(i, j) = image.at<cv::Vec3b>(i * 4, j * 4);
}
}
// Display each pixel four times its original size ( Use nearest point interpolation )
cv::resize(reduced1, reduced1, cv::Size(), 4, 4, cv::INTER_NEAREST);
cv::imshow("badly reduced", reduced1);

In this case , First traverse and reserve one of the four pixels , Re pass cv::resize() Function amplification . It can be seen that , The quality of the image is significantly reduced , Obvious sawtooth deformation can be seen , Is due to Spatial pseudofrequency Caused by the .
When trying to include high-frequency components in the image and the image is too small to include , Will appear Spatial pseudofrequency , The solution is Remove the high-frequency components before reducing the image , In this example, Gaussian filtering in the previous section is used .
cv::Mat reduced2(image.rows / 4, image.cols / 4, CV_8UC3);
// First, Gaussian filtering is used to remove high-frequency components
cv::GaussianBlur(image, image, cv::Size(11, 11), 2.0);
for (int i = 0; i < reduced2.rows; i++)
{
for (int j = 0; j < reduced2.cols; j++)
{
reduced2.at<cv::Vec3b>(i, j) = image.at<cv::Vec3b>(i * 4, j * 4);
}
}
// Display each pixel four times its original size ( Use nearest point interpolation )
cv::resize(reduced2, reduced2, cv::Size(), 4, 4, cv::INTER_NEAREST);
cv::imshow("reduced image", reduced2);

Image quality is much better than directly removing pixels , But also lost some delicate details .
in addition , Lead to a theorem Nyquist-Shannon Theorem , That is, the image is reduced by half , Its visible frequency bandwidth will also be reduced by half .
cv::pyrDown Achieve image reduction
OpenCV Built in cv::pyrDown Function realizes image reduction , The principle is to use 5*5 Gauss filter , First, low-pass filter the image and then reduce it ( It can only be reduced to 1/2).
Its parameters are the original image 、 Output image .
cv::Mat reduced3;
cv::pyrDown(image, reduced3);
cv::imshow("pyrdown", reduced3);

On the contrary , One more cv::pyrUp Function can enlarge the image size , The principle is first on every two lines / The pixel value inserted between two columns is 0 The pixel , Then apply to the expanded image 5*5 Gauss filter .
The parameters are : Original image 、 Output image .
cv::Mat enlarged;
cv::pyrUp(image, enlarged);
cv::imshow("pyrup", enlarged);

The above two built-in functions can only achieve twice the reduction and amplification , In fact, there is a more general function cv::resize, You can specify the size of the scaled image .
cv::resize Use of functions
Function signature
CV_EXPORTS_W void resize( InputArray src, OutputArray dst,
Size dsize, double fx = 0, double fy = 0,
int interpolation = INTER_LINEAR );
- The parameters are : Original image , Output image , The size of the output image ,x Directional amplification factor ,y Directional amplification factor , Interpolation method .
- You can not specify the size of the output image ( The specified value is empty cv::Size()), Must be specified x and y Amplification factor of direction , If 2 Just double the magnification .
- You may not specify the magnification factor ( The default is 0), You must specify the size of the output image .
- If the interpolation method here is not specified as bilinear interpolation
cv::INTER_LINEAR, You can combine the values of multiple adjacent pixels , It is better to . In addition, there is nearest neighbor interpolationcv::INTER_LINEAR, The nearest pixel will be selected for interpolation .
边栏推荐
- 使用C#语言来进行json串的接收
- 用MLP代替掉Self-Attention
- Global and Chinese markets for Salmonella typhi nucleic acid detection kits 2022-2028: Research Report on technology, participants, trends, market size and share
- Carsim-路面3D形状文件参数介绍
- Eklavya -- infer the parameters of functions in binary files using neural network
- One book 1078: sum of fractional sequences
- 解决jetson nano安装onnx错误(ERROR: Failed building wheel for onnx)总结
- Static library and dynamic library
- open3d环境错误汇总
- I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
猜你喜欢

Hystrix dashboard cannot find hystrix Stream solution

针对tqdm和print的顺序问题

浅谈深度学习中的对抗样本及其生成方法

静态库和动态库

用MLP代替掉Self-Attention

Graph Pooling 简析
![[binocular vision] binocular stereo matching](/img/93/2e916038f0e7d0c7b3bf64f8dc1b4e.png)
[binocular vision] binocular stereo matching

In the era of short video, how to ensure that works are more popular?

Data reverse attack under federated learning -- gradinversion

用全连接层替代掉卷积 -- RepMLP
随机推荐
针对语义分割的真实世界的对抗样本攻击
Sparse matrix storage
Gensim如何冻结某些词向量进行增量训练
Feature Engineering: summary of common feature transformation methods
Simply test the two different data transmission methods of content length and chunked
Find and rfind methods in string
樂理基礎(簡述)
install. IMG production method
Media query usage
E-R draw clear content
Embedding malware into neural networks
用C# 语言实现MYSQL 真分页
力扣每日一题刷题总结:字符串篇(持续更新)
C语言的库函数
AR system summary harvest
OpenCV3 6.3 用滤波器进行缩减像素采样
[learning notes] matlab self compiled image convolution function
Open3d learning note 3 [sampling and voxelization]
【学习笔记】Matlab自编高斯平滑器+Sobel算子求导
Wang extracurricular words