English 中文(简体)
DIP - Image Pyramids
  • 时间:2024-12-22

Java DIP - Image Pyramids


Previous Page Next Page  

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

Image Pyramids Tutorial

On the original image, pyrUp(UP Samppng) and pyrDown(Down Samppng) are performed. The output after samppng is as shown below −

PyrUP Image

Image Pyramids Tutorial

pyrDown Image

Image Pyramids Tutorial Advertisements