Opencv3 C++ VS2017 study notes 13 edge processing during convolution

  • It is easy to find a problem in Note 12: The peripheral circle of pixels cannot be processed during the convolution operation.
    • When the image is convolved, the boundary pixels cannot be convolved. The reason is that the boundary pixels do not completely overlap the kernel. Therefore, when the 3x3 filter is used, the edge of 1 pixel is not processed, and the edge of 2 pixels is not processed when the 5x5 filter is used. Be processed.
  • Handling the edges
    • Before the convolution operation, add edge pixels and fill in pixel values
      • BORDER_CONSTANT-fill the edge with the specified pixel value
      • BORDER_REPLICATE-Fill edge pixels with known edge pixel values.
      • BORDER_WRAP-Use the pixels on the other side to compensate for the fill
    • API
      • copyMakeBorder(src, dst, top,bottom, left, right, borderType, value);
      • Parameters: original image, output image, edge length, generally top\bottom\left\right take the same value, edge type (that is, the three above), color value​​​​​​​
  • In fact, it can be found during blur that GaussianBlur and some functions have the borderType parameter.
    • ​​​​​​​GaussianBlur(src, dst, Size(3, 3), 0, 0, BORDER_CONSTANT);
#include "pch.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>

using namespace std;
using namespace cv;
int main(int argc, char ** argv)
{
	Mat src, gray, bin, dst;
	src = imread("C:\\Users\\xujin\\Desktop\\test1.JPG");
	if (!src.data)
	{
		cout << "no image";
		return -1;
	}
	namedWindow("src_image", WINDOW_AUTOSIZE);
	namedWindow("dst_image", WINDOW_AUTOSIZE);
	imshow("src_image", src);


	int top = (int)(0.05*src.rows);
	int bottom = (int)(0.05*src.rows);
	int left = (int)(0.05*src.cols);
	int right = (int)(0.05*src.cols);
	RNG rng = (12345);
	int borderType = BORDER_CONSTANT;
	Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
	copyMakeBorder(src, dst, top, bottom, left, right, borderType, color);
	
	GaussianBlur(src, dst, Size(3, 3), 0, 0, BORDER_CONSTANT);
    imshow("dst_image", dst);

	waitKey(0);
	return 0;
}

 

Guess you like

Origin blog.csdn.net/Mrsherlock_/article/details/104551674
Recommended