📜  Java DIP-图像金字塔

📅  最后修改于: 2020-12-14 05:38:33             🧑  作者: Mango


图像金字塔不过是显示多分辨率图像的方法。最下层是图像的最高分辨率版本,最上层是图像的最低分辨率版本。图像金字塔用于处理不同比例的图像。

在本章中,我们对图像执行一些下采样和上采样。

我们使用OpenCV函数pyrUppyrDown 。它们可以在Imgproc软件包下找到。其语法如下-

Imgproc.pyrUp(source, destination, destinationSize);
Imgproc.pyrDown(source, destination,destinationSize);

参数说明如下-

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)).

除了pyrUp和pyrDown方法外,Imgproc类还提供其他方法。他们简要描述-

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 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.

下面的示例演示如何使用Imgproc类对图像执行上采样和下采样。

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;

public class main {
   public 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());
      }
   }
}

输出

当您执行给定的代码时,将看到以下输出-

原始图片

图像金字塔教程

在原始图像上,执行pyrUp(上采样)和pyrDown(下采样)。采样后的输出如下所示-

PyrUP图片

图像金字塔教程

pyrDown图片

图像金字塔教程