- DIP - Color Space Conversion
- DIP - GrayScale Conversion OpenCV
- DIP - Introduction To OpenCV
- DIP - Open Source Libraries
- DIP - Create Zooming Effect
- DIP - Weighted Average Filter
- DIP - Laplacian Operator
- DIP - Robinson Operator
- DIP - Kirsch Operator
- DIP - Sobel Operator
- DIP - Prewitt Operator
- DIP - Understanding Convolution
- DIP - Watermark
- DIP - Eroding & Dilation
- DIP - Box Filter
- DIP - Gaussian Filter
- DIP - Image Shape Conversions
- DIP - Basic Thresholding
- DIP - Image Pyramids
- DIP - Adding Image Border
- DIP - Image Compression Technique
- DIP - Enhancing Image Sharpness
- DIP - Enhancing Image Brightness
- DIP - Enhancing Image Contrast
- DIP - Grayscale Conversion
- DIP - Image Pixels
- DIP - Image Download & Upload
- DIP - Java BufferedImage Class
- DIP - Introduction
- DIP - Home
DIP Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java DIP - Image Pyramids
Image pyramid is nothing but a method to display a multi-resolution image. The lowermost layer is a highest-resolution version of image and the topmost layer is a lowest-resolution version of the image. Image pyramids are used to handle image at different scales.
In this chapter we perform some down samppng and up samppng on images.
We use OpenCV functions pyrUp and pyrDown. They can be found under Imgproc package. Its syntax is given below −
Imgproc.pyrUp(source, destination, destinationSize); Imgproc.pyrDown(source, destination,destinationSize);
The parameters are described below −
Sr.No. | Parameter & Description |
---|---|
1 |
source It is the source image. |
2 |
destination It is the destination image. |
3 |
destinationSize It is the size of the output image. By default, it is computed as Size((src.cols*2), (src.rows*2)). |
Apart from the pyrUp and pyrDown methods, 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 |
equapzeHist(Mat src, Mat dst) It equapzes the histogram of a grayscale image. |
4 |
filter2D(Mat src, Mat dst, int depth, 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 perform up samppng and down samppng on an image.
import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; pubpc class main { pubpc static void main( String[] args ) { try{ System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = Highgui.imread("digital_image_processing.jpg", Highgui.CV_LOAD_IMAGE_COLOR); Mat destination1 = new Mat(source.rows()*2, source.cols()*2,source.type()); destination1 = source; Imgproc.pyrUp(source, destination1, new Size(source.cols()*2 source.rows()*2)); Highgui.imwrite("pyrUp.jpg", destination1); source = Highgui.imread("digital_image_processing.jpg", Highgui.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows()/2,source.cols()/2, source.type()); destination = source; Imgproc.pyrDown(source, destination, new Size(source.cols()/2, source.rows()/2)); Highgui.imwrite("pyrDown.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
On the original image, pyrUp(UP Samppng) and pyrDown(Down Samppng) are performed. The output after samppng is as shown below −