Вы находитесь на странице: 1из 4

Image Processing using Java and C#: A Comparison Approach

María Isabel Díaz Figueroa


Advisor: Dr. Domingo Rodríguez

Automated Image Processing System Group


Electrical and Computer Engineering Department
University of Puerto Rico, Mayagüez Campus
Mayagüez, Puerto Rico 00681 – 9042
Maria.Diaz@ece.uprm.edu

Abstract these high level languages, such as


MATLAB, offer a rich functionality
This paper presents results of a study with a large group of images routines,
to compare Java and C# programming but hides many important aspects of the
languages features in terms of algorithms [1]. For that reason, is
portability, functional programming and important to create new environment to
execution time. This comparison know the performance of languages and
permits to evaluate both programming compare them.
languages to know which one has better C# is one of the most recent
performance in the image processing programming languages created by
area. Microsoft and Java is a programming
language very popular to create
1. Introduction environment to solve the image
processing discipline. This paper deals
Image Processing involves the with a basic comparison between Java
manipulation of the pixels of one image and C# programming languages focus in
to form another image. Those techniques image processing programming area.
have been used for years to improve the The goal of this paper is find out is
visual appearance of images. Image discover which language facilitates
processing operations can be divided manage of image processing algorithms.
into three major categories: Image In next section a comparison of both
Compression, Image Enhancement and languages will be done in terms of:
Restoration, and Image Measurement portability, functional programming and
Extraction. An image can be obtained execution time. The last section will
from some devices such as: scanners, provide the conclus ion and future work.
sensors, etc.
Many applications to solve the image 2. Java and C# Portability
processing discipline have been
developed for years. Programmers are Portability refers to the flexibility to
using different kinds of programming run a program in different architectures
languages to create new tools that and operating systems. Java offers three
improve quality of images to facilitate its kinds of portability: source code
study. Programmers use high level portability, CPU architecture portability
language such as C, Java and MATLAB and Operating System. A Java code can
to create these environments. Some of be run at any machine independently of
the operating system and its CPU new version of Visual Basic named
architecture. Java uses a Java Virtual VB.NET. At the same time, other
Machine (JVM) that is an abstract companies are developing .NET-
computing machine. It has an instruction compatible compilers for many other
set and manipulates various me mory languages. Figure 2 shows the CLR
areas at run time. That means that a user portability.
can do a Java program in Windows
platform and the same program can be
run in a computer using Linux platform
without doing any change to that code.
Figure 1 shows some of the platforms
supported by JVM.

Figure 2. CLR portability.

3. Functional Programming in Java


and C#

Functional programming cons ists in


that the main program is written as a
Figure 1. Some platforms supported by
function which receives the program’s
JVM. input as its argument and delivers the
program’s output as its result. Typically
On the other hand, a program written
the main function is defined in terms of
in C# can be executable just on
other functions, which in turn are
Windows operating system. C# is a
defined in terms of still more functions,
language build specifically to program until at the bottom level the functions are
the .NET Framework. The .NET
language primitives[2].
Framework consist of a runtime
In this case, the function to be
environment called (CLR) Common
developed will be functions that will
Language Runtime, and a set of base
operate on images. Those functions will
class libraries, which provide a receive an image as a parameter, then it
development platform that can be
will perform changes to the image and it
exploited by a variety of languages and
will return another image as a result.
tools. The CLR greatly improves
Figure 3 shows the functional
runtime interactivity between programs,
programming diagram to manipulate
security, development simplicity, and images.
cross- language integration. Whereas a
Java virtual machine only runs Java
programs, the CLR has been designed to
run programs written in any language.
Microsoft has developed .NET Figure 3. Functional Programming for
compilers for C++, C#, JScript, and a Image Processing.
4. Executable Speed in Java and C# Table 1. Java and C# Execution Speed.

To execute a source code made in Vector Matrix C# Java


Size Size Time(ms) Time(ms)
Java, the machine must have a JVM. 512 512 x 512 31 10
JVM interpret the class file format. A 1024 1024 x 1024 150 30
class file contains Java virtual machine 2048 2048 x 2048 610 590
instructions and a symbol table, as well 4096 4096 x 4096 2544 4357
as other ancillary information [3]. After 8192 8192 x 8192 9975 18697
that, JVM executes that program using 16834 16834 x 16834 2947168 N/A
the requirements to determinate
operating system. Every time a Java The benchmark measure the
code is executed, the JVM has to execution time that takes the
interpret the class files. On the other multiplication of the vector and matrix in
side, when the user runs a source code in both languages. Java provides a
C#, the computer must have a CLR function to take time in milliseconds. In
environment for hosting mana ged contrast, C# has not a function to take
applications. If the user runs a managed time in milliseconds. For that reason, the
executable, the CLR loads the module time was taken in hours, minutes,
containing the executable and execute seconds and milliseconds to then convert
the code inside it [4]. all to milliseconds. Figure 4 shows Java
An important factor to study in and C# code to take time system of the
image processing programming is the multiplication of the vector and matrix.
execution speed of Java and C#
programs respectively. When a Java Code
programming language is going to Start = System.currentTimeMillis();
manipulate any images, the images are
//matrix and vector multiply
converted into a matrix where every for (int i=0; i<size; i++)
element of the matrix represents a pixel for (int j=0; j<size; j++)
of the image. re[i]=a1[j]*matrix[j][i]+re[i];
A benchmark has been implemented end = System.currentTimeMillis();
in both languages in order to find out
which language has better performance. C# Code
The benchmark multiplies a vector by a hrbf = DateTime.Now.Hour;
mnbf = DateTime.Now.Minute;
squared matrix. The tests were realized scbf = DateTime.Now.Second;
in a Dell Laptop Inspiron 4150, Pentium msbf = DateTime.Now.Millisecond;
4 of 1.8 GHz, RAM 384MB, 30GB Ultra
//matrix and vector multiply
ATA Hard Drive. The operating system for (int i=0; i<size; i++)
used was Windows XP Professional. for (int j=0; j<size; j++)
The Java version is Java™ 2 Runtime re[i]=a1[j]*matrix[j,i]+re[i];
Environment, Standard Edition (build msaf = DateTime.Now.Millisecond;
1.4.0-b92). The .NET Edition used was scaf = DateTime.Now.Second;
Microsoft Development Environment mnaf = DateTime.Now.Minute;
hraf = DateTime.Now.Hour;
2002 version 7.0. Table 1 shows
resulting executing time in both Figure 4. Java and C# code for vector
environments. and matrix multiply.
functions that receive an argument as
The result shows that Java input and produce another argument as
application executes in less time than C# an output. Java and C# are similar in the
when matrix and vector is less than 1024 construction of classes. When a Java
size. For matrices and vectors of 2048 program is compiled, it generates a class
size, the execution time is similar for file that contains a set of statements that
both languages. When matrix and vector JVM must interpret to execute it at any
sizes are more than 4096, C# execute in platform. C# just creates an executable
less time than Java. In the environment file from the source code.
that was used for the test, Java was In the experiment to measure the
unavailable to execute a multiplication execution time in Java and C#, Java was
matrix vector with a 16834 size. faster than C# when the vector and
Therefore, C# language can perform the matrix sizes were small. For the other
matrix and vector of 16384, it takes a side, C# is faster than Java when matrix
while. Figure 5 shows that the execution and vector were greater than 4096.
time grows in exponential form when Another factor to observe in this
matrix and vector grows. experiment is that Java cannot solve
vector and matrix with size of 16834 and
Execution Time in C# and Java languages C# does. As a hypothetical conclusion to
20000
explain is that C# manages better the
15000
system component s or use hard disk to
solve it. Others studies will be done to
Time (ms)

C#
10000
Java know clearly what can be the causes.
5000
Future work includes develop a C#
0 environment with image processing
512 1024 2048 4096 8192
Matrix and Vector Size algorithms in order to compare it with
other Java applications.
Figure 5. Execution Time in Java and
C#. References
A hypothetical response to explain [1] D. Sage, M. Unser, Teaching Image –
this is that C# manages better the system Processing Programming in Java, IEEE Signal
components or that it uses the hard disk Processing Magazine, November 2003.
to solve this. Others studies will be done
[2] J. Hughes, Why Functional Programming
to know clearly what can be the causes. Matters, The Computer Journal, April 1989.

6. Conclusion and Future Work [3] T. Lindholm, F. Yellin. The Java™ Virtual
Machine Specification, Addison-Wesley, Palo
In terms of portability, Java is Alto, California, 1997-1999.
portable in source code, hardware and [4] J. Prosise, Programming Microsoft .NET,
operating system. However, C# is Microsoft Press, Redmond, Washington, 2002.
portable in terms of programming
languages. Both languages are Object [5] J. Sharp, J. Jagger, Microsoft Visual C# .NET
Oriented language that allows reuse the Step by Step, Microsoft Press, Redmond,
Washington, 2003.
code and offers the advantages of a
functional programming that permit
convert main program in terms of

Вам также может понравиться