Image Processing using OpenCV in Java | Set 14 ( Sharpness Enhancement )
In this article we will learn how to enhance sharpness of an image using OpenCv library.
In order to enhance sharpness we will use Gaussian filter. Gaussian filter reduces the noise in the image and makes it look better (or higher resolution).
At first we need to setup OpenCV for java, we recommend to use eclipse for the same since it is easy to use and setup.For installation refer to http://docs.opencv.org/2.4/doc/tutorials/introduction/java_eclipse/java_eclipse.html
Methods required for sharpness enhancement.
- GaussianBlur(source, destination, new Size(0, 0), sigmaX) – This method resides in Imgproc package of OpenCv.
Imgproc.GaussianBlur(source, destination, new Size(0, 0), sigmaX) parameters: source - source image destination - destination image new Size(0, 0) - Gaussian kernel size sigmaX - Gaussian kernel standard deviation in X direction
addWeighted(InputArray src1, alpha, src2, beta, gamma, OutputArray dst) - This method resides in Core package of OpenCv.
Core.addWeighted(InputArray src1, alpha, src2, beta, gamma, OutputArray dst) parameters: src1 - first input array alpha - weight of the first array elements src2 - second input array of the same size and channel number as src1 beta - weight of the second array elements gamma - scalar added to each sum dst - output array that has the same size and number of channels as the input arrays
- imread() - This method is used to read images as Mat objects which are rendered by OpenCV.
Imgcodecs.imread(filename); parameters: filename: filename of the image file.If the image is in another directory whole path of image must be mentioned.
- imwrite() - This method is used to write Mat objects to image file.
Imgcodecs.imwrite(filename, mat_img); parameters: filename: filename of the image file.If the image is in another directory whole path of image must be mentioned. mat_img: resultant mat object.
Note: The code will not work in online ide since it requires image in hard drive.
output.jpgTry to notice minor improvement in resolution
This article is contributed by Pratik Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.