Example usage for org.opencv.imgproc Imgproc bilateralFilter

List of usage examples for org.opencv.imgproc Imgproc bilateralFilter

Introduction

In this page you can find the example usage for org.opencv.imgproc Imgproc bilateralFilter.

Prototype

public static void bilateralFilter(Mat src, Mat dst, int d, double sigmaColor, double sigmaSpace,
            int borderType) 

Source Link

Usage

From source file:OCV_BilateralFilter.java

License:Open Source License

@Override
public void run(ImageProcessor ip) {
    if (ip.getBitDepth() == 8) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        byte[] srcdst_bytes = (byte[]) ip.getPixels();

        // mat/*www.j a v a  2s  .co m*/
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1);

        // run
        src_mat.put(0, 0, srcdst_bytes);
        Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace,
                INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_bytes);
    } else if (ip.getBitDepth() == 24) {
        // dst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        int[] srcdst_ints = (int[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3);

        // run
        OCV__LoadLibrary.intarray2mat(srcdst_ints, src_mat, imw, imh);
        Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace,
                INT_BORDERTYPE[indBorderType]);
        OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ints, imw, imh);
    } else if (ip.getBitDepth() == 32) {
        // srcdst
        int imw = ip.getWidth();
        int imh = ip.getHeight();
        float[] srcdst_bytes = (float[]) ip.getPixels();

        // mat
        Mat src_mat = new Mat(imh, imw, CvType.CV_32FC1);
        Mat dst_mat = new Mat(imh, imw, CvType.CV_32FC1);

        // run
        src_mat.put(0, 0, srcdst_bytes);
        Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace,
                INT_BORDERTYPE[indBorderType]);
        dst_mat.get(0, 0, srcdst_bytes);
    } else {
        IJ.error("Wrong image format");
    }
}