Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Image Processing In Java - Get and Set Pixels
Next article icon

Image Processing in Java - Sharpness Enhancement

Last Updated : 03 Feb, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Prerequisites:

  • Image Processing in Java - Read and Write
  • Image Processing In Java - Get and Set Pixels
  • Image Processing in Java - Colored Image to Grayscale Image Conversion
  • Image Processing in Java - Colored Image to Negative Image Conversion
  • Image Processing in Java - Colored to Red Green Blue Image Conversion
  • Image Processing in Java - Colored Image to Sepia Image Conversion
  • Image Processing in Java - Creating a Random Pixel Image
  • Image Processing in Java - Creating a Mirror Image
  • Image Processing in Java - Face Detection
  • Image Processing in Java - Watermarking an Image
  • Image Processing in Java – Changing Orientation of Image
  • Image Processing in Java - Contrast Enhancement
  • Image Processing in Java - Brightness Enhancement
  • Image Processing in Java - Comparison of Two Images

 Tip: It is recommended to use eclipse for the same since it is easy to use and set up.

Here, we will use a Gaussian filter. This filter reduces the noise in the image and makes it look better (or higher resolution). Go through the pre-requisite of installing OpenCV and setup as per OS in your local machine in order to write code as we will be importing libraries. So let us discuss prior methods required for sharpness enhancement. 

Method 1: GaussianBlur(): This method resides in Imgproc package of OpenCv. 

Syntax: 

Imgproc.GaussianBlur(source, destination, new Size(0, 0), sigmaX)

Parameters:

  • Source image
  • Destination image
  • Gaussian kernel size
  • Gaussian kernel standard deviation in X direction

Method 2: addWeighted(): This method resides in the Core package of OpenCV. 

Syntax: 

Core.addWeighted(InputArray src1, alpha, src2, beta, gamma, OutputArray dst)

Parameters:

  • First input array
  • Weight of the first array elements
  • Second input array of the same size and channel number as src1
  • Weight of the second array elements
  • Scalar added to each sum
  • Output array that has the same size and number of channels as the input arrays

Method 3: imread(): It is used to read images as Mat objects which are rendered by OpenCV. 

Syntax: 

Imgcodecs.imread(filename);

Parameters: Filename of the image file. If the image is in another directory whole path of the image must be mentioned.

Method 4: imwrite():  It is used to write Mat objects to an image file. 

Syntax: 

Imgcodecs.imwrite(filename, mat_img);

Parameters:

  • Filename of the image file. If the image is in another directory whole path of an image must be mentioned.
  • Resultant mat object.

Implementation: The input image is as follows:

Example

Java
// Java Program to Enhance Sharpness in An Image // Using OpenCV Library  // Importing package module package ocv;  // Importing require classes 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;  // Main class public class GFG {      // Main driver method     public static void main(String[] args)     {         // Try block to check for exceptions         try {              // For proper execution of native libraries             // Core.NATIVE_LIBRARY_NAME must be loaded             // before calling any of the opencv methods             System.loadLibrary(Core.NATIVE_LIBRARY_NAME);              // Reading the input image from local directory             // by creating object of Mat class             Mat source = Imgcodecs.imread(                 "E://input.jpg",                 Imgcodecs.CV_LOAD_IMAGE_COLOR);                        Mat destination                 = new Mat(source.rows(), source.cols(),                           source.type());              // Filtering             Imgproc.GaussianBlur(source, destination,                                  new Size(0, 0), 10);             Core.addWeighted(source, 1.5, destination, -0.5,                              0, destination);              // Writing output image to directory in the local             // system             Imgcodecs.imwrite("E://output.jpg",                               destination);         }          // Catch block to handle exceptions         catch (Exception e) {              // Display message when exception occurs             System.out.print("Exception/s Occurred")         }     } } 

 
 

Output:


 

Note: Do notice a minor improvement in resolution


 


Next Article
Image Processing In Java - Get and Set Pixels

P

Pratik Agarwal
Improve
Article Tags :
  • Java
  • Image-Processing
  • OpenCV
Practice Tags :
  • Java

Similar Reads

  • Image Processing in Java - Contrast Enhancement
    Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C
    2 min read
  • Image Processing in Java - Brightness Enhancement
    Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C
    3 min read
  • Image Processing in Java - Read and Write
    Java implements a particular type of object called a BufferedImage for images in Java. A BufferedImage can be read from several distinct image types (i.e., BMP, HEIC, etc.). Not all of these are backed by ImageIO itself, but there are plugins to extend ImageIO and other libraries such as Apache Imag
    3 min read
  • Image Processing In Java - Get and Set Pixels
    Prerequisite - Image Processing in Java - Read and Write In this set, we will learn about the pixels of images, how we can get pixel values of an image and how to set pixel values in an image using Java programming language. Pixels are the smallest unit of an image which consists of four components
    3 min read
  • Image Processing in Java - Watermarking an Image
    Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C
    3 min read
  • Image Processing in Java - Face Detection
    Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C
    3 min read
  • Image Processing in Java - Creating a Random Pixel Image
    Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C
    2 min read
  • Image Processing in Java - Creating a Mirror Image
    Prerequisite:  Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C
    3 min read
  • Image Processing in Java - Comparison of Two Images
    Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C
    4 min read
  • Image Processing in Java - Colored Image to Sepia Image Conversion
    Prerequisites:  Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences