Want to start developing applications for Java phones? Builder AU's resident Java expert, Michael Geisler shows you how to get started.

Question
Hi Michael, I'm a VB Developer and would like to start coding for my new toy (Sony/Ericsson P800 phone) but I have no idea where to start or what to download, any ideas?

Answer
Java has become the major platform for application development on mobile phones. Most of the new phones coming onto the market are Java capable and the Sony Ericsson P800 was one of the first phones to support Java. First of all I suggest you take a look at the following site which provides some pointers to VB developers wishing to learn Java. The online Java tutorials are also an excellent resource if you are new to Java.

With regard to developing for your phone. Your phone is capable of running J2ME MIDP 1.0 applications. J2ME (Java 2 Micro Edition) defines a subset of the APIs to that found in J2SE (Java 2 Standard Edition) and has a simpler GUI development model.

Sun offers a wireless toolkit for development of Java applications for phones using the MIDP (Mobile Information Device Profile) API set. Alternatively, you can download SunONE Studio Mobility (which inlcludes the wireless toolkit) for a full IDE. Another resource for developers looking for information on developing applications for mobile phones is the Sun Web site for mobile development.

Sony Ericsson has a great developer portal for their handsets, supply tools and technical hints and tips. You can also find an emulator specifically for your phone.


Ask the Builder AU Experts
Need your development-related questions solved? Meet the Builder AU team of experts that will answer your questions on a range of topics and technologies. Forward your questions now!


Do you need help with Java, C, or C++? Gain advice from Builder AU forums

Comments

1

AKmal - 25/04/05

is there any way to create a mobile java app to record movie thorugh java prog ....
as in c65 (siemens) there is camera n java but u cannot record movie i wana know if java can record movie

» Report offensive content

2

Jack - 25/10/05

Hi, i am new for j2me blackbarry development. i got example form your site ,so thank you very much, but i fail to run this hello application.
i am using RIM JDE 4.0.2.188 and
BlackBarry 7290 emulator.

my application does't display on the emulator.
please help me what mistake i'v comitted.

Is there any IDE or emulator configuration required.

Please reply me

Thanks
Jack

» Report offensive content

3

JADE - 28/11/06

hello there!!! please do help me about this problem program..how could i convert days into the following???
year=
months=
weeks=
days=
The problem required the use of java language..tnx..i hup so u cud email the code..

» Report offensive content

4

Leo - 14/08/07

This code below is a piece of code i
got from my C language program. So my question is that i want to change this
piece of code into the C++ language.

a) oddnumber(vector<vector<int> > &met, int n);

» Report offensive content

5

krish - 10/04/08

I have two jsp pages.in first jsp i placed one lable with name as Enter empno,one text filed and one button with ? mark.when i click on ? button it will open one window.in that window all existing employee numbers in the table are displayed.when i clicked on one employee number it will print on the first jsp page text filed. i wrote the all code by using window.open().it working fine.but when i clicked on employee numberin the window,it will not displayed in the first jsp's text filed.So please give me the answer to how to print that clicked employee number in the text filed.and send me the code too.Thanks in advanse.send me ASAP.

» Report offensive content

6

real_artist - 14/08/08

How to develop a J2ME program which gives an english word meaning in languages other than english

» Report offensive content

7

Abhilash - 06/03/09

hi,i m trying dis puzzle for long tyme...but unfortunately i did not get it.so,try dis and if u get plz suggest and explain me dat cod thanks in advance.

//Directions: Write a program that places a mouse(“M”) in a maze.
// The mouse has 2500 moves to find the cheese(“C”= -1). Create an int
// matrix x[55][95] with a border of cells all equal to 30000(=”X”).
// Then randomly fill the matrix with about 15% of its internal cells equal to 40000 (=”#”).
// Drop the cheese( -1) randomly in the lower right-hand quadrant.
// Place the mouse in the upper right-hand corner. All other cells have a zero value(=” “).
// As the mouse moves, it leaves a train of ever-increasing integers( = “.”).
// The mouse moves only up, down, left and right. The mouse does not move diagonally.
// When the mouse moves, it choses the adjacent cell with the smallest number.
// If there are two-or-more cells with the smallest number, then the mouse favors the directions
// in some particular order(right, down, left, up)




import java.lang.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;

public class Mouse extends JFrame
{
int mr = 1, mc = 1;
int move = 1;
int cc = 73, cr = 20;
int MAXMOVE = 2500;
int RMAX = 55, CMAX = 95;
int[][] x = new int [CMAX][RMAX];
//-----------------------------------------------------------------------------------------------
static void pause(int num)
{
long start = System.currentTimeMillis();
while(System.currentTimeMillis()-start<num);
}
//-----------------------------------------------------------------------------------------------
void printArray(Graphics2D g)
{
for(int r=0; r<RMAX; r++)
{
for(int c=0; c<CMAX; c++)
{
if (x[c][r] == 0)
g.drawString(" ", c*10+20, r*12+50);
else if (x[c][r] == 30000)
g.drawString("X", c*10+20, r*12+50);
else if (x[c][r] == 40000)
g.drawString("#", c*10+20, r*12+50);
else if(x[c][r] == -1)
{
g.setColor(Color.red);
g.drawString("C", c*10+20, r*12+50);
g.setColor(Color.yellow);
}
else
g.drawString(".", c*10+20, r*12+50);
}
}
}
//--------------------------------------------------------------------------------------------------
void initializeArray(Graphics2D g)
{
}
//--------------------------------------------------------------------------------------------------
void search(Graphics2D g)
{
while(move<MAXMOVE)
{
if(x[mc][mr] == -1)
break;
g.drawString("M", mc*10+20, mr*12+50);
pause(30);

//here are directions for the “search” method:
// You are at position x[c][r] in matrix x. You must move to either the left cell x[c-1][r],
// the right cell x[c+1][r], the upper cell x[c][r-1], or the lower cell x[c][r+1].
// You must move to the cell that has the smallest number value s. If s is in more than one location,
// then you will favor the directions in this order: right, down, left, and up.
// Write the code to give c and r their new values.
//
//
//
//
}
}
//---------------------------------------------------------------------------------------------------
public void paint(Graphics g1)
{
Graphics2D g = (Graphics2D) g1;
g.clearRect(0,0,getWidth(),getHeight());
initializeArray (g);
printArray (g);
g.setColor(Color.red);
search(g);
}
//----------------------------------------------------------------------------------------------------
public static void main(String[]args) throws IOException
{
System.out.println(" main begun ");
Mouse frame = new Mouse();
frame.setBackground(new Color(0,0,150));
frame.setForeground(Color.yellow);
frame.setSize(1280, 980);
frame.setTitle("Graphics Window");
frame.setFont(new Font("SansSerif", Font.PLAIN, 12));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println("paint launched.");
frame.setVisible(true);
}
}

» Report offensive content

8

Abhishek - 02/04/09

can we develop a mobile application whice run only for two days without using date and time and calendar class

» Report offensive content

9

Claus - 21/06/09

hellow, can you tell me where i can get a java aplication for my 6234(nokia) that has only image and video browsing option but with 3d effects like on N-series or new technology phones.Thanks in advance!

» Report offensive content

10

saleem - 04/10/09

hi
i am at the 5th year in the informatic faculty
i am thinking about graduation project
i am thinking to make
face recognation as a mobile application
but i am not sure if this cane be done
i am going to use j2me
please help

» Report offensive content

11

Aneev - 25/02/10

Hi
i m doing my final year project on BIOMETRIC ATTENDANCE MANAGEMENT .In this m using java .
The thing is that i have a source code but they r in c.
and want to convert them in java runnable code using jdk1.5.0.
Plz can anybody help me in this.
PlzPlzPlzPlz.
i m waiting.........................

SOURCE CODE FOR EVERY MODULE

A.1 Image Segmentation Source Code

// mean_block subrotine
//This subroutine calculate the average value for 8x8 blocks
int mean_block (BYTE **the_image, int row, int col, int x, int y)
{
int i, j;
long sum = 0;
long mean_value = 0;
//sum of all pixel value
for ( i = y; i < row; i++)
{
for (j = x; j < col; j++)
sum += the_image[i][j];
}
mean_value = sum/64;
return mean_value;
}
//image segmentation module
//this subroutine separate the foreground from the background
void image_segmentation (BYTE **the_image, int row, int col)
{
int i,j,x,y;
int subparameter = 0;
long powerparameter = 0;
long sumvalue = 0;
long variance_value = 0;
int new_row, new_col;
//define 8x8 block
y = 0;
x = 0;
new_row = 8;
new_col = 8;
do
{
do
{
//calculate the variance every pixel in each block
for (i=y; i<new_row; i++)
{
for (j=x; j<new_col; j++)
{
subparameter = the_image[i][j] - mean_block (the_image,new_row,new_col,x,y);
powerparameter = subparameter * subparameter;
sumvalue += powerparameter;
}
}
variance_value = sumvalue / 64;
sumvalue = 0;
// use variance as threshold value for each pixel
for (i=y; i<new_row; i++)
{
for (j=x; j<new_col; j++)
{
if (variance_value <= 4900)
{
the_image[i][j] = 255;
}
else
the_image[i][j] = the_image[i][j];
}
}
x = x + 8;
new_col = new_col + 8;
}
while ((x <= col) && (new_col <= col));
x = 0;
new_col = 8;
y = y + 8;
new_row = new_row + 8;
}
while ((y <= row) && (new_row <= row));
}


A.2 Binarization Source Code

//mean subroutine
//This subroutine calculate average intensity value
int mean(BYTE **the_image, int row, int col)
{
int i, j;
int sum = 0;
int mean_value = 0;
//sum of all pixel value
for ( i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
sum += the_image[i][j];
}
// sum of all pixel value divided by number of pixels
mean_value = sum/(row*col);
return (mean_value);
}
//binarization module
//This subroutine convert the grayscale image into binary image
void binarization(BYTE **the_image, int row, int col)
{
int i, j;// x, y;
int thres = 0;
thres = mean(the_image,row,col);
for (i = 0; i <row; i++)
{
for (j = 0; j <col; j++)
{
if (the_image[i][j] <= thres)
the_image[i][j] = 0;//turn all above thres to black
else
the_image[i][j] = 1;//turn all below thres to white
}
}
}

A.3 Noise Elimination Source Code

//define_struc_element3x3 subroutine
//this subroutine defines the 3x3 structuring element
int* define_struc_element3x3(BYTE **the_array, int p[], int y, int x, int row, int col)
{
int i;
// initial value for 3x3 structuring element
// all pixel are initialized to background value
for (i=0; i<9; i++)
{
p[i] = 1;
}
//boundary conditions for 3x3 structuring element
p[0] = the_array[y][x];
if ((y == 0) && (x == 0))
{
p[3] = the_array [y][x+1];
p[4] = the_array [y+1][x+1];
p[5] = the_array [y+1][x];
}
else if ((y == 0) && (x == (col - 1)))
{
p[5] = the_array [y+1][x];
p[6] = the_array [y+1][x-1];
p[7] = the_array [y][x-1];
}
else if ((y == (row -1)) && (x == 0))
{
p[1] = the_array [y-1][x];
p[2] = the_array [y-1][x+1];
p[3] = the_array [y][x+1];
}
else if ((y == (row - 1)) && (x == (col -1)))
{
p[1] = the_array [y-1][x];
p[7] = the_array [y][x-1];
p[8] = the_array [y-1][x-1];
}
else if (y == 0)
{
p[3] = the_array [y][x+1];
p[4] = the_array [y+1][x+1];
p[5] = the_array [y+1][x];
p[6] = the_array [y+1][x-1];
p[7] = the_array [y][x-1];
}
else if (x == 0)
{
p[1] = the_array [y-1][x];
p[2] = the_array [y-1][x+1];
p[3] = the_array [y][x+1];
p[4] = the_array [y+1][x+1];
p[5] = the_array [y+1][x];
}
else if (y == (row - 1))
{
p[1] = the_array [y-1][x];
p[2] = the_array [y-1][x+1];
p[3] = the_array [y][x+1];
p[7] = the_array [y][x-1];
p[8] = the_array [y-1][x-1];
}
else if (x == (col - 1))
{
p[1] = the_array [y-1][x];
p[5] = the_array [y+1][x];
p[6] = the_array [y+1][x-1];
p[7] = the_array [y][x-1];
p[8] = the_array [y-1][x-1];
}
else
{
p[1] = the_array [y-1][x];
p[2] = the_array [y-1][x+1];
p[3] = the_array [y][x+1];
p[4] = the_array [y+1][x+1];
p[5] = the_array [y+1][x];
p[6] = the_array [y+1][x-1];
p[7] = the_array [y][x-1];
p[8] = the_array [y-1][x-1];
}
return p;
}
// define_struc_element5x5 subroutine
// This subroutine defines the 5x5 structuring element
int* define_struc_element5x5(BYTE **the_array, int p[], int y, int x, int row, int col)
{
int i;
// initial value for 5x5 structuring element
// all pixel are initialized to background value
for (i=0; i<25; i++)
{
p[i] = 1;
}
//boundary conditions for 5x5 structuring element
p[0] = the_array[y][x];
if ((y == 0) && (x == 0))
{
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
}
else if ((y == 0) && (x == (col - 1)))
{
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
}
else if ((y == (row - 1)) && (x == 0))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
}
else if ((y == (row - 1)) && (x == (col - 1)))
{
p[1] = the_array[y-1][x];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
else if ((y == 0) && (x == 1))
{
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
}
else if ((y == 0) && (x == (col - 2)))
{
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
}
else if ((y == 1) && (x == 1))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
}
else if ((y == 1) && (x == (col - 2)))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
}
else if ((y == (row - 2)) && (x == 1))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[24] = the_array[y-2][x-1];
}
else if ((y == (row - 2)) && (x == (col - 2)))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
else if ((y == (row - 1)) && (x == 1))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[24] = the_array[y-2][x-1];
}
else if ((y == (row - 1)) && (x == (col - 2)))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
else if ((y == 1) && (x == 0))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
}
else if ((y == 1) && (x == (col - 1)))
{
p[1] = the_array[y-1][x];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
}
else if ((y == (row - 2)) && (x == 0))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
}
else if ((y == (row - 2)) && (x == (col - 1)))
{
p[1] = the_array[y-1][x];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
else if (y == 0)
{
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
}
else if (x == 0)
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
}
else if (x == (col - 1))
{
p[1] = the_array[y-1][x];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
else if (y == (row - 1))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];;
}
else if (y == 1)
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
}
else if (x == 1)
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[24] = the_array[y-2][x-1];

}
else if (x == (col - 2))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
else if (y == (row - 2))
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
else
{
p[1] = the_array[y-1][x];
p[2] = the_array[y-1][x+1];
p[3] = the_array[y][x+1];
p[4] = the_array[y+1][x+1];
p[5] = the_array[y+1][x];
p[6] = the_array[y+1][x-1];
p[7] = the_array[y][x-1];
p[8] = the_array[y-1][x-1];
p[9] = the_array[y-2][x];
p[10] = the_array[y-2][x+1];
p[11] = the_array[y-2][x+2];
p[12] = the_array[y-1][x+2];
p[13] = the_array[y][x+2];
p[14] = the_array[y+1][x+2];
p[15] = the_array[y+2][x+2];
p[16] = the_array[y+2][x+1];
p[17] = the_array[y+2][x];
p[18] = the_array[y+2][x-1];
p[19] = the_array[y+2][x-2];
p[20] = the_array[y+1][x-2];
p[21] = the_array[y][x-2];
p[22] = the_array[y-1][x-2];
p[23] = the_array[y-2][x-2];
p[24] = the_array[y-2][x-1];
}
return p;
}
// Noise_condition3x3 subroutine
// This subroutine contains the condition for 3x3 structuring element
void Noise_condition3x3 (BYTE **the_image, int row, int col)
{
int p[9];
int* ptr_p;
int x,y;
for (y=0;y<row;y++)
{
for (x=0;x<col;x++)
{
ptr_p = define_struc_element3x3 (the_image,p,y,x,row,col);
if (!p[0])
{
if (!((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8])))
{
if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
p[0] = 1;
the_image[y][x] = p[0];
}
}
}
}
}
}
// Noise_condition5x5 subroutine
// This subroutine contains the condition for 5x5 structuring element
void Noise_condition5x5 (BYTE **the_image, int row, int col)
{
int p[25];
int* ptr_p;
int x,y;
for (y=0;y<row;y++)
{
for (x=0;x<col;x++)
{
ptr_p = define_struc_element5x5 (the_image, p, y, x, row, col);
if (!p[0])
{
if (!((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]) && (!p[9]) &&
(!p[10]) && (!p[11]) && (!p[12]) && (!p[13]) && (!p[14]) && (!p[15]) && (!p[16]) && (!p[17]) && (!p[18]) && (!p[19]) &&
(!p[20]) && (!p[21]) && (!p[22]) && (!p[23]) && (!p[24])))
{
if ((p[9]) && (p[10]) && (p[11]) && (p[12]) && (p[13]) && (p[14]) && (p[15]) && (p[16]) &&
(p[17]) && (p[18]) && (p[19]) && (p[20]) && (p[21]) && (p[22]) && (p[23]) && (p[24]))
{
if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y-1][x] = 1;
}
else if ((p[1]) && (p[!2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y-1][x+1] = 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y][x+1] = 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[!4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y+1][x+1] = 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (!p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y+1][x] = 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (!p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y+1][x-1] = 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y][x-1] = 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (!p[8]))
{
the_image[y][x] = 1;
the_image[y-1][x-1] = 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y-1][x] = 1;
the_image[y-1][x+1] = 1;
the_image[y][x+1] = 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y][x+1] = 1;
the_image[y+1][x+1] = 1;
the_image[y+1][x] = 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y+1][x] = 1;
the_image[y+1][x-1] = 1;
the_image[y][x-1] = 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
the_image[y][x] = 1;
the_image[y-1][x] = 1;
the_image[y][x-1] = 1;
the_image[y-1][x-1] = 1;
}
else if ((p[1]) && (!p[2]) && (p[3]) && (!p[4]) && (p[5]) && (!p[6]) && (p[7]) && (!p[8]))
{
the_image[y][x] = 1;
the_image[y-1][x+1] = 1;
the_image[y+1][x+1] = 1;
the_image[y+1][x-1] = 1;
the_image[y-1][x-1] = 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
the_image[y][x] = 1;
the_image[y-1][x] = 1;
the_image[y][x+1] = 1;
the_image[y+1][x] = 1;
the_image[y][x-1] = 1;
}
}
}
}
}
}
}
// noise elimination module
// this subroutine remove all unwanted noise
void noise_elimination (BYTE **the_image, int row, int col)
{
Noise_condition5x5 (the_image, row, col);
Noise_condition3x3 (the_image, row, col);
}

A.4 Smoothing Source Code

// smooth_condition3x3 subroutine
// This subroutine contains the condition for 3x3 structuring element
int smooth_condition3x3(int p[])
{
int n;
if (!((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8])))
{
n = 0;
if (!p[1]) n++;
if (!p[2]) n++;
if (!p[3]) n++;
if (!p[4]) n++;
if (!p[5]) n++;
if (!p[6]) n++;
if (!p[7]) n++;
if (!p[8]) n++;
if ((n >= 6) && (n <= 8))
{
if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
}
}
return 0;
}
// smoothing3x3 subroutine
// this subroutine fill the pixel if it meets the condition
void smoothing3x3(BYTE **the_image, int row, int col)
{
int i,j;
int* ptr_p;
int p[9];
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
ptr_p = define_struc_element3x3(the_image, p, i, j, row, col);
if (p[0])
{
if (smooth_condition3x3(p))
{
p[0] = 0;
the_image[i][j] = p[0];
}
}
}
}
}

// smooth_condition5x5 subroutine
// This subroutine contains the condition for 5x5 structuring element
int smooth_condition5x5(int p[])
{
int n;
// if all outer rim is black, do the loop
if((!p[9]) && (!p[10]) && (!p[11]) && (!p[12]) && (!p[13]) && (!p[14]) && (!p[15]) && (!p[16]) && (!p[17]) &&
(!p[18]) && (!p[19]) && (!p[20]) && (!p[21]) && (!p[22]) && (!p[23]) && (!p[24]))
{
// if all inner rim is not white, do the loop
if (!((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8])))
{
n = 0;
if (!p[1]) n++;
if (!p[2]) n++;
if (!p[3]) n++;
if (!p[4]) n++;
if (!p[5]) n++;
if (!p[6]) n++;
if (!p[7]) n++;
if (!p[8]) n++;
if ((n >= 4) && (n <= 8))
{
if ((!p[1]) && (!p[2]) && (p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (p[3]) && (p[4]) && (p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (!p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((p[1]) && (!p[2]) && (p[3]) && (!p[4]) && (p[5]) && (!p[6]) && (p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
}
}
}
return 0;
}
// smoothing5x5 subroutine
// this subroutine fill the pixel if it meets the condition
void smoothing5x5(BYTE **the_image, int row, int col)
{
int i,j;
int* ptr_p;
int p[25];
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
ptr_p = define_struc_element5x5(the_image, p, i, j, row, col);
if (p[0])
{
if (smooth_condition5x5(p))
{
p[0] = 0;
the_image[i][j] = p[0];
}
}
}
}
}
// smoothing module
// this subroutine fill all the holes in the image
void smoothing (BYTE **the_image, int row, int col)
{
smoothing5x5(the_image,row,col);
smoothing3x3(the_image,row,col);
}

A.5 Thinning Source Code

// thinning_condition module
// conditions to delete the pixel at every subiteration
int thinning_condition( int p[])
{
int n,s;
if (!((p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8])))
{
// count the foreground pixel in the neighborhood
n = 0;
if (!p[1]) n++;
if (!p[2]) n++;
if (!p[3]) n++;
if (!p[4]) n++;
if (!p[5]) n++;
if (!p[6]) n++;
if (!p[7]) n++;
if (!p[8]) n++;
if ((n >= 2) && (n <= 6))
{
// count number of 1 to 0 transaction
s = 0;
if ((p[1]) && (!p[2])) s++;
if ((p[2]) && (!p[3])) s++;
if ((p[3]) && (!p[4])) s++;
if ((p[4]) && (!p[5])) s++;
if ((p[5]) && (!p[6])) s++;
if ((p[6]) && (!p[7])) s++;
if ((p[7]) && (!p[8])) s++;
if ((p[8]) && (!p[1])) s++;
if (s == 1)
{
return 1;
}
}
}
return 0;
}
//check condition for every subiteration (for every pixel)
//add counter every time satisfied condition
//delete all flagged pixel
int check_thinning_condition (BYTE **the_image, int row, int col, int ctr,int sub_no)
{
int i,j,x,y;
int* ptr_p;
int p[9];
int flag;
BYTE **the_image2;
the_image2 = allocate_image_array(row, col);
for (y=0;y<row;y++)
{
for (x=0;x<col;x++)
{
the_image2[y][x] = 0;
}
}
for (y=0;y<row;y++)
{
for (x=0;x<col;x++)
{
ptr_p = define_struc_element3x3 (the_image,p,y,x,row,col);
if (!p[0])
{
if (thinning_condition(p))
{
if (sub_no == 1)
{
if ((p[3]) || (p[5]) || ((p[1]) && (p[7])))
{
the_image2 [y][x] = 1;
ctr += 1;
}
}
if (sub_no ==2)
{
if ((p[1]) || (p[7]) || ((p[3]) && (p[5])))
{
the_image2 [y][x] = 1;
ctr += 1;
}
}
}
}
}
}
for (i=0;i<row;i++)
{
for (j=0;j<col;j++)
{
flag = the_image2 [i][j];
if (flag)
{
the_image [i][j] = 1;
}
}
}
return ctr;
}
//contain condition for 3x3 structuring element
int modified_thinning(int p[9])
{
if ((!p[1]) && (!p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (!p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (p[5]) && (p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (p[4]) && (p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (!p[2]) && (p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (!p[4]) && (p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (p[5]) && (!p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (p[4]) && (p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (!p[3]) && (!p[4]) && (!p[5]) && (p[6]) && (p[7]) && (p[8]))
{
return 1;
}
else if ((p[1]) && (p[2]) && (!p[3]) && (p[4]) && (!p[5]) && (!p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
else if ((!p[1]) && (p[2]) && (p[3]) && (p[4]) && (!p[5]) && (p[6]) && (!p[7]) && (!p[8]))
{
return 1;
}
else if ((!p[1]) && (!p[2]) && (!p[3]) && (p[4]) && (p[5]) && (p[6]) && (!p[7]) && (p[8]))
{
return 1;
}
return 0;
}
//thinning module
//skeletonized the image to one pixel thick
void thinning (BYTE **the_image, int row, int col)
{
int ctr;
int x,y;
int* ptr_p;
int p[9];
ctr = 0;
do
{
//check first sub(for every pixel)
ctr = check_thinning_condition (the_image, row, col, ctr, 1);
if (!(ctr == 0))//if counter != 0
{
ctr = 0;//set counter to 0
//check second sub(for every pixel)
ctr = check_thinning_condition (the_image, row, col, ctr, 2);
}
}
while (ctr != 0);//loop back to check first sub if counter != 0
for (y = 0; y < row; y ++)
{
for (x = 0; x < col; x++)
{
ptr_p = define_struc_element3x3(the_image,p,y,x,row,col);
if (!p[0])
{
if (modified_thinning(p))
{
the_image[y][x] = 1;
}
}
the_image[y][x] = the_image[y][x];
}
}
}

A.6 Minutiae Extraction Source Code

// calculate crossing number
int cross_num_algorithm(int p[9])
{
int sum_value = 0;
int sub_value;
int cn;
sub_value = p[1] - p[2];
sum_value = sum_value + abs (sub_value);
sub_value = p[2] - p[3];
sum_value = sum_value + abs (sub_value);
sub_value = p[3] - p[4];
sum_value = sum_value + abs (sub_value);
sub_value = p[4] - p[5];
sum_value = sum_value + abs (sub_value);
sub_value = p[5] - p[6];
sum_value = sum_value + abs (sub_value);
sub_value = p[6] - p[7];
sum_value = sum_value + abs (sub_value);
sub_value = p[7] - p[8];
sum_value = sum_value + abs (sub_value);
sub_value = p[8] - p[1];
sum_value = sum_value + abs (sub_value);
cn = sum_value / 2;
return cn;
}
// minutiae extraction module
// extract minutiae points from the image
int minutiae_extraction(BYTE **the_image, int row, int col, struct record minutiae[200])
{
int i,j;
int minutiae_count;
int p[9];
int *ptr_p;
int cross_num;
minutiae_count = 0;
for (i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
ptr_p = define_struc_element3x3(the_image,p,i,j,row,col);
if (!p[0])
{
cross_num = cross_num_algorithm(p);
if ((cross_num == 1) || (cross_num == 3))
{
minutiae[minutiae_count].type = cross_num;
minutiae[minutiae_count].x = j;
minutiae[minutiae_count].y = i;
minutiae_count++;
}
}
}
}
return minutiae_count;
}

A.7 Minutiae Validation Source Code

//define the 3x3 structuring element used in validation
void define_struc_p (BYTE **p, BYTE **image,int row, int col, int i, int j)
{
p[0][0] = (((i - 1 >= 0) && (j - 1 >= 0)) && ((i - 1 < row) && (j - 1 < col))) ? image[i - 1][j - 1] : 1;
p[0][1] = (((i - 1 >= 0) && (j >= 0)) && ((i - 1 < row) && (j < col))) ? image[i - 1][j] : 1;
p[0][2] = (((i - 1 >= 0) && (j + 1 >= 0)) && ((i - 1 < row) && (j + 1 < col))) ? image[i - 1][j + 1] : 1;
p[1][0] = (((i >= 0) && (j - 1 >= 0)) && ((i < row) && (j - 1 < col))) ? image[i][j - 1] : 1;
p[1][1] = (((i >= 0) && (j >= 0)) && ((i < row) && (j < col))) ? image[i][j] : 1;
p[1][2] = (((i >= 0) && (j + 1 >= 0)) && ((i < row) && (j + 1 < col))) ? image[i][j + 1] : 1;
p[2][0] = (((i + 1 >= 0) && (j - 1 >= 0)) && ((i + 1 < row) && (j - 1 < col))) ? image[i + 1][j - 1] : 1;
p[2][1] = (((i + 1 >= 0) && (j >= 0)) && ((i + 1 < row) && (j < col))) ? image[i + 1][j] : 1;
p[2][2] = (((i + 1 >= 0) && (j + 1 >= 0)) && ((i + 1 < row) && (j + 1 < col))) ? image[i + 1][j + 1] : 1;
}
//label each ridge according to minutiae type
void label_ridge (BYTE **image, int row, int col, BYTE **temp, BYTE **p, int i, int j, int m, int n, int label)
{
int stop = 0;
int black_count;
int stop1 = 0;
do
{
//define new structural element, p with new i,j
define_struc_p(p, image, row, col, i, j);
black_count = 0;
if (p[0][0] == 0) black_count++;
if (p[0][1] == 0) black_count++;
if (p[0][2] == 0) black_count++;
if (p[1][2] == 0) black_count++;
if (p[2][2] == 0) black_count++;
if (p[2][1] == 0) black_count++;
if (p[2][0] == 0) black_count++;
if (p[1][0] == 0) black_count++;
if (black_count == 1)
{
// check eight-connected pixel clock-wise
if (p[0][0] == 0)
{
// increment i,j accordingly
i--;
j--;
image[i][j] = label;
m--;
n--;
temp[m][n] = image[i][j];
}
else if (p[0][1] == 0)
{
i--;
image[i][j] = label;
m--;
temp[m][n] = image[i][j];
}
else if (p[0][2] == 0)
{
i--;
j++;
image[i][j] = label;
m--;
n++;
temp[m][n] = image[i][j];
}
else if (p[1][2] == 0)
{
j++;
image[i][j] = label;
n++;
temp[m][n] = image[i][j];
}
else if (p[2][2] == 0)
{
i++;
j++;
image[i][j] = label;
m++;
n++;
temp[m][n] = image[i][j];
}
else if (p[2][1] == 0)
{
i++;
image[i][j] = label;
m++;
temp[m][n] = image[i][j];
}
else if (p[2][0] == 0)
{
i++;
j--;
image[i][j] = label;
m++;
n--;
temp[m][n] = image[i][j];
}
else if (p[1][0] == 0)
{
j--;
image[i][j] = label;
n--;
temp[m][n] = image[i][j];
}
else
{
stop = 1;
}
}
else
{
stop1 = 1;
}
}
// find the right algorithm to stop the do loop( while == 0)
// do loop if while equal to 1
while (m != 0 && m != 14 && n != 0 && n != 14 && stop != 1 && stop1 != 1);
}
//check validity of ridge ending minutiae
int ending_candidate(BYTE **image, int row, int col, BYTE **temp, int i, int j)
{
int m,n; // variable for temp index
BYTE **p; // structural element used to check the ridge
int t01 = 0; // sum of 0 to 1 transition
// define structural element, p
p = allocate_image_array(3,3);
// delete image[i][j] with i,j is minutiae position
image[i][j] = 1;
define_struc_p(p, image, row, col, i, j);
m = 7;
n = 7;
// label the ridge accordingly
label_ridge(image,row, col, temp, p, i, j, m, n, 1);
free_image_array(p,3);
// count number of 0 to 1 transition along the border of temp
for (m=0, n=0; n<=13; n++)
{
if ((temp[m][n] == 0) && (temp[m][n + 1] == 1))
{
t01++;
}
}
for (m=0, n=14; m<=13; m++)
{
if ((temp[m][n] == 0) && (temp[m + 1][n] == 1))
{
t01++;
}
}
for (m=14, n=14; n>=1; n--)
{
if ((temp[m][n] == 0) && (temp[m][n - 1] == 1))
{
t01++;
}
}
for (m=14, n=0; m>=1; m--)
{
if ((temp[m][n] == 0) && (temp[m - 1][n] == 1))
{
t01++;
}
}
//minutiae valid if t01 == 1
if (t01 == 1)
{
return 1;
}
return 0;
}
// check validity of ridge bifurcation minutiae
int bifurcation_candidate(BYTE **image, int row, int col, BYTE **temp, int i_bifur, int j_bifur)
{
int m,n; // variable for temp index
int stop = 0;// variable to stop the do/while loop
BYTE **p; // structural element used to check the ridge
int t01 = 0, t02 = 0, t03 = 0; // sum of 0 to 1 transition
int counter; // variable for loop index
int x[3], y[3]; // x,y variable for each ridge
int q[3], r[3];
int i,j;
int black_count = 0;
// define structural element, p
p = allocate_image_array(3,3);
// at the minutiae point
// define structural element, p with i,j is the original minutiae position
define_struc_p(p, image, row, col, i_bifur, j_bifur);
// delete image[i_bifur][j_bifur]
image[i_bifur][j_bifur] = 1;
// label the first structuring element,p
// count the number of black pixel in p
if (p[0][0] == 0) black_count++;
if (p[0][1] == 0) black_count++;
if (p[0][2] == 0) black_count++;
if (p[1][2] == 0) black_count++;
if (p[2][2] == 0) black_count++;
if (p[2][1] == 0) black_count++;
if (p[2][0] == 0) black_count++;
if (p[1][0] == 0) black_count++;
if (black_count == 3)
{
counter = 1;
do
{
if (p[0][0] == 0)
{
i = i_bifur - 1;
j = j_bifur - 1;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 6;
n = 6;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
if (p[0][1] == 0)
{
i = i_bifur - 1;
j = j_bifur;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 6;
n = 7;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
if (p[0][2] == 0)
{
i = i_bifur - 1;
j = j_bifur + 1;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 6;
n = 8;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
if (p[1][2] == 0)
{
i = i_bifur;
j = j_bifur + 1;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 7;
n = 8;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
if (p[2][2] == 0)
{
i = i_bifur + 1;
j = j_bifur + 1;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 8;
n = 8;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
if (p[2][1] == 0)
{
i = i_bifur + 1;
j = j_bifur;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 8;
n = 7;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
if (p[2][0] == 0)
{
i = i_bifur + 1;
j = j_bifur - 1;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 8;
n = 6;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
if (p[1][0] == 0)
{
i = i_bifur;
j = j_bifur - 1;
y[counter - 1] = i;
x[counter - 1] = j;
image[i][j] = counter;
m = 7;
n = 6;
q[counter - 1] = m;
r[counter - 1] = n;
temp[m][n] = image[i][j];
counter++;
}
}
while (counter != 4);
}
else
{
return 0;
} // end if structuring element has 3 black pixel
// for the next structuring element
for (counter = 1; counter <= 3; counter++)
{
i = y[counter - 1];
j = x[counter - 1];
m = q[counter - 1];
n = r[counter - 1];
label_ridge(image,row,col,temp,p,i,j,m,n,counter);
}
free_image_array(p,3);
// count number of 0 to 1, 0 to 2 and 0 to 3 transition along the border of temp
for (m=0, n=0; n<=13; n++)
{
if ((temp[m][n] == 0) && (temp[m][n + 1] == 1))
{
t01++;
}
if ((temp[m][n] == 0) && (temp[m][n + 1] == 2))
{
t02++;
}
if ((temp[m][n] == 0) && (temp[m][n + 1] == 3))
{
t03++;
}
}
for (m=0, n=14; m<=13; m++)
{
if ((temp[m][n] == 0) && (temp[m + 1][n] == 1))
{
t01++;
}
if ((temp[m][n] == 0) && (temp[m + 1][n] == 2))
{
t02++;
}
if ((temp[m][n] == 0) && (temp[m + 1][n] == 3))
{
t03++;
}
}
for (m=14, n=14; n>=1; n--)
{
if ((temp[m][n] == 0) && (temp[m][n - 1] == 1))
{
t01++;
}
if ((temp[m][n] == 0) && (temp[m][n - 1] == 2))
{
t02++;
}
if ((temp[m][n] == 0) && (temp[m][n - 1] == 3))
{
t03++;
}
}
for (m=14, n=0; m>=1; m--)
{
if ((temp[m][n] == 0) && (temp[m - 1][n] == 1))
{
t01++;
}
if ((temp[m][n] == 0) && (temp[m - 1][n] == 2))
{
t02++;
}
if ((temp[m][n] == 0) && (temp[m - 1][n] == 3))
{
t03++;
}
}
//minutiae valid if (t01 = 1 AND t02 =1 AND t03 = 1)
if ((t01 == 1) && (t02 == 1) && (t03 == 1))
{
return 1;
}
return 0;
}
// calculate the teta for minutiae direction
int teta_calculation(int y_pos, int x_pos)
{
int sub_x, sub_y;
int select_x, select_y;
int teta;
sub_y = y_pos - 7;
select_y = abs(sub_y);
sub_x = x_pos - 7;
select_x = abs(sub_x);
switch (select_y)
{
case 0:
teta = 0;
break;
case 1:
teta = 8;
break;
case 2:
teta = 16;
break;
case 3:
teta = 23;
break;
case 4:
teta = 30;
break;
case 5:
teta = 36;
break;
case 6:
teta = 41;
break;
default:
switch (select_x)
{
case 0:
teta = 90;
break;
case 1:
teta = 82;
break;
case 2:
teta = 74;
break;
case 3:
teta = 67;
break;
case 4:
teta = 60;
break;
case 5:
teta = 54;
break;
case 6:
teta = 49;
break;
default:
teta = 45;
break;
}
break;
}
return teta;
}
// identify which quadrant the direction is
int direction_quadrant(int y_pos, int x_pos, int teta)
{
int direction;
if (y_pos <= 7)
{
direction = (x_pos >= 7) ? teta : (180 - teta);
}
else
{
direction = (x_pos <= 7) ? (180 + teta) : (360 - teta);
}
return direction;
}
// calculate the ending minutiae direction
int ending_direction(BYTE **temp)
{
int m,n;
int x_pos = 0;
int y_pos = 0;
int direction;
int teta;
// find the pixel for ridge direction and save the position
for (m=0, n=0; n<=14; n++)
{
if (temp[m][n] == 1)
{
y_pos = m;
x_pos = n;
}
}
for (m=1, n=14; m<=14; m++)
{
if (temp[m][n] == 1)
{
y_pos = m;
x_pos = n;
}
}
for (m=14, n=13; n>=0; n--)
{
if (temp[m][n] == 1)
{
y_pos = m;
x_pos = n;
}
}
for (m=13, n=0; m>=1; m--)
{
if (temp[m][n] == 1)
{
y_pos = m;
x_pos = n;
}
}
// calculate the value of teta
teta = teta_calculation(y_pos, x_pos);
// find direction quadrant and direction of ridge
direction = direction_quadrant(y_pos, x_pos, teta);
return direction;
}
// calculate the bifurcation minutiae direction
int bifurcation_direction(BYTE **temp)
{
int m, n;
int counter;
int y_pos, x_pos;
int x[3], y[3];
int bifur_direction;
int direction[3];
int teta, teta12, teta23, teta31;
// find the pixel for ridge direction and save the position
for (m=0, n=0; n<=13; n++)
{
for (counter = 1; counter <= 3; counter++)
{
if (temp[m][n] == counter)
{
y[counter - 1] = m;
x[counter - 1] = n;
}
}
}
for (m=0, n=14; m<=13; m++)
{
for (counter = 1; counter <= 3; counter++)
{
if (temp[m][n] == counter)
{
y[counter - 1] = m;
x[counter - 1] = n;
}
}
}
for (m=14, n=14; n>=1; n--)
{
for (counter = 1; counter <= 3; counter++)
{
if (temp[m][n] == counter)
{
y[counter - 1] = m;
x[counter - 1] = n;
}
}
}
for (m=14, n=0; m>=1; m--)
{
for (counter = 1; counter <= 3; counter++)
{
if (temp[m][n] == counter)
{
y[counter - 1] = m;
x[counter - 1] = n;
}
}
}
for (counter = 1; counter <= 3; counter++)
{
y_pos = y[counter - 1];
x_pos = x[counter - 1];
// calculate the value of teta
teta = teta_calculation(y_pos, x_pos);
// find direction quadrant and direction of ridge
direction[counter - 1] = direction_quadrant(y_pos, x_pos, teta);
}
// find teta difference between ridges
teta12 = direction[0] - direction[1];
if (teta12 < 0)
{
teta12 = (360 - direction[1]) + direction[0];
}
else
{
teta12 = teta12;
}
teta23 = direction[1] - direction[2];
if (teta23 < 0)
{
teta23 = (360 - direction[2]) + direction[1];
}
else
{
teta23 = teta23;
}
teta31 = direction[2] - direction[0];
if (teta31 < 0)
{
teta31 = (360 - direction[0]) + direction[2];
}
else
{
teta31 = teta31;
}
// find the bifurcation direction
if ((teta23 < teta12) && (teta23 < teta31))
{
bifur_direction = direction[0];
}
else if ((teta31 < teta12) && (teta31 < teta23))
{
bifur_direction = direction[1];
}
else if ((teta12 < teta23) && (teta12 < teta31))
{
bifur_direction = direction[2];
}
else
{
bifur_direction = 360;
}
return bifur_direction;
}
// minutiae validation module
// validate the minutiae point extracted from minutiae extraction
int minutiae_validation(BYTE **the_image, int row, int col, int minutiae_count, struct record minutiae[200], struct
record valid_minutiae[200])
{
int i,j,q;
int valid_minutiae_count = 0;
BYTE **temp;
BYTE **image;
int x,y; // general purpose variable for loop index
int direct;
int validity;
for (q=0; q<minutiae_count; q++)
{
image = allocate_image_array(row,col);
for (y=0; y<row; y++)
{
for (x=0; x<col; x++)
{
image[y][x] = the_image[y][x];
}
}
// create an array of size 15x15
temp = allocate_image_array(15,15);
// initialized the array to zero
for (y=0; y<15; y++)
{
for (x=0; x<15; x++)
{
temp[y][x] = 0;
}
}
// label the central pixel with -1 value
temp[7][7] = 4;
i = minutiae[q].y;
j = minutiae[q].x;
// the rest of the algorithm depend on the type of minutiae point
if (minutiae[q].type == 1)// for ridge ending minutiae
{
validity = ending_candidate(image, row, col, temp, i, j);
}
else if (minutiae[q].type == 3)// for ridge bifurcation minutiae
{
validity = bifurcation_candidate(image, row, col,temp, i, j);
}
else
{
validity = 0;
}
// add direction and store the record
if (validity == 1)
{
if (minutiae[q].type == 1)
{
direct = ending_direction(temp);
valid_minutiae[valid_minutiae_count].direction = direct;
valid_minutiae[valid_minutiae_count].type = minutiae[q].type;
valid_minutiae[valid_minutiae_count].x = minutiae[q].x;
valid_minutiae[valid_minutiae_count].y = minutiae[q].y;
valid_minutiae_count++;
}
else if(minutiae[q].type == 3)
{
direct = bifurcation_direction(temp);
valid_minutiae[valid_minutiae_count].direction = direct;
valid_minutiae[valid_minutiae_count].type = minutiae[q].type;
valid_minutiae[valid_minutiae_count].x = minutiae[q].x;
valid_minutiae[valid_minutiae_count].y = minutiae[q].y;
valid_minutiae_count++;
}
// mark the minutiae point
// 2 = red colour for ending
// 3 = green colour for bifurcation
if (valid_minutiae[valid_minutiae_count - 1].type == 1)
{
the_image[i][j] = 2;
}
else if (valid_minutiae[valid_minutiae_count - 1].type == 3)
{
the_image[i][j] = 3;
}
else
{
the_image[i][j] = the_image[i][j];
}
}
free_image_array(temp,15);
free_image_array(image,col);
}
return valid_minutiae_count;
}

A.8 Minutiae Matching Source Code

// minutiae matching module
// match templates from valid_minutiae with minutiae_enroll
int minutiae_matching(struct record valid_minutiae[200], struct record minutiae_enroll[200], int
enroll_minutiae_count, int verify_minutiae_count)
{
double similarity_M;
int match_count = 0;
int distance;
int angle;
int i,j,k,l;
int compare;
int percentage;
int array_number;
int a,b,c;
double d;
struct matched minutiae_point[60];
struct record minutiae_matched[400];
// minutiae1 = stored minutiae
// valid_minutiae = test minutiae
for (i=0; i<enroll_minutiae_count; i++)
{
k = 0;
for (j=0; j<verify_minutiae_count; j++)
{
// compare first minutiae1 with all valid_minutiae
// only the same type matters
if (valid_minutiae[j].type == minutiae_enroll[i].type)
{
// calculate the distance between the two minutiae point
a = minutiae_enroll[i].x - valid_minutiae[j].x;
b = minutiae_enroll[i].y - valid_minutiae[j].y;
c = (pow(abs(a),2)) + (pow(abs(b),2));
distance = sqrt(c);
// only minutiae that have distance < than Df
if (distance <= Df)
{
if (minutiae_enroll[i].direction - valid_minutiae[j].direction < 0)
{
angle = valid_minutiae[j].direction - minutiae_enroll[i].direction;
}
else
{
angle = minutiae_enroll[i].direction - valid_minutiae[j].direction;
}
// only minutiae that have angle < than Af
if (angle <= Af)
{
minutiae_point[k].no = j;
minutiae_point[k].distance = distance;
k++;
}
}
}
}
compare = minutiae_point[0].distance;
array_number = minutiae_point[0].no;
for (l = 1; l < k; l++)
{
if (minutiae_point[l].distance <= compare)
{
compare = minutiae_point[l].distance;
array_number = minutiae_point[l].no;
}
else
{
compare = compare;
array_number = array_number;
}
}
// store in minutiae matched
minutiae_matched[match_count].type = valid_minutiae[array_number].type;
minutiae_matched[match_count].direction = valid_minutiae[array_number].direction;
minutiae_matched[match_count].x = valid_minutiae[array_number].x;
minutiae_matched[match_count].y = valid_minutiae[array_number].y;
match_count++;
// delete valid_minutiae record
valid_minutiae[array_number].type = 0;
valid_minutiae[array_number].direction = 0;
valid_minutiae[array_number].x = 0;
valid_minutiae[array_number].y = 0;
}
d = (pow(match_count,2)) / (enroll_minutiae_count * verify_minutiae_count);
similarity_M = sqrt(d);
percentage = similarity_M * 100;
return percentage;
}

» Report offensive content

12

noel - 09/09/10

pls i want to learn how to develop application and deploy them on a telecom network (intelligent network)

» Report offensive content

12

noel - 09/09/10

pls i want to learn how to develop application and deploy them on a telecom network (intelligent network) ... more

11

Aneev - 25/02/10

Hi i m doing my final year project on BIOMETRIC ATTENDANCE MANAGEMENT .In this m using java . The thing is that ... more

10

saleem - 10/04/09

hi i am at the 5th year in the informatic faculty i am thinking about graduation project i am thinking to make face ... more

Log in


Sign up | Forgot your password?

What's on?

  • Optus Deal

    Broadband + home phone + PlayStation®3 in a single package price!