Java OpenCV-4.0.0 圖像處理07.2 圖像形態學操作 圖像頂帽和黑帽
Java OpenCV-4.0.0 圖像處理 圖像形態學操作 圖像頂帽和黑帽
頂帽:原圖像與開操作之間的差值圖像。
黑帽:原圖像與閉操作之間的差值圖像
/**
* OpenCV-4.0.0 圖像形態學 頂帽 (原圖像與開操作之間的差值圖像)
* @return: void
* @date: 2019年5月7日12:16:55
*/
public static void topHat() {
Mat src = Imgcodecs.imread("C:\\Users\\Administrator\\Pictures\\1.jpg");
Mat image = new Mat(src.size(), src.type());
//Imgproc.getStructuringElement 獲取圖片形態結構調整Size(,)的大小來去除污點
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15, 15), new Point(-1, -1));
Imgproc.morphologyEx(src, image, Imgproc.MORPH_TOPHAT, kernel);
//Imgproc.resize(image, image, new Size(image.width()/3,image.height()/3));
HighGui.imshow("圖像形態學 頂帽 (原圖像與開操作之間的差值圖像)", image);
HighGui.waitKey(1);
}
/**
* OpenCV-4.0.0 圖像形態學 黑帽 (原圖像與閉操作之間的差值圖像)
* @return: void
* @date: 2019年5月7日12:16:55
*/
public static void blackHat() {
Mat src = Imgcodecs.imread("C:\\Users\\Administrator\\Pictures\\1.jpg");
Mat image = new Mat(src.size(), src.type());
//Imgproc.getStructuringElement 獲取圖片形態結構元素,調整Size(,)的大小來去除污點
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15, 15), new Point(-1, -1));
Imgproc.morphologyEx(src, image, Imgproc.MORPH_BLACKHAT, kernel);
//Imgproc.resize(image, image, new Size(image.width()/3,image.height()/3));
HighGui.imshow("圖像形態學 黑帽 (原圖像與閉操作之間的差值圖像)", image);
HighGui.waitKey(1);
}