OpenCV双边滤镜

图像过滤可以让您将各种效果应用于图像。 在本章和后面的三章中,我们将讨论各种过滤器操作,如双边过滤器,盒式过滤器,SQR盒式过滤器和过滤器2D。

双边过滤器

双边过滤器操作将双边图像应用于过滤器。可以使用imgproc类的bilateralFilter()方法在图像上执行此操作。 以下是此方法的语法。

bilateralFilter(src, dst, d, sigmaColor, sigmaSpace, borderType)

该方法接受以下参数 -

  • src - 表示此操作的源(输入图像)的Mat对象。
  • dst - 表示此操作的目标(输出图像)的Mat对象。
  • d - 代表像素邻域直径的整数类型变量。
  • sigmaColor - 表示颜色空间中的过滤器sigma的整数类型变量。
  • sigmaSpace - 表示坐标空间中过滤器sigma的整型变量。
  • borderType - 表示所用边框类型的整数对象。

示例

以下程序演示如何对图像执行双边滤镜操作。

package com.zyiz.filtering;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class BilateralFilter {
   public static void main(String args[]) {
      // Loading the OpenCV core library
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

      // Reading the Image from the file and storing it in to a Matrix object
      String file =\\\\\\\"F:/worksp/opencv/images/sample2.jpg\\\\\\\";
      Mat src = Imgcodecs.imread(file);

      // Creating an empty matrix to store the result
      Mat dst = new Mat();

      // Applying Bilateral filter on the Image
      Imgproc.bilateralFilter(src, dst, 15, 80, 80, Core.BORDER_DEFAULT);

      // Writing the image
      Imgcodecs.imwrite(\\\\\\\"F:/worksp/opencv/images/sample2bilateralfilter.jpg\\\\\\\", dst);

      System.out.println(\\\\\\\"Image Processed\\\\\\\");
   }
}

假定以下是上述程序中指定的输入图像sample2.jpg

执行上面示例代码,得到以下结果 -


上一篇:OpenCV中位模糊

下一篇:OpenCV箱式滤镜

关注微信小程序
程序员编程王-随时随地学编程

扫描二维码
程序员编程王

扫一扫关注最新编程教程