#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; // obfuscation // Smooth/Blur is the simplest common operation in image processing // used for noise reduction during preprocessing // The principle behind it is mathematical convolution calculation // blur(src, dst, Size(x_radius, y_radius), Point(-1, -1)); mean filter // GaussianBlur(src, dst, Size(11, 11), sigmax, sigmay); Gaussian Blur is blurred based on a normal distribution mask, so it will have a little more contrast than mean filtering // must use odd mask
// An interesting little operation can set Size(x, y) to a single direction to achieve horizontal or vertical blur.
// Median filter has a good suppression effect on salt and pepper noise // medianBlur(src, dst, ksize) // minimum and maximum filter // Gaussian bilateral blur --- is an edge-preserving filtering method, which avoids the loss of edge information and keeps the image outline unchanged // bilateralFilter (src, dst, ksize, sigmaColor, sigmaSpace); /* src – Source 8-bit or floating-point, 1-channel or 3-channel image. dst – Destination image of the same size and type as src . d – Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace . sigmaColor – Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see sigmaSpace ) will be mixed together, resulting in larger areas of semi-equal color. sigmaSpace – Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see sigmaColor ). When d>0 , it specifies the neighborhood size regardless of sigmaSpace . Otherwise, d is proportional to sigmaSpace . */ // Simply put, ksize is the size of the mask; the larger the sigmaColor, the larger the color range involved in blurring, that is, the lower the contrast; the larger the sigmaSpace, the more pixels that affect each other. // But sigmaSpace interacts with ksize, ksize > 0, sigmaSpace does not work; ksize < 0, z generates ksize by sigmaSpace. int main() { Mat src1, src2, gray_src, dst; src1 = imread("/Users/apple/Desktop/birth.jpg", IMREAD_COLOR); //src2 = imread("/Users/apple/Desktop/test2.jpg", IMREAD_COLOR); if (src1.empty()) { // if (!src.data()) cout << "could not load image..." << endl; return -1; } imshow("input", src1); //blur(src1, dst, Size(15, 15), Point(-1, -1)); //imshow("blur_output", dst); GaussianBlur(src1, dst, Size(5, 5), 11); //imshow("gaussianblur_output", dst); //medianBlur(src1, dst, 15); //imshow("medianBlur", dst); bilateralFilter(src1, dst, 3, 30, 100); //imshow("bilateral", dst); Mat kernel = (Mat_<int>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0); filter2D(dst, dst, -1, kernel); imshow("Final result", dst); waitKey(0); return 0; }