Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Alter Image Sharpness Using Java OpenCV Library



Sharpening an image is the opposite of blur. To alter the sharpness of an image using the OpenCV library, you need to smooth/blur it using the Gaussian filter and subtract the smoothed version from the original image.

Example

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);
   }
}

Input

Output

Updated on: 2020-04-09T07:55:11+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements