OpenCV - Gaussian Blur
ในการดำเนินการ Gaussian Blur ภาพจะถูกแปลงด้วยฟิลเตอร์ Gaussian แทนตัวกรองกล่อง ตัวกรอง Gaussian เป็นตัวกรองความถี่ต่ำที่ลบส่วนประกอบความถี่สูงจะลดลง
คุณสามารถดำเนินการนี้กับรูปภาพโดยใช้ไฟล์ Gaussianblur() วิธีการของ imgprocชั้นเรียน ต่อไปนี้เป็นไวยากรณ์ของวิธีนี้ -
GaussianBlur(src, dst, ksize, sigmaX)
วิธีนี้ยอมรับพารามิเตอร์ต่อไปนี้ -
src - ก Mat วัตถุแทนแหล่งที่มา (ภาพอินพุต) สำหรับการดำเนินการนี้
dst - ก Mat อ็อบเจ็กต์ที่แสดงปลายทาง (รูปภาพเอาต์พุต) สำหรับการดำเนินการ
ksize - ก Size วัตถุที่แสดงขนาดของเคอร์เนล
sigmaX - ตัวแปรประเภท double ที่แสดงถึงค่าเบี่ยงเบนมาตรฐานของเคอร์เนล Gaussian ในทิศทาง X
ตัวอย่าง
โปรแกรมต่อไปนี้แสดงให้เห็นถึงวิธีดำเนินการเบลอแบบเกาส์เซียนบนรูปภาพ
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class GaussianTest {
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 ="C:/EXAMPLES/OpenCV/sample.jpg";
Mat src = Imgcodecs.imread(file);
// Creating an empty matrix to store the result
Mat dst = new Mat();
// Applying GaussianBlur on the Image
Imgproc.GaussianBlur(src, dst, new Size(45, 45), 0);
// Writing the image
Imgcodecs.imwrite("E:/OpenCV/chap9/Gaussian.jpg", dst);
System.out.println("Image Processed");
}
}
สมมติว่าต่อไปนี้เป็นภาพอินพุต sample.jpg ระบุไว้ในโปรแกรมข้างต้น
เอาต์พุต
ในการรันโปรแกรมคุณจะได้รับผลลัพธ์ต่อไปนี้ -
Image Processed
หากคุณเปิดเส้นทางที่ระบุคุณสามารถสังเกตภาพที่ส่งออกได้ดังนี้ -