OpenCV Filters - adaptiveBilateralFilter

Applies the adaptive bilateral filter to an image.

C++: void adaptiveBilateralFilter(InputArray src, OutputArray dst, Size ksize, double sigmaSpace, double maxSigmaColor=20.0, Point anchor=Point(-1, -1), int borderType=BORDER_DEFAULT )

Python: cv2.adaptiveBilateralFilter(src, ksize, sigmaSpace[, dst[, maxSigmaColor[, anchor[, borderType]]]]) → dst 

Parameters:
  • src – The source image
  • dst – The destination image; will have the same size and the same type as src
  • ksize – The kernel size. This is the neighborhood where the local variance will be calculated, and where pixels will contribute (in a weighted manner).
  • sigmaSpace – Filter sigma in the coordinate space. Larger value of the parameter means that farther pixels will influence each other (as long as their colors are close enough; see sigmaColor). Then d>0, it specifies the neighborhood size regardless of sigmaSpace, otherwise d is proportional to sigmaSpace.
  • maxSigmaColor – Maximum allowed sigma color (will clamp the value calculated in the ksize neighborhood. Larger value of the parameter means that more dissimilar pixels will influence each other (as long as their colors are close enough; see sigmaColor). Then d>0, it specifies the neighborhood size regardless of sigmaSpace, otherwise d is proportional to sigmaSpace.
  • borderType – Pixel extrapolation method.
A main part of our strategy will be to load each raw pixel once, and reuse it to calculate all pixels in the output (filtered) image that need this pixel value. The math of the filter is that of the usual bilateral filter, except that the sigma color is calculated in the neighborhood, and clamped by the optional input value.

Reference: OpenCV Documentation -  adaptiveBilateralFilter

Example
This is a sample code (C++) with images for opencv adaptive bilateral filter.

  string imgFileName = "lena.jpg";

  cv::Mat src = cv::imread(imgFileName);
  if (!src.data){
     cout << "Unable to open file" << endl;
     getchar();
     return 1;
  }

  cv::Mat dst;
  cv::adaptiveBilateralFilter(src, dst, cv::Size(11, 11), 50);//kernal size(11) should be an odd value

 cv::namedWindow("Source");
 cv::namedWindow("Filtered");

 cv::imshow("Source", src);
 cv::imshow("Filtered", dst);

 cv::waitKey(0);

 cv::imwrite("Adaptive Bilateral Filter.jpg", dst);


Filtered Image Source Image



Download complete Visual Studio project.

No comments:

Post a Comment