如何使用 Java OpenCV 库改变图像的锐度?
图像锐化与图像模糊相反。如需使用 OpenCV 库来改变图像锐度,则需进行平滑/模糊处理,即使用高斯滤波器进行模糊处理,再将平滑处理后的图像从原始图像中减去。
范例
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 AlteringSharpness { public static void main (String[] args) { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the Image from the file String file ="D:\Image\lamma1.jpg"; Mat src = Imgcodecs.imread(file, Imgcodecs.IMREAD_COLOR); //Creating an empty matrix Mat dest = new Mat(src.rows(), src.cols(), src.type()); Imgproc.GaussianBlur(src, dest, new Size(0,0), 10); Core.addWeighted(src, 1.5, dest, -0.5, 0, dest); // Writing the image Imgcodecs.imwrite("D:\Image\altering_sharpness_100.jpg", dest); } }
输入
输出
广告