当前位置:网站首页>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 .
边栏推荐
- Rhel7 operation level introduction and switching operation
- SQL server如何卸载干净
- Eklavya -- infer the parameters of functions in binary files using neural network
- Command line is too long
- 力扣方法总结:滑动窗口
- Organigramme des activités
- Remplacer l'auto - attention par MLP
- Correction binoculaire
- Erase method in string
- open3d学习笔记三【采样与体素化】
猜你喜欢
Array and string processing, common status codes, differences between PHP and JS (JS)
用于类别增量学习的动态可扩展表征 -- DER
C language implements XML generation and parsing library (XML extension)
Embedding malware into neural networks
用MLP代替掉Self-Attention
简易打包工具的安装与使用
Sqlyog remote connection to MySQL database under centos7 system
Nacos service registration in the interface
Static library and dynamic library
将恶意软件嵌入到神经网络中
随机推荐
Fundamentals of music theory (brief introduction)
A brief analysis of graph pooling
open3d学习笔记三【采样与体素化】
应对长尾分布的目标检测 -- Balanced Group Softmax
Hystrix dashboard cannot find hystrix Stream solution
STM32疑难杂症之ST-LINK Connection error INVALID ROM TABLE
【MagNet】《Progressive Semantic Segmentation》
Where do you find the materials for those articles that have read 10000?
Longest isometric subsequence
Global and Chinese market of snow sweepers 2022-2028: Research Report on technology, participants, trends, market size and share
利用超球嵌入来增强对抗训练
Business architecture diagram
用MLP代替掉Self-Attention
install.img制作方式
【学习笔记】Matlab自编高斯平滑器+Sobel算子求导
乐理基础(简述)
The hystrix dashboard reported an error hystrix Stream is not in the allowed list of proxy host names solution
常量指针和指针常量
In the era of short video, how to ensure that works are more popular?
Constant pointer and pointer constant