Sei sulla pagina 1di 43

VISVESVARAIAH TECHNOLOGICAL UNIVERSITY BELGAUM

DHARWAD- 580 002

COMPARATIVE STUDY OF IMAGE MANIPULATION OPERATIONS IN JAVA, MATLAB AND JAVA ADAVANCED IMAGING (JAI)
UNDER THE GUIDANCE OF

Prof. Dr U.P.Kulkarni (SDMCET) Prof. Vidya Hemadri (SDMCET)


SUBMITTED BY Shruthi I. Lokapur Reshma J. Shetty Rajani B. Paraddi Vishwas P. 8th Semester, B-Div

DEPT. OF COMPUTER SCIENCE & ENGINEERING 2009 2010

Comparative study of image manipulation operations in Java and Matlab

INDEX 1. Abstract 2. Background/purpose 3. Working Environment


3.1. NetBeans installation and working under Windows.

3.2.JAI and JDK installation. 3.3.Java and Java Advanced Imaging. 3.4.Matlab installation and working. 3.5.Functions used in Matlab. 4. Implementation 4.1.JAVA program (execute in netbeans) to find addition and difference of two images. 4.2.Program in matlab to find difference of two images. 4.3.Program in matlab to find addition of two images. 4.4.JAI program (execute in netbeans) to find addition and difference of two images.
5. Comparative Study. 5.1. Sample1(Resolution 1024*768)

5.2.Sample2 (Resolution 162*170) 5.3.Graph for addition module for 100 images. 5.4.Graph for difference module for 100 images.
6. Conclusion.

7. References.

Dept of Computer Science and Engineering SDMCET

Comparative study of image manipulation operations in Java and Matlab

ABSTRACT
Image Processing is analyzing and manipulating images with a computer. Image processing techniques are now applied to virtually all natural sciences and technical disciplines. Generally it involves three steps: 1. Importing an image with an optical scanner or directly through digital photography 2. Manipulate or analyze the image in some way. This stage can include image enhancement and data compression, or the image may be analyzed to find patterns that are not visible by human eye. 3. Output the result. The result might be the image altered in some way or it might be a report based on analysis of the image. A whole chain of processing steps is necessary to analyze and identify objects. The basic procedures for extracting the data of interest and its analysis are the image operations. Image operations include subtraction of two images, addition of two images which are basically used to identify the change and analysis. In this work, a comparative study of the image operations in Java, Matlab and Java Advanced Imaging (JAI) is made. The image operations are performed on different samples in Java, Matlab and JAI, and comparison is made based on the time taken for the operation.

Dept of Computer Science and Engineering SDMCET

Comparative study of image manipulation operations in Java and Matlab 1. BACKGROUND/PURPOSE Visual sensor networks have emerged as an important class of sensor-based distributed intelligent systems, with unique performance, complexity, and quality of service challenges. Visual Sensor Networks consists of a large number of low-power camera nodes. The camera nodes provide information from a monitored site, performing distributed and collaborative processing of their collected data. With the recent advances in imaging technologies, producing small, low-power, low cost image/video capture devices at a large scale may be available in the foreseeable future. However, the large amount of image data produced by the cameras combined with the network's resource constraints require exploring new means for image processing, communication, and sensor management. Meeting these challenges of visual sensor networks requires interdisciplinary approaches, utilizing image processing, communications and networking, and embedded processing. In this proposed work a comparative study of image processing algorithms in JAVA and MATLAB is been done. A sensor node installed with JVM java virtual machine can easily interpret the byte code of image processing algorithms. JVM can be installed on sensor node with very low memory and processing capabilities hence it is advantage to use java API for image processing instead of MATLAB program which requires matlab compiler to be installed on sensor node. Hence in this proposed work comparative study is been made to use java advanced imaging(API) for image processing on sensor node instead of MATLAB.

Dept of Computer Science and Engineering SDMCET

Comparative study of image manipulation operations in Java and Matlab

2. WORKING ENVIRONMENT 2.1. NetBeans installation and working


Installation Steps 1. Go to Netbeans Home Page www.netbeans.org/ 2 Click on the Download NetBeans IDE button select netbeans-6.5 3. Download the file to desktop 4. To start NetBeans double click on the exe file downloaded 5. Follow the setup wizard by clicking Next. You can specify different options, but selecting the default values will work OK. 6. At the NetBeans IDE installation page, do the following: a. Accept the default installation directory for the NetBeans IDE or specify another directory. Note: The installation directory must be empty, and the user profile you are using to run the installer must have read/write permissions for this directory. b. Accept the default JDK installation to use with the NetBeans IDE or select a different installation from the drop-down list. If the installation wizard did not find a compatible JDK installation to use with the NetBeans IDE, your JDK is not installed in the default location. In this case, specify the path to an installed JDK or cancel the current installation, install the required JDK version, and restart this installation. c. Click Next. 7. If the GlassFish application server installation page opens, do the following: a. Accept the default installation directory for the server or specify another installation directory. NOTE: The installation directory you specify must be empty and the user profile you are using to run the installer must have read/write permissions for this directory. b. From the list of compatible JDK installations, choose the JDK you want the application Server to use or click the Browse button to specify another JDK installation. Dept of Computer Science and Engineering SDMCET 5

Comparative study of image manipulation operations in Java and Matlab c. Change the username and password for the default server domain or accept the defaults and click Next. The default username and password are admin and adminadmin. Verify the default port values (HTTP, HTTPS, and Admin) for the server or change them if necessary. Click Next. 8. If you selected the Register... checkbox at the previous step, the Registration page opens in the browser. Click Register. 9 .The netbeans icon appears on the desktop.

2.2.

JAI and JDK installation

Installation Steps: 1. Download the following files from https://jai.dev.java.net/binary-builds.html a. b. c. d. jai-1_1_3-lib-windows-i586-jdk.exe jai-1_1_3-lib-windows-i586-jre.exe jai-1_1_3-lib-windows-i586.jar.zip jai-1_1_3-lib-windows-i586.exe

2. Double click on the jai-1_1_3-lib-windows-i586-jdk.exe file. 3. Accept the license agreement and click next. 4. Select the path for installation. 5. Follow the instructions and select the option to finish the installation. This will install the library files into th following default location without any check for the JDK or the JRE . C:\Program Files\Sun Microsystems\Java Advanced Imaging 1.1.3 6. To install the JRE version, double-click on the jai-1_1_3-lib-windows-i586-jre.exe icon and follow the directions. 7. To install the JDK version, double-click on the jai-1_1_3-lib-windows-i586-jdk.exe icon and follow the directions. NOTE: The executable will try to install JAI within the latest JDK (or JRE) version that it finds. If you need to install and use JAI within another JDK (or JRE) version on disk, please make sure you enter a valid JDK directory when prompted.

Dept of Computer Science and Engineering SDMCET

Comparative study of image manipulation operations in Java and Matlab

2.3. Java and Java Advanced Imaging


The latest release build of Java Advanced Imaging is available at the site

http://java.sun.com/products/java-media/jai/downloads/download-iio-1_0_01.html. After installing Netbeans this package can be incorporated by just downloading from the above mentioned site and installing it. The Java Advanced Imaging API extends the Java platform (including the Java 2D API) by allowing sophisticated, high-performance image processing to be incorporated into Java programs. Java Advanced Imaging is a set of classes which provide imaging functionality beyond that of Java 2D and the Java Foundation classes, although it is compatible with those APIs. The Java Advanced Imaging API implements a set of core image processing capabilities including image tiling, regions of interest, threading and deferred execution. JAI also offers a set of core image processing operators including many common point, area and frequency-domain operators. Image processing algorithms usually require the manipulation of the image data (pixels).In this section the model used by JAI for image data storage and manipulation will be represented, with the corresponding Java/JAI classes. Images in JAI may be multidimensional (i.e. with several values associated to a single (pixel) and may have pixel with either integer or floating point values (although there are restrictions on the types of images which can be stored in disk). Pixels may be packed in different ways or unpacked in the image data array. Different color models can be used. As one may expect, in order to be able to represent a variety of image data, one must deal with a variety of classes. Some of those classes are abstract, concrete subclasses of those behave on more or less the same way PlanarImage: Basic class for image representation in JAI, allows the representation of images with more flexibility than the Java class BufferedImage. Both Buffered-Image and PlanarImage uses several different classes for flexible image data representation, its pixels are stored in an instance of Raster which contains an instance of a concrete subclass of DataBuffer, packed accordingly to the rules described by an instance of a concrete subclass of SampleModel. An instance of PlanarImage also have a ColorModel associated to it, which contains an instance of ColorSpace, which determines how a pixels value can be translated to color values. Figure 1 shows how those classes are used to compose an instance of PlanarImage. A PlanarImage is read-only, i.e. it may be created and its pixels values may be read in several different ways, but there are no methods that allow the modification of pixels values. PlanarImages may have the origin of the image in a position different from the coordinate (0, 0), or even pixel coordinates with negative values. TiledImage: A subclass of PlanarImage, which can be used for reading and writing image data. RenderedOp: Another subclass of PlanarImage, which represents a node in a rendered imaging chain. A rendered imaging chain is a powerful and interesting concept of JAI which allows the processing of an image to be specified as a series of steps (operators and parameters) which are applied to one or more images.

Dept of Computer Science and Engineering SDMCET

Comparative study of image manipulation operations in Java and Matlab

Another interesting concept used in JAI is tiled images. Tiles can be considered as subsets of the images which may be processed independently. Large images thus can be processed in Java/JAI with reasonable performance, even through rendered imaging chains, since there is no need to load the whole image data in memory at once. If the image is tiled, all its tiles must have the same width and height. JAI allows different origins for the pixels and for the tiles on an image, although there are few, if any, practical applications for this. CREATE METHOD IN JAI The JAI API contains several image operators which can be applied with minimum programming. Those operators follow the concept of a rendered imaging chain, where the steps for the image processing are defined but will be carried only when needed (deferred execution). Those operations are specified in a simple way: first an instance of ParameterBlock is created, which is basically a vector of data that will be used for the operation. Create The static method create of the class JAI gets as an argument a name for the operation and the instance of ParameterBlock and returns an instance of RenderedOp which can be manipulated as a PlanarImage. Alternatively one can add the original image in the instance of ParameterBlock as a parameter to its addSource method. Other parameters are added to the ParameterBlock with its add method. Other forms of the method does not require a ParameterBlock and accept other arguments. The call for the JAI.create method is used with different arguments as operator, a file name as string containing the desired image file name (TIFF, JPEG, PNG, etc.). It accepts different operator argument options like fileload for loading a file subtract to find difference of two images addto add two images A list of all operators can be found on the JAI API documentation for the package javax.media.jai.operator. Dept of Computer Science and Engineering SDMCET 8

Comparative study of image manipulation operations in Java and Matlab

2.4.

Matlab Installation
Step 1: Prepare to Install Before you run the installer: Make sure you have your e-mail address and your MathWorks Account password handy. You will need them to log in to your account during installation. If you have multiple licenses associated with your account, know the number of the license you want to install. If you don't have a MathWorks Account, you can create one during installation. However, you must have an Activation Key. An Activation Key is the unique code that identifies a license. It is used to activate the license. The Activation Key also allows licensed end users to associate their MathWorks Account with a license. Ask the administrator of the license for the Activation Key. Exit any existing copies of MATLAB software you have running. Log in to an account with administrator privileges.

Consider disabling virus-checking software and Internet security applications on your system for the duration of the installation process. These applications can slow down the installation process or cause it to appear unresponsive (or to hang).If you do not have an Internet connection during installation, see Connection. If you need to perform a network server or client installation, see Network Installation Procedure.

Step 2: Choose Whether to Install Automatically or Manually Insert the DVD into the DVD drive connected to your system or double-click the installer file you downloaded from the MathWorks Web site. The installer should start automatically. If you are connected to the Internet, the easiest way to install is by selecting the Install automatically using the Internet option. During installation, you log in to your MathWorks Account, select the license you want to install, and follow the prompts on the other installer dialog boxes. Choose to install manually if you do not have an Internet connection. Click Next to proceed with the installation. Step 3: Review the Software License Agreement Review the software license agreement and, if you agree with the terms, select Yes and click Next. After the installation is complete, you can view or print the license agreement using the file license.txt located in the top-level installation folder. Step 4: Log In to Your MathWorks Account Enter the e-mail address and password of your MathWorks Account and click Next. If you do not have a MathWorks Account, select the I need to create a MathWorks Account option and click Next. Step 5: Select the License You Want to Install Select a license from the list of licenses associated with your MathWorks Account and click Next. The list contains the following information about the licenses: Dept of Computer Science and Engineering SDMCET 9

Comparative study of image manipulation operations in Java and Matlab


License number. An optional descriptive text label that can help identify the license. To label a license, go to the License Center at the MathWorks Web site. See the License Center Help for instructions. Information identifying the license option and the activation type. If an activation type has not yet been set on the license, the word "Unset" appears. If you want to install products on a license that is not associated with your MathWorks Account, select the Enter an Activation Key for a license not listed option, enter an Activation Key, and click Next. Specify an Activation Key If there are no licenses associated with your account, or if permission to activate is disabled on the license you selected, you might see the Activation Key dialog box. Enter an Activation Key and click Next. Ask the administrator contact on the license for the Activation Key.

Step 6: Choose the Installation Type In the Installation Type dialog box, specify whether you want to perform a Typical or Custom installation and click Next.

Choose Typical if you have an Individual or Group license and do not need to specify which products you want to install and do not need to access any installation options. Choose Custom if you need to specify which products to install, need access to installation options, or need to install the license manager (network license options only). Specify the name of the folder where you want to install MathWorks products. You can accept the default installation folder or specify the name of a different installation folder. If the folder doesn't exist, the installer creates it. When specifying a folder name, do not specify a name that contains the @ sign, an exclamation point (!), the percent character (%), the plus sign (+), or the dollar sign character ($). The full path of the installation folder must not include a folder named private. If you make a mistake while entering a folder name and want to start over using the default folder name, click Restore Default Folder. To continue with the installation, click Next.

Step 7: Specify the Installation Folder

Step 8: Specify Products to Install (Custom Only) If you are performing a custom installation, you can specify which products you want to install in the Product Selection dialog box. This dialog box lists all the products associated with the license you selected or with the Activation Key you specified. In the dialog box, all the products are preselected for installation. If you do not want to install a particular product, clear the check box next to its name. After selecting the products you want to install, click Next to continue with the installation. After clicking Next, you might receive a message telling you that one or more of the products you selected depend on other products. Consider adjusting your product selection. Dept of Computer Science and Engineering SDMCET 10

Comparative study of image manipulation operations in Java and Matlab Step 9: Specify Installation Options (Custom Only) For Custom installations, you can specify several installation options, including Setting the permissions of all installed files to read only. Determining whether the installer puts shortcuts for MATLAB software in the Start menu and on the desktop. Specifying which files the operating system associates with MATLAB, based on their file extension. For example, if you associate files with the .m file extension with MATLAB, the operating system identifies the type of these files as MATLAB M-file. Step 10: Confirm Your Choices Before it begins copying files to your hard disk, the installer displays a summary of your installation choices. To change a setting, click Back. To proceed with the installation, click Install. Step 11: Complete the Installation When the installation successfully completes, the installer displays the Installation Complete dialog box. In this dialog box, you can choose to activate the software you just installed. You cannot use the software you installed until you activate it. The MathWorks recommends activating immediately after installation. If you logged in to your MathWorks Account during installation, your log-in session continues into the activation process. Click Next to proceed with activation. If you choose to exit the installer without performing activation, clear the Activate MATLAB option and click Finish (the button label changes). You can activate later using the activation application. 2.5.

Functions used in MATLAB


Method:imread -- Reading Image Data

To import an image from any supported graphics image file format, in any of the supported bit depths, use the imread function. This example reads a truecolor image into the MATLAB workspace as the variable RGB. RGB = imread('football.jpg'); If the image file format uses 8-bit pixels, imread stores the data in the workspace as a uint8 array. For file formats that support 16-bit data, such as PNG and TIFF, imread creates a uint16 array. imread uses two variables to store an indexed image in the workspace: one for the image and another for its associated colormap. imread always reads the colormap into a matrix of class double, even though the image array itself may be of class uint8 or uint16. [X,map] = imread('trees.tif'); In these examples, imread infers the file format to use from the contents of the file. You can also specify the file format as an argument to imread. imread supports many common graphics file formats, such as Microsoft Windows Bitmap (BMP), Graphics Interchange Format (GIF), Joint Photographic Experts Group (JPEG), Portable Network Graphics (PNG), and Tagged Image File Format (TIFF) formats. For the latest information concerning the bit depths and/or image formats supported, see imread and imformats. Dept of Computer Science and Engineering SDMCET 11

Comparative study of image manipulation operations in Java and Matlab Method: imadd - Add two images or add constant to image Syntax Z = imadd(X,Y) Description Z = imadd(X,Y) adds each element in array X with the corresponding element in array Y and returns the sum in the corresponding element of the output array Z. X and Y are real, nonsparse numeric arrays with the same size and class, or Y is a scalar double. Z has the same size and class as X, unless X is logical, in which case Z is double. If X and Y are integer arrays, elements in the output that exceed the range of the integer type are truncated, and fractional values are rounded. Examples Add two uint8 arrays. Note the truncation that occurs when the values exceed 255. X = uint8([ 255 0 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]); Z = imadd(X,Y) Z= 255 50 125 94 255 150 Add two images together and specify an output class. I = imread('rice.png'); J = imread('cameraman.tif'); K = imadd(I,J,'uint16'); imshow(K,[]) Add a constant to an image. I = imread('rice.png'); J = imadd(I,50); subplot(1,2,1), imshow(I) subplot(1,2,2), imshow(J) Method: imabsdiff - Absolute difference of two images Syntax Z = imabsdiff(X,Y) Description Z = imabsdiff(X,Y) subtracts each element in array Y from the corresponding element in array X and returns the absolute difference in the corresponding element of the output array Z. X and Y are real, nonsparse numeric arrays with the same class and size. Z has the same class and size as X and Y. If X and Y are integer arrays, elements in the output that exceed the range of the integer type are truncated. Dept of Computer Science and Engineering SDMCET 12

Comparative study of image manipulation operations in Java and Matlab If X and Y are double arrays, you can use the expression abs(X-Y) instead of this function. Examples Calculate the absolute difference between two uint8 arrays. Note that the absolute value prevents negative values from being rounded to zero in the result, as they are with imsubtract. X = uint8([ 255 10 75; 44 225 100]); Y = uint8([ 50 50 50; 50 50 50 ]); Z = imabsdiff(X,Y) Z= 205 40 25 6 175 50 Display the absolute difference between a filtered image and the original. I = imread('cameraman.tif'); J = uint8(filter2(fspecial('gaussian'), I)); K = imabsdiff(I,J); imshow(K,[]) % [] = scale data automatically

3.

IMPLEMENTATION

3.1.

JAVA code (run in netbeans) to find addition and difference of two images

package windowimageconstructor; import java.awt.*; import java.awt.event.*; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import java.awt.image.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Date; import javax.imageio.ImageIO; import javax.swing.JFileChooser; // create Frame Window. public class FrameImage extends Frame { String msg="RSR" ; Image myImage1,myImage3; BufferedImage myImage2; int iw,ih;

Dept of Computer Science and Engineering SDMCET

13

Comparative study of image manipulation operations in Java and Matlab


//Conctructor public FrameImage() { //Event Registrations addWindowListener(new MyWindowAdapter()) }// end of constructor public void saveImage( BufferedImage bi) { // Save the filtered image in the selected format. // The selected item will be the name of the format to use String format = "jpg"; File saveFile = new File("SavedImage."+format); JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(saveFile); int rval = chooser.showSaveDialog(this); if (rval == JFileChooser.APPROVE_OPTION) { saveFile = chooser.getSelectedFile(); /* Write the filtered image in the selected format, * to the file chosen by the user. */ try { ImageIO.write(bi, format, saveFile); } catch (IOException ex) { } } }// saveImage routine ends public void buildImage3() { // Image object local to this module, used temporarily Image tempImage1=null, tempImage2 = null; URL u1=null,u2=null; Graphics big = null; int iw1 = 0,iw2=0,ih1=0,ih2=0; try { // original data file TEST-6-1.jpg //Picture005.jpg and Picture006.jpg u1 = new URL("File:" + "D:/ACADEMICS/7THSEM/PROJECT/DATABASE/pics/a1.jpg"); u2 = new URL("File:" + "D:/ACADEMICS/7THSEM/PROJECT/DATABASE/pics/a2.jpg"); } catch (MalformedURLException ex) { ex.printStackTrace(); System.out.println(" TEST-1: BuildImage3:Failed to Create URLs"); } // Image Comparision

Dept of Computer Science and Engineering SDMCET

14

Comparative study of image manipulation operations in Java and Matlab


try { tempImage1 = ImageIO.read(u1); tempImage2 = ImageIO.read(u2); iw1 = tempImage1.getWidth(null); ih1 = tempImage1.getHeight(null); iw2 = tempImage2.getWidth(null); ih2 = tempImage2.getHeight(null); catch (IOException e) System.out.println("TEST-2: Image could not be read"); System.exit(1); } //new logic // grab pixels from image, construct array of pixels //and then again construct image from array of pixels. int pixels1[] = new int [iw1*ih1]; PixelGrabber pg1 = new PixelGrabber(tempImage1,0,0,iw1,ih1,pixels1,0,iw1); int pixels2[] = new int [iw2*ih2]; PixelGrabber pg2 = new PixelGrabber(tempImage2,0,0,iw2,ih2,pixels2,0,iw2); try { pg1.grabPixels(); pg2.grabPixels(); } catch (InterruptedException ex) { ex.printStackTrace(); System.out.println(" TEST-3: BuildImage2:Failed to grab pixels"); } int pixels3[] = new int [iw1*ih1]; int pixels4[] = new int [iw1*ih1]; int pixels5[]= new int[iw1*ih1]; int k; k= iw1 * ih1; System.out.println(" K Value is :" + Integer.toString(k)); int k1,k2,k3,r1,r2,g1,g2,b1,b2,r3,g3,b3; for (int var=0; var<k; var++ ) { // get RGB Values of Image- 1 r1= (pixels1[var]>>16) & 0xff; g1= (pixels1[var]>>8) & 0xff; b1= (pixels1[var]) & 0xff; //Image-1Compute Brightness of pixel using NTSC color-to-brightness conversion factor k1= (int) (.56 * g1 + .33 *r1 + .11 *b1);

} {

Dept of Computer Science and Engineering SDMCET

15

Comparative study of image manipulation operations in Java and Matlab


// get RGB Values of Image- 2 r2= (pixels2[var]>>16) & 0xff; g2= (pixels2[var]>>8) & 0xff; b2= (pixels2[var]) & 0xff; //Image-2 Compute Brightness of pixel using NTSC color-to-brightness conversion factor k2= (int) (.56 * g2 + .33 *r2 + .11 *b2); //System.out.println("TEST-var" + Integer.toString(k1)+" :"+Integer.toString(k2)+"\n"); //compare brightness; 3 is adhoc number if ( Math.abs(k1 -k2) <= 3) { // if image 1 and 2 are almost same the //result is White color pixels3[var]=(0<<24) | (0<<16) | (0<<8) | 0; //System.out.println("FUN"+Integer.toString(pixels3[var])); } else { // if image 1 is brighter than image 2 pixels3[var]=pixels1[var]; pixels5[var]=(0<<24) | (0<<16) | (0<<8) | 0; } // constructing original image // now compute for difference image r3= (pixels3[var]>>16) & 0xff; g3= (pixels3[var]>>8) & 0xff; b3= (pixels3[var]) & 0xff; k3= (int) (.56 * g3 + .33 *r3 + .11 *b3); // compare with image-2 if (pixels3[var] == 0 ) { pixels4[var]= pixels2[var]; } else { pixels4[var]= pixels3[var]; } }// for loop // pixels5=array_intersect(pixels1,pixels2); myImage3 = createImage(new MemoryImageSource(iw1,ih1,pixels4,0,iw1)); // save Image // Image Comparision

public void buildImage1() { // test-1 Dimension d = getSize(); int iw1=d.width;

Dept of Computer Science and Engineering SDMCET

16

Comparative study of image manipulation operations in Java and Matlab


int int int for { ih1=d.height; pixels[] = new int [iw1*ih1]; i=0; (int y =0; y<ih1;y++) for (int x =0; x<iw1;x++) { int r = (x^y) &0xff; int gg = (x*2^y*4)&0xff; int b= (x*4^y*4)&0xff; // 0 for BLACK // 255 for white if (y <=50) { r=200; gg=200; b=200; } pixels[i++]=(255<<24)| (r <<16)| (gg<<8)| b; } } myImage1 = createImage(new MemoryImageSource(iw1,ih1,pixels,0,iw1)); myImage3=myImage1; //test-1 ends }// end of buildImage-1 public void buildImage2() { // Image object local to this module, used temporarily BufferedImage tempImage = null; URL u=null; Graphics big = null; try { u = new URL("File:" + "D:/Picture005.jpg"); } catch (MalformedURLException ex) { ex.printStackTrace(); System.out.println(" TEST-1: BuildImage2:Failed to Create URL"); } // new logic try { tempImage = ImageIO.read(u); iw = tempImage.getWidth(null); ih = tempImage.getHeight(null); //now image can be displayed directly myImage3=tempImage; } { catch (IOException e) System.out.println("TEST-2: Image could not be read");

Dept of Computer Science and Engineering SDMCET

17

Comparative study of image manipulation operations in Java and Matlab


System.exit(1);

//new logic //grab pixels from image, construct array of pixels and then // again construct image from array of pixels. iw=tempImage.getWidth(null); ih=tempImage.getHeight(null); int pixels[] = new int [iw*ih]; PixelGrabber pg = new PixelGrabber(tempImage,0,0,iw,ih,pixels,0,iw); try { pg.grabPixels(); } catch (InterruptedException ex) { ex.printStackTrace(); System.out.println(" TEST-3: BuildImage2:Failed to grab pixels"); } myImage3 = createImage(new MemoryImageSource(iw,ih,pixels,0,iw)); //Buffered Image only and not Image type saveImage(tempImage); }// end of buildImage-2 public void paint(Graphics g) { g.drawString(msg,40,40); g.drawImage(myImage3,50,50,this); } void doMyJob() { Date d1 = new Date(); long t1,t2,t3; t1= d1.getTime(); System.out.println(" Start TIME buildImage3(); Date d2 = new Date(); t2=d2.getTime(); System.out.println(" End TIME t3 = t2-t1; in millisec --> "+t1);

in millisec --> " + t2);

System.out.println(" TIME TAKEN in millisec --> " + t3); repaint();

// Main public static void main(String args[]) { FrameImage fm = new FrameImage(); fm.setTitle("ImageA"); fm.setSize(new Dimension(300,200)); fm.setVisible(true); // Image Related ActivityCall to routine

Dept of Computer Science and Engineering SDMCET

18

Comparative study of image manipulation operations in Java and Matlab


fm.doMyJob(); } }// end of class- FrameImage // Window Event Handler class MyWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { System.exit(0); } }

3.2.

Implementing a program in matlab to find addition of two images.


I = imread('TEST-6-3.JPG'); J = imread('TEST-6-2.JPG'); K = imadd(I,J,'uint16'); figure,imshow(I); title('image1'); figure,imshow(J); title('image2'); figure,imshow(K,[]); title('added image');

3.3.

Implementing a program in Matlab to find difference of two images :


[N,map] = imread('TEST-6-2.JPG'); imshow(N,map);title('Image-1'); [O,map] = imread('TEST-6-3.JPG'); figure,imshow(O,map);title('Image-2'); B = imabsdiff(N,O); figure,imshow(B,map); title('diff -image');

3.4.

/* * Created on Feb, 05 2010 * @author Team B4 */ package operators; import import import import import import import import

JAI program (execute in netbeans) to find addition and difference of two images

java.awt.event.MouseEvent; java.awt.event.MouseMotionListener; java.awt.image.DataBuffer; java.awt.image.IndexColorModel; java.awt.image.RenderedImage; javax.media.jai.iterator.RandomIter; javax.media.jai.iterator.RandomIterFactory; com.sun.media.jai.widget.DisplayJAI;

/** * This class shows how one can extend the DisplayJAI class. We'll override the

Dept of Computer Science and Engineering SDMCET

19

Comparative study of image manipulation operations in Java and Matlab


* mouseMoved method of DisplayJAI so when the mouse is moved, some information * about the pixel beneath the mouse will be stored (but not displayed). */ public class DisplayJAIWithPixelInfo extends DisplayJAI implements MouseMotionListener { private StringBuffer pixelInfo; // the pixel information (formatted in a StringBuffer). private double[] dpixel; // the pixel information as an array of doubles. private int[] ipixel; // the pixel information as an array of integers. private boolean isDoubleType; // indicates which of the above arrays we will use. private RandomIter readIterator; // a RandomIter that allow us to get the data // on a single pixel. private boolean isIndexed; // true if the image has a indexed color model. private short[][] lutData; // will contain the look-up table data if isIndexed is true. protected int width,height; // the dimensions of the image /** * The constructor of the class, which creates the arrays and instances needed * to obtain the image data and registers the class to listen to mouse motion * events. * @param image a RenderedImage for display */ public DisplayJAIWithPixelInfo(RenderedImage image) { super(image); // calls the constructor for DisplayJAI. readIterator = RandomIterFactory.create(image, null); // creates the iterator. // Get some data about the image width = image.getWidth(); height = image.getHeight(); int dataType = image.getSampleModel().getDataType(); // gets the data type switch(dataType) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: case DataBuffer.TYPE_INT: isDoubleType = false; break; case DataBuffer.TYPE_FLOAT: case DataBuffer.TYPE_DOUBLE: isDoubleType = true; break; } // Depending on the image data type, allocate the double or the int array.

Dept of Computer Science and Engineering SDMCET

20

Comparative study of image manipulation operations in Java and Matlab


if (isDoubleType) dpixel = new double[image.getSampleModel().getNumBands()]; else ipixel = new int[image.getSampleModel().getNumBands()]; // Is the image color model indexed ? isIndexed = (image.getColorModel() instanceof IndexColorModel); if (isIndexed) { // Retrieve the index color model of the image. IndexColorModel icm = (IndexColorModel)image.getColorModel(); // Get the number of elements in each band of the colormap. int mapSize = icm.getMapSize(); // Allocate an array for the lookup table data. byte[][] templutData = new byte[3][mapSize]; // Load the lookup table data from the IndexColorModel. icm.getReds(templutData[0]); icm.getGreens(templutData[1]); icm.getBlues(templutData[2]); // Load the lookup table data into a short array to avoid negative numbers. lutData = new short[3][mapSize]; for(int entry=0;entry<mapSize;entry++) { lutData[0][entry] = templutData[0][entry] > 0 ? templutData[0][entry] : (short)(templutData[0][entry] +256); lutData[1][entry] = templutData[1][entry] > 0 ? templutData[1][entry] : (short)(templutData[1][entry] +256); lutData[2][entry] = templutData[2][entry] > 0 ? templutData[2][entry] : (short)(templutData[2][entry] +256); } } // end if indexed // Registers the mouse motion listener. addMouseMotionListener(this); // Create the StringBuffer instance for the pixel information. pixelInfo = new StringBuffer(50); } /** * This method will be called when the mouse is moved over the image * being displayed. @param me the mouse event that caused the execution * of this method. */ public void mouseMoved(MouseEvent me) { pixelInfo.setLength(0); // clear the StringBuffer int x = me.getX(); int y = me.getY(); if ((x >= width) || (y >= height)) { pixelInfo.append("No data!"); return; }

Dept of Computer Science and Engineering SDMCET

21

Comparative study of image manipulation operations in Java and Matlab


if (isDoubleType) // process the pixel as an array of double values { pixelInfo.append("(floating-point data) "); readIterator.getPixel(me.getX(),me.getY(),dpixel); // read the pixel for(int b=0;b<dpixel.length;b++) pixelInfo.append(dpixel[b]+","); // append to the StringBuffer pixelInfo = pixelInfo.deleteCharAt(pixelInfo.length()-1); // erase last comma } else // pixel type is not floating point, will be processed as integers. { if (isIndexed) // if color model is indexed { pixelInfo.append("(integer data with colormap) "); readIterator.getPixel(me.getX(),me.getY(),ipixel); // read the pixel // Assume ipixel.length = 1 pixelInfo.append("Index: "+ipixel[0]); // Add also the RGB entry from the LUT. pixelInfo.append(" RGB:"+lutData[0][ipixel[0]]+","+ lutData[1][ipixel[0]]+","+ lutData[2][ipixel[0]]); } else // pixels are of integer type, but not indexed { pixelInfo.append("(integer data) "); readIterator.getPixel(me.getX(),me.getY(),ipixel); // read the pixel for(int b=0;b<ipixel.length;b++) pixelInfo.append(ipixel[b]+","); // append to the StringBuffer pixelInfo = pixelInfo.deleteCharAt(pixelInfo.length()-1); // erase last comma } } // pixel is integer type } // end of method mouseMoved /** * This method allows external classes access to the pixel info which * was obtained in the mouseMoved method.@return the pixel information, * formatted as a string */ public String getPixelInfo() { return pixelInfo.toString(); } } // end class /* * Created on Feb, 05 2010 * @author Team B4 */ package operators;

Dept of Computer Science and Engineering SDMCET

22

Comparative study of image manipulation operations in Java and Matlab


import import import import import import java.awt.GridLayout; java.awt.event.AdjustmentEvent; java.awt.event.AdjustmentListener; java.awt.image.RenderedImage; javax.swing.JPanel; javax.swing.JScrollPane;

/** * This class represents a JPanel which contains two scrollable * instances of DisplayJAIWithPixelInfo. The scrolling bars of both * images are synchronized so scrolling one image will automatically * scroll the other. */ public class DisplayTwoSynchronizedImages extends JPanel implements AdjustmentListener { /** The DisplayJAIWithPixelInfo for the first image. */ protected DisplayJAIWithPixelInfo dj1; /** The DisplayJAIWithPixelInfo for the second image. */ protected DisplayJAIWithPixelInfo dj2; /** The JScrollPane which will contain the first of the images */ protected JScrollPane jsp1; /** The JScrollPane which will contain the second of the images */ protected JScrollPane jsp2; /** * Creates an instance of this class, setting the components' layout, * creating two instances of DisplayJAIWithPixelInfo for the two images * and creating/registering event handlers for the scroll bars. * @param im1 the first image (left side) * @param im2 the second image (right side) */ public DisplayTwoSynchronizedImages(RenderedImage im1,RenderedImage im2) { super(); setLayout(new GridLayout(1,2)); dj1 = new DisplayJAIWithPixelInfo(im1); // Instances of DisplayJAI for the dj2 = new DisplayJAIWithPixelInfo(im2); // two images jsp1 = new JScrollPane(dj1); // JScrollPanes for the both jsp2 = new JScrollPane(dj2); // instances of DisplayJAI add(jsp1); add(jsp2); // Retrieve the scroll bars of the images and registers adjustment // listeners to them. // Horizontal scroll bar of the first image. jsp1.getHorizontalScrollBar().addAdjustmentListener(this); // Vertical scroll bar of the first image. jsp1.getVerticalScrollBar().addAdjustmentListener(this); // Horizontal scroll bar of the second image. jsp2.getHorizontalScrollBar().addAdjustmentListener(this); // Vertical scroll bar of the second image. jsp2.getVerticalScrollBar().addAdjustmentListener(this); }

Dept of Computer Science and Engineering SDMCET

23

Comparative study of image manipulation operations in Java and Matlab

/** * This method changes the first image to be displayed. * @param newImage the new first image. */ public void setImage1(RenderedImage newimage) { dj1.set(newimage); repaint(); } /** * This method changes the second image to be displayed. * @param newImage the new second image. */ public void setImage2(RenderedImage newimage) { dj2.set(newimage); repaint(); } /** * This method returns the first image. * @return the first image. */ public RenderedImage getImage1() { } /** * This method returns the second image. * @return the second image. */ public RenderedImage getImage2() { return dj2.getSource(); } /** * This method returns the first DisplayJAIWithPixelInfo component. * @return the first DisplayJAIWithPixelInfo component. */ public DisplayJAIWithPixelInfo getDisplayJAIComponent1() { return dj1; } /** * This method returns the second DisplayJAIWithPixelInfo component. * @return the second DisplayJAIWithPixelInfo component. */ public DisplayJAIWithPixelInfo getDisplayJAIComponent2() return dj1.getSource();

Dept of Computer Science and Engineering SDMCET

24

Comparative study of image manipulation operations in Java and Matlab


{ } /** * This method will be called when any of the scroll bars of the * instances of DisplayJAIWithPixelInfo are changed. The method will * adjust scroll bar of the other DisplayJAIWithPixelInfo as needed. * @param e the AdjustmentEvent that ocurred (meaning that one of the * scroll bars position has changed. */ public void adjustmentValueChanged(AdjustmentEvent e) { // If the horizontal bar of the first image was changed... if (e.getSource() == jsp1.getHorizontalScrollBar()) { // We change position of the horizontal bar of the second image. jsp2.getHorizontalScrollBar().setValue(e.getValue()); } // If the vertical bar of the first image was changed... if (e.getSource() == jsp1.getVerticalScrollBar()) { // We change the position of the vertical bar of the second image. jsp2.getVerticalScrollBar().setValue(e.getValue()); } // If the horizontal bar of the second image was changed... if (e.getSource() == jsp2.getHorizontalScrollBar()) { // We change position of the horizontal bar of the first image. jsp1.getHorizontalScrollBar().setValue(e.getValue()); } // If the vertical bar of the second image was changed... if (e.getSource() == jsp2.getVerticalScrollBar()) { // We change the position of the vertical bar of the first image. jsp1.getVerticalScrollBar().setValue(e.getValue()); } } // end adjustmentValueChanged } // end class /* * Created on Feb, 05 2010 * @author Team B4 */ package operators; import java.awt.GridLayout; import java.awt.event.AdjustmentEvent; import java.awt.image.RenderedImage; import javax.swing.JScrollPane; /** * This class represents a Panel which contains three instances of * DisplayJAIWithPixelInfo. The scrolling bars of all images are

return dj2;

Dept of Computer Science and Engineering SDMCET

25

Comparative study of image manipulation operations in Java and Matlab


* synchronized so scrolling one image will automatically scroll * others.*/ public class DisplayThreeSynchronizedImages extends DisplayTwoSynchronizedImages { /** The DisplayJAIWithPixelInfor for the third image. */ protected DisplayJAIWithPixelInfo dj3; /** The JScrollPane which will contain the third image */ protected JScrollPane jsp3; /** * Constructs an instance of this class, setting the components' * layout, creating three instances of DisplayJAI for the three images * and creating/registering event handlers for the scroll bars. * @param im1 the first image (left side) * @param im2 the second image (middle) * @param im3 the third image (right side) */ public DisplayThreeSynchronizedImages(RenderedImage im1,RenderedImage im2,RenderedImage im3) { super(im1,im2); setLayout(new GridLayout(1,3)); // Instance of DisplayJAIWithPixelInfo for the third image. dj3 = new DisplayJAIWithPixelInfo(im3); jsp3 = new JScrollPane(dj3); // JScrollPane for that instance. add(jsp3); // Retrieve the scroll bars of the images and registers adjustment // listeners to them. // Horizontal scroll bar of the third image. jsp3.getHorizontalScrollBar().addAdjustmentListener(this); // Vertical scroll bar of the third image. jsp3.getVerticalScrollBar().addAdjustmentListener(this); } /** * This method changes the image displayed in the right DisplayJAI * instance. @param newImage the new image */ public void setImage3(RenderedImage newimage) { dj3.set(newimage); repaint(); } /** * This method returns the third image. * @return the third image. */ public RenderedImage getImage3() { return dj3.getSource();

Dept of Computer Science and Engineering SDMCET

26

Comparative study of image manipulation operations in Java and Matlab


} /** * This method returns the third DisplayJAI component. * @return the third DisplayJAI component. */ public DisplayJAIWithPixelInfo getDisplayJAIComponent3() { return dj3; } /** * This method will be called when any of the scroll bars of the * instances of DisplayJAI are changed. The method will adjust the * scroll bar of the other DisplayJAI as needed. @param e the * AdjustmentEvent that ocurred (meaning that one of the scroll * bars position has changed. */ public void adjustmentValueChanged(AdjustmentEvent e) { // If the horizontal bar of the first image was changed... if (e.getSource() == jsp1.getHorizontalScrollBar()) { // We change the position of the horizontal bar of the 2nd and 3rd images. jsp2.getHorizontalScrollBar().setValue(e.getValue()); jsp3.getHorizontalScrollBar().setValue(e.getValue()); } // If the vertical bar of the first image was changed... if (e.getSource() == jsp1.getVerticalScrollBar()) { // We change the position of the vertical bar of the 2nd and 3rd images. jsp2.getVerticalScrollBar().setValue(e.getValue()); jsp3.getVerticalScrollBar().setValue(e.getValue()); } // If the horizontal bar of the second image was changed... if (e.getSource() == jsp2.getHorizontalScrollBar()) { // We change the position of the horizontal bar of the 1st and 3rd images. jsp1.getHorizontalScrollBar().setValue(e.getValue()); jsp3.getHorizontalScrollBar().setValue(e.getValue()); } // If the vertical bar of the second image was changed... if (e.getSource() == jsp2.getVerticalScrollBar()) { // We change the position of the vertical bar of the 1st and 3rd images. jsp1.getVerticalScrollBar().setValue(e.getValue()); jsp3.getVerticalScrollBar().setValue(e.getValue()); } // If the horizontal bar of the third image was changed...

Dept of Computer Science and Engineering SDMCET

27

Comparative study of image manipulation operations in Java and Matlab


if (e.getSource() == jsp3.getHorizontalScrollBar()) { // We change the position of the horizontal bar of the 1st and 2nd images. jsp1.getHorizontalScrollBar().setValue(e.getValue()); jsp2.getHorizontalScrollBar().setValue(e.getValue()); } // If the vertical bar of the third image was changed... if (e.getSource() == jsp3.getVerticalScrollBar()) { // We change the position of the vertical bar of the 1st and 2nd images. jsp1.getVerticalScrollBar().setValue(e.getValue()); jsp2.getVerticalScrollBar().setValue(e.getValue()); } } // end adjustmentValueChanged } // end class /* * Created on Feb, 05 2010 * @author Team B4 */ package operators; import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.renderable.ParameterBlock; import javax.media.jai.JAI; import javax.media.jai.PlanarImage; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; /** * This class demonstrates the use of several arithmetic operators using two images to generate a third one. The three images will be shown, side by side. */ public class ArithmeticOps extends JFrame implements ActionListener { // Four buttons, one for each operation. private JButton add,subtract,multiply,divide; // Three instances of PlanarImage: two input and one output images. private PlanarImage input1,input2,output; // Two strings to store the names of the images. private String im1,im2; // One instance of DisplayThreeSynchronizedImages to display // the three images. private DisplayThreeSynchronizedImages imagesPanel; /** * Creates the user interface for this JFrame.

Dept of Computer Science and Engineering SDMCET

28

Comparative study of image manipulation operations in Java and Matlab


* @param im1 the first input image file name. * @param im2 the second input image file name.

*/

public ArithmeticOps(String im1,String im2) { super(); // Store the images' names. this.im1 = im1; this.im2 = im2; // Read the input images. input1 = JAI.create("fileload", im1); input2 = JAI.create("fileload", im2); // Create a temporary output image so we can show something before // clicking on the buttons. output = createConstFrom(input1); // Let's create the graphical user interface. First we create a JPanel // with the operations' buttons. JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(1,4)); // Let's create the buttons, register their ActionListeners and add them // to the JPanel. add = new JButton("Add"); add.addActionListener(this); buttonPanel.add(add); subtract = new JButton("Subtract"); subtract.addActionListener(this); buttonPanel.add(subtract); multiply = new JButton("Multiply"); multiply.addActionListener(this); buttonPanel.add(multiply); divide = new JButton("Divide"); divide.addActionListener(this); buttonPanel.add(divide); // We'll create an instance of DisplayThreeSynchronizedImages to //display the input and output images. imagesPanel = new DisplayThreeSynchronizedImages(input1,input2,output); // Get the Container for this JFrame. Container cp = getContentPane(); cp.setLayout(new BorderLayout()); // Add the panel with the buttons and the panel with the images to //the container. cp.add(imagesPanel,BorderLayout.CENTER); cp.add(buttonPanel,BorderLayout.SOUTH); // Set the closing operation so the application is finished. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); // adjust the frame size using preferred dimensions. setVisible(true); // show the frame.. } /**

Dept of Computer Science and Engineering SDMCET

29

Comparative study of image manipulation operations in Java and Matlab


* * * * * Create an image with the same dimensions as the image passed as an argument but with a constant value. @param ip an input PlanarImage @return an output PlanarImage with the same dimensions and bands as the input one. */

public PlanarImage createConstFrom(PlanarImage pi) { // Create an array of Bytes with length equal to the number of bands // of the input image. Byte[] bandValues = new Byte[pi.getNumBands()]; // Fill the array with a constant value. for(int band=0;band<pi.getNumBands();band++) bandValues[band] = new Byte((byte)127); // Create a ParameterBlock with the parameters for the creation of //the output image. ParameterBlock pb = new ParameterBlock(); pb.add((float)pi.getWidth()); // the input image dimensions pb.add((float)pi.getHeight()); pb.add(bandValues); // Create and return the constant image. return JAI.create("constant", pb, null); } /** * This method will be called when an action event occur (such as the ones generated when an user clicks on the application's buttons). @param e the action event.*/ public void actionPerformed(ActionEvent e) { // Create a ParameterBlock for the images' operation. ParameterBlock pb = new ParameterBlock(); // Add the input images to the ParameterBlock. pb.addSource(input1); pb.addSource(input2); // Run the operation (depending on the source of the event, i.e. the // button that was clicked) if (e.getSource() == add) { setTitle("Sum of images "+im1+" and "+im2); output = JAI.create("add", pb); } else if (e.getSource() == subtract) { setTitle("Image "+im1+" minus image "+im2); output = JAI.create("subtract", pb); } else if (e.getSource() == multiply) { setTitle("Multiplication of images "+im1+" and "+im2); output = JAI.create("multiply", pb); }

Dept of Computer Science and Engineering SDMCET

30

Comparative study of image manipulation operations in Java and Matlab


else if (e.getSource() == divide) { setTitle("Sum of images "+im1+" and "+im2); output = JAI.create("divide", pb); } // Change the third image on the DisplayThreeSynchronizedImages. imagesPanel.setImage3(output); } } /** * Authors: Team B4 * Date: 5th Feb,2010 * Time: 4.45 PM * Implements Addition, Subtraction, Multiplication and Division of two images using Java Advanced Imaging APIs */ package operators; public class Main { /** * The application entry point. */ public static void main(String[] args) { /* We need two arguments: the input images' names. (May be passed as command line arguments if (args.length != 2) { System.err.println("Usage: java operators.ArithmeticOps image1 image2"); System.exit(0); }*/ new ArithmeticOps("C:/MyWorks/a1.jpg","C:/MyWorks/a2.jpg"); } }

4. STATISTICS (Time taken for image addition and subtraction in JAI,

MATLAB and JAVA)

Dept of Computer Science and Engineering SDMCET

31

Comparative study of image manipulation operations in Java and Matlab


JAIADDITIO N (secs) MATLA BADDITI ON (secs)

FIRST IMAGE

SECOND IMAGE

JAISUBTRACTI ON (secs)

MATLABSUBTRACTI ON (secs)

JAVAADDITION (secs)

JAVASUBTRACTI ON (secs)

Dept of Computer Science and Engineering SDMCET

32

Comparative study of image manipulation operations in Java and Matlab


0 a1 a1 a2 a3 abstract_ 15 abstract_ 15 abstract_ 17 abstract_ 22 abstract_ 28 abstract_ 32 abstract_ 36 art2 abstract_ 25 aud1 a1 ast abstract_ 37 shark1 snow2 snow2 space2 shut1 sun1 space6 abstract_ 27 a2 a3 a4 a4 abstract_ 17 abstract_ 22 abstract_ 23 abstract_ 25 abstract_ 29 abstract_ 34 abstract_ 37 art3 art6 aud2 art9 ast2 aud1 snow1 snow1 space2 space3 shut2 sun2 space7 art6 0.319 0.063 0.047 0.078 0.047 0.063 0.063 0.062 0.063 0.046 0.062 0.063 0.062 0.047 0.047 0.063 0.062 0.047 0.047 0.047 0.063 0.062 0.063 0.047 0.061 0.3 0.042 0.016 0.032 0.015 0.015 0.015 0.015 0.015 0.016 0.015 0.016 0.015 0.016 0.016 0.015 0.015 0.015 0.015 0.016 0.016 0.016 0.016 0.015 0.003 .59 0 .58 0 .58 0 .60 0 .61 0 .61 0 .61 0 .60 0 .58 0 .62 0 .58 0 .57 0 .58 0 .60 0 .58 0 .56 0 .59 0 .58 0 .59 0 .58 0 .60 0 .58 0 .59 0 .57 0 .48 0.377361 1.03 0.997 0.359212 0.873 0.921 0.388271 0.826 0.89 0.362172 0.904 0.873 0.347774 0.937 0.983 0.34921 0.905 0.874 0.34214 0.936 0.969 0.370974 0.889 0.92 0.318654 0.891 0.844 0.306164 0.859 0.874 0.322833 1.048 1.013 0.388113 0.904 0.905 0.36095 1.076 1.25 0.317874 0.967 0.982 0.337294 0.952 0.875 0.410009 0.904 0.935 0.302898 0.873 0.858 0.323543 0.982 0.997 0.384761 0.89 0.872 0.380579 0.875 0.872 0.488386 0.937 0.906 0.336536 0.857 0.889 0.380018 0.92 0.862 0.373631 0.844 0.888 0.311454 0.827 0.859

Dept of Computer Science and Engineering SDMCET

33

Comparative study of image manipulation operations in Java and Matlab


0 images lion fire1 bmw3 cars2 dol1 dub1 clouds1 f1 ferr1 buttr1 buttr1 buttr2 game1 game1 game2 cars2 cars3 dol3 ferr1 horse1 horse4 horse4 fl1 fl1 images1 lion1 fire2 build cars3 dol2 dub2 clouds2 f1-1 ferr2 buttr2 buttr3 buttr3 game2 game3 game3 cars4 cars5 dub1 fire1 horse2 horse5 horse6 fl2 fl3 0.081 0.056 0.061 0.06 0.058 0.068 0.069 0.077 0.06 0.06 0.055 0.067 0.059 0.061 0.064 0.06 0.065 0.06 0.055 0.056 0.055 0.05 0.055 0.055 0.054 0.003 0.002 0.005 0.005 0.003 0.004 0.003 0.003 0.01 0.005 0.005 0.003 0.004 0.003 0.003 0.008 0.003 0.005 0.005 0.0045 0.005 0.005 0.005 0.005 0.005 .25 0 .59 0 .57 0 .58 0 .57 0 .62 0 .70 0 .57 0 .58 0 .66 0 .59 0 .57 0 .59 0 .68 0 .69 0 .66 0 .55 0 .59 0 .58 0 .61 0 .59 0 .63 0 .62 0 .61 0 .58 0.33099 0.967 0.92 0.344271 0.875 0.858 0.343377 0.922 0.905 0.404947 0.935 0.951 0.476614 0.92 0.955 0.325451 0.982 0.933 0.356435 0.889 0.905 0.315243 0.89 0.889 0.3115 0.904 0.935 0.35418 1.683 1.528 0.384375 1.732 1.745 0.445922 1.684 1.639 0.318801 1.044 0.903 0.331263 0.951 1 0.379384 0.967 0.984 0.436218 0.969 0.967 0.364865 0.889 0.859 0.381838 0.858 0.905 0.350293 0.982 0.999 0.393574 0.872 0.905 0.347389 0.858 0.811 0.467446 0.81 0.89 0.363504 0.873 0.89 0.361386 0.904 0.888 0.111671 0.203 0.219

Dept of Computer Science and Engineering SDMCET

34

Comparative study of image manipulation operations in Java and Matlab


0 fl2 fl5 fl3 fire2 clouds1 mac lion1 kang1 mount1 mount1 mount3 mount3 moto3 lea lion3 moto3 mun1 mus4 mase mas paris1 mun2 mount4 nature15 porsh fl4 fl6 fl6 fl6 dub2 lion1 lion2 kang2 mount2 mount3 mount4 mase mount1 mase lot3 mus3 mun2 mus5 lion mel paris2 mus1 nature20 nature16 mac 0.06 0.06 0.061 0.055 0.05 0.055 0.055 0.055 0.053 0.065 0.055 0.055 0.06 0.06 0.05 0.055 0.063 0.062 0.047 0.063 0.046 0.047 0.063 0.062 0.063 0.005 0.005 0.004 0.01 0.005 0.005 0.005 0.006 0.005 0.005 0.006 0.005 0.005 0.005 0.001 0.003 0.016 0.004 0.015 0.016 0.016 0.015 0.016 0.016 0.016 .61 0 .70 0 .65 1 .73 0 .62 0 .60 0 .70 0 .65 0 .60 0 .64 0 .64 0 .59 0 .56 0 .56 0 .61 0 .55 0 .61 0 .54 0 .59 0 .58 0 .63 0 .61 0 .60 0 .59 0 .55 0.34975 0.905 0.858 0.33495 0.906 0.855 0.312966 0.935 0.953 0.387947 0.921 0.984 0.412229 0.937 0.921 0.381721 0.968 0.921 0.299602 0.935 0.889 0.302466 0.951 0.966 0.398685 0.921 0.905 0.38 0.934 0.967 0.341578 0.92 0.904 0.442517 0.922 0.904 0.329938 0.812 0.888 0.376786 0.921 0.935 0.345344 0.937 0.966 0.379219 0.937 0.921 0.389956 0.983 0.965 0.409368 0.936 0.949 0.361604 0.935 0.984 0.361295 0.936 0.889 0.324587 0.92 0.889 0.340053 0.904 0.845 0.344597 0.952 0.919 0.445556 0.95 0.984 0.336888 0.905 0.936

Dept of Computer Science and Engineering SDMCET

35

Comparative study of image manipulation operations in Java and Matlab


0 nature20 rose1 rose3 penguin syd1 sun6 surf1 tiger1 snow2 winter1 winter1 wol1 space8 sun1 shut2 swan bost2 b2 cars2 a2 fighterjet 4 nature19 rose2 rose2 porsh syd2 syd1 surf2 tiger4 space6 winter2 tiger1 wol2 sun1 swan shut4 beetle buttr1 b3 build dol2 fighterjet 10 0.063 0.056 0.062 0.056 0.059 0.056 0.056 0.056 0.051 0.064 0.057 0.06 0.06 0.062 0.057 0.063 0.059 0.06 0.062 0.065 0.051 0.015 0.003 0.002 0.002 0.003 0.003 0.003 0.003 0.002 0.003 0.003 0.003 0.003 0.003 0.02 0.003 0.003 0.002 0.004 0.003 0.004 .57 0 .62 0 .65 0 .59 0 .65 0 .64 0 .62 0 .59 0 .61 0 .66 0 .56 0 .62 0 .59 0 .77 0 .62 0 .56 0 .60 0 .59 0 .57 0 .62 0 .58 0.316558 0.936 0.922 0.316558 0.907 0.934 0.294412 0.95 0.92 0.367049 0.936 0.904 0.367842 0.951 0.937 0.304521 0.903 0.925 0.362377 0.921 0.934 0.367876 0.936 0.906 0.360019 0.904 0.982 0.385112 0.982 0.937 0.310131 0.935 0.922 0.413931 0.936 0.919 0.314697 0.983 0.921 0.36746 0.936 0.92 0.331708 0.92 0.938 0.365051 0.923 0.907 0.690411 0.922 0.937 0.341755 0.967 0.953 0.372828 0.934 0.951 0.358842 0.981 0.92 0.301778 0.967 0.903

AVERA GES

0.0611 46

0.01158 854

0. 61 0.36

0.9414 792

0.93833 333

Dept of Computer Science and Engineering SDMCET

36

Comparative study of image manipulation operations in Java and Matlab

5. COMPARATIVE STUDY
5.1. Sample1(Resolution (1024*768)): Image2: a2.jpg

Image1: a1.jpg

Dept of Computer Science and Engineering SDMCET

37

Comparative study of image manipulation operations in Java and Matlab

Addition:

Difference:

Graph: 1. Addition:
x-axis: samples yaxis: time (in secs)

Dept of Computer Science and Engineering SDMCET

38

Comparative study of image manipulation operations in Java and Matlab

2. Difference
x-axis: samples yaxis: time (in secs)

5.2.

SAMPLE2 (Resolution (1024*768)): Image2: lion.jpg

Image1: mase.jpg

Dept of Computer Science and Engineering SDMCET

39

Comparative study of image manipulation operations in Java and Matlab

Addition:

Difference:

Graph:
x-axis: samples yaxis: time (in secs)

1. Addition:

Dept of Computer Science and Engineering SDMCET

40

Comparative study of image manipulation operations in Java and Matlab

2. Difference
x-axis: samples yaxis: time (in secs)

5.3. Graph for addition module for 100 images x-axis: samples yaxis: time (in secs)

Dept of Computer Science and Engineering SDMCET

41

Comparative study of image manipulation operations in Java and Matlab

5.4.

Graph for subtraction module for 100 images

6. CONCLUSION

Dept of Computer Science and Engineering SDMCET

42

Comparative study of image manipulation operations in Java and Matlab

By the above analysis, we conclude that the image processing in JAI (Java Advanced Imaging) is better compared to Core Java and MATLAB image processing. JAI is better both in terms of time and accuracy. 7. REFERENCES
[1] https://jaistuff.dev.java.net/ [2] www.netbeans.org/ [3] www.mathworks.com/products/matlab/ [4] https://jai.dev.java.net/binary-builds.html [5] http://java.sun.com/developer/technicalArticles/Media/AdvancedImage/ [6] http://wiki.netbeans.org/OpenImagesUsingJAI [7] Programming in Java Advanced Imaging- Release 1.0.1 -- By, Sun Microsystems. [8] Java Advanced Imaging API- A Tutorial By, Rafael Santos.

Dept of Computer Science and Engineering SDMCET

43

Potrebbero piacerti anche