Download java_dip_tutorial.pdf PDF

Titlejava_dip_tutorial.pdf
TagsJava Programming Language Pixel String (Computer Science) Integer (Computer Science) Rgb Color Model
File Size2.7 MB
Total Pages149
Document Text Contents
Page 2

Java Digital Image Processing

i

About the Tutorial

This tutorial gives a simple and practical approach of implementing algorithms

used in digital image processing. After completing this tutorial, you will find

yourself at a moderate level of expertise, from where you can take yourself to

next levels.

Audience

This reference has been prepared for the beginners to help them understand and

implement the basic to advance algorithms of digital image processing in java.

Prerequisites

Before proceeding with this tutorial, you need to have a basic knowledge of digital

image processing and Java programming language.

Disclaimer & Copyright

 Copyright 2014 by Tutorials Point (I) Pvt. Ltd.

All the content and graphics published in this e-book are the property of Tutorials

Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy,

distribute or republish any contents or a part of contents of this e-book in any

manner without written consent of the publisher. We strive to update the contents

of our website and tutorials as timely and as precisely as possible, however, the

contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides

no guarantee regarding the accuracy, timeliness or completeness of our website

or its contents including this tutorial. If you discover any errors on our website or

in this tutorial, please notify us at [email protected]

















mailto:[email protected]

Page 75

Java Digital Image Processing

68

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 perform erosion and

dilation on an image:

import org.opencv.core.Core;

import org.opencv.core.CvType;

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{

System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

Mat source = Highgui.imread("digital_image_processing.jpg",

Highgui.CV_LOAD_IMAGE_COLOR);

Mat destination =new

Mat(source.rows(),source.cols(),source.type());

destination = source;

Page 148

Java Digital Image Processing

141

public class Main {

public static void main( String[] args )

{

try {

System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

File input = new File("digital_image_processing.jpg");

BufferedImage image = ImageIO.read(input);

byte[] data = ((DataBufferByte) image.getRaster().

getDataBuffer()).getData();

Mat mat = new Mat(image.getHeight(),image.getWidth(),CvType.CV_8UC3);

mat.put(0, 0, data);



Mat mat1 = new Mat(image.getHeight(),image.getWidth(),CvType.CV_8UC3);

Imgproc.cvtColor(mat, mat1, Imgproc.COLOR_RGB2HSV);



byte[] data1 = new

byte[mat1.rows()*mat1.cols()*(int)(mat1.elemSize())];

mat1.get(0, 0, data1);

BufferedImage image1 = new BufferedImage(mat1.cols(), mat1.rows(), 5);

image1.getRaster().setDataElements(0,0,mat1.cols(),mat1.rows(),data1);



File ouptut = new File("hsv.jpg");

ImageIO.write(image1, "jpg", ouptut);

} catch (Exception e) {

System.out.println("Error: " + e.getMessage());

}

}

}

Page 149

Java Digital Image Processing

142

Output

When you execute the given example, it converts an image name

digital_image_processing.jpg to its equivalent HSV color space image and writes it

on hard disk with name hsv.jpg.

Original Image (RGB)



Converted Image (HSV)

Similer Documents