📜  Java DIP-Robinson运算符

📅  最后修改于: 2020-12-14 05:42:52             🧑  作者: Mango


罗宾逊罗盘掩模是用于边缘检测的另一种衍生掩模。此运算符也称为方向遮罩。在此运算符,我们采用一个遮罩并将其沿所有八个主要方向旋转以获取八个方向的边缘。

我们将使用OpenCV函数filter2D将Robinson运算符应用于图像。可以在Imgproc软件包下找到。其语法如下-

filter2D(src, dst, depth , kernel, anchor, delta, BORDER_DEFAULT );

函数参数描述如下-

Sr.No. Argument & Description
1

src

It is source image.

2

dst

It is destination image.

3

depth

It is the depth of dst. A negative value (such as -1) indicates that the depth is the same as the source.

4

kernel

It is the kernel to be scanned through the image.

5

anchor

It is the position of the anchor relative to its kernel. The location Point(-1, -1) indicates the center by default.

6

delta

It is a value to be added to each pixel during the convolution. By default it is 0.

7

BORDER_DEFAULT

We let this value by default.

除了filter2D方法之外,Imgproc类还提供其他方法。他们简要描述-

Sr.No. Method & Description
1

cvtColor(Mat src, Mat dst, int code, int dstCn)

It converts an image from one color space to another.

2

dilate(Mat src, Mat dst, Mat kernel)

It dilates an image by using a specific structuring element.

3

equalizeHist(Mat src, Mat dst)

It equalizes the histogram of a grayscale image.

4

filter2D(Mat src, Mat dst, int depth, Mat kernel, Point anchor, double delta)

It convolves an image with the kernel.

5

GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX)

It blurs an image using a Gaussian filter.

6

integral(Mat src, Mat sum)

It calculates the integral of an image.

下面的示例演示如何使用Imgproc类将Robinson运算符应用于灰度图像。

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;

public class convolution {
   public static void main( String[] args ) {
   
      try {
         int kernelSize = 9;
         System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
         
         Mat source = Highgui.imread("grayscale.jpg",  Highgui.CV_LOAD_IMAGE_GRAYSCALE);
         Mat destination = new Mat(source.rows(),source.cols(),source.type());
         
         Mat kernel = new Mat(kernelSize,kernelSize, CvType.CV_32F) {
            {
               put(0,0,-1);
               put(0,1,0);
               put(0,2,1);

               put(1,0-2);
               put(1,1,0);
               put(1,2,2);

               put(2,0,-1);
               put(2,1,0);
               put(2,2,1);
            }
         };          
         
         Imgproc.filter2D(source, destination, -1, kernel);
         Highgui.imwrite("output.jpg", destination);
         
      } catch (Exception e) {
         System.out.println("Error: " + e.getMessage());
      }
   }
}

输出

当您执行给定的代码时,将看到以下输出-

原始图片

应用罗宾逊算子教程

原始图像与北边的Robinson运算符卷积,如下所示-

北向面具

-1 0 1
-2 0 2
-1 0 1

卷积图像(北罗宾逊)

应用罗宾逊算子教程

该原始图像还已经与东边的Robinson运算符进行了卷积处理,如下所示-

东方方向面具

-1 -2 -1
0 0 0
1 2 1

卷积图像(东鲁滨逊)

应用罗宾逊算子教程