
- Java Digital Image Processing
- DIP - Home
- DIP - Introduction
- DIP - Java BufferedImage Class
- DIP - Image Download & Upload
- DIP - Image Pixels
- DIP - Grayscale Conversion
- DIP - Enhancing Image Contrast
- DIP - Enhancing Image Brightness
- DIP - Enhancing Image Sharpness
- DIP - Image Compression Technique
- DIP - Adding Image Border
- DIP - Image Pyramids
- DIP - Basic Thresholding
- DIP - Image Shape Conversions
- DIP - Gaussian Filter
- DIP - Box Filter
- DIP - Eroding & Dilation
- DIP - Watermark
- DIP - Understanding Convolution
- DIP - Prewitt Operator
- DIP - Sobel Operator
- DIP - Kirsch Operator
- DIP - Robinson Operator
- DIP - Laplacian Operator
- DIP - Weighted Average Filter
- DIP - Create Zooming Effect
- DIP - Open Source Libraries
- DIP - Introduction To OpenCV
- DIP - GrayScale Conversion OpenCV
- DIP - Color Space Conversion
- DIP Useful Resources
- DIP - Quick Guide
- DIP - Useful Resources
- DIP - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java DIP - Create Zooming Effect
Zooming is the process of enlarging an image so that the details in the image become more visible and prominent.
We use OpenCV function resize to apply zooming to images. It can be found under Imgproc package. Its syntax is given below −
Imgproc.resize(source,destination, destination.size(),zoomFactor,zoomFactor,Interpolation);
In the resize function, we pass source image, destination image and its size, zooming factor, and the interpolation method to use.
The interpolation methods available are described below −
Sr.No. | Interpolation method & Description |
---|---|
1 |
INTER_NEAREST It is nearest-neighbour interpolation. |
2 |
INTER_LINEAR It is bilinear interpolation (used by default). |
3 |
INTER_AREA It is resampling using pixel area relation. It may be a preferred method for image decimation, as it gives more-free results. |
4 |
INTER_CUBIC It is a bi-cubic interpolation over 4x4 pixel neighbourhood. |
5 |
INTER_LANCZOS4 It is a Lanczos interpolation over 8x8 pixel neighbourhood. |
Apart from the resize method, there are other methods provided by the Imgproc class. They are described briefly −
Sr.No. | Method & Description |
---|---|
1 |
cvtColor(Mat src, Mat dst, int code, int dstCn) It converts an image from one color space to another. |
2 |
dilate(Mat src, Mat dst, Mat kernel) It dilates an image by using a specific structuring element. |
3 |
equalizeHist(Mat src, Mat dst) It equalizes the histogram of a grayscale image. |
4 |
filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta) It convolves an image with the kernel. |
5 |
GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX) It blurs an image using a Gaussian filter. |
6 |
integral(Mat src, Mat sum) It calculates the integral of an image. |
Example
The following example demonstrates the use of Imgproc class to apply zooming to an image.
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; public class Main { public static void main( String[] args ) { try { int zoomingFactor = 2; System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = Highgui.imread("image.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE); Mat destination = new Mat(source.rows() * zoomingFactor, source.cols()* zoomingFactor,source.type()); Imgproc.resize(source, destination, destination.size(), zoomingFactor,zoomingFactor,Imgproc.INTER_NEAREST); Highgui.imwrite("zoomed.jpg", destination); } catch (Exception e) { System.out.println("Error: "+e.getMessage()); } } }
Output
When you execute the given code, the following output is seen −
Original Image
