Exemplo n.º 1
0
//LEE:: segmentation for video images
void Masek::segmentiris(Masek::IMAGE *eyeimage, int *circleiris, int *circlepupil, double *imagewithnoise, int eyelidon, int highlighton, int highlightvalue)
{
	int lpupilradius, upupilradius, lirisradius, uirisradius, reflecthres;
	double scaling;	
	int rowi, coli, ri, rowp, colp, rp, oldrowp;
	double rowid, colid, rid, rowpd, colpd, rpd;
	int irl, iru, icl, icu;
	int imgsize[2];
	IMAGE* imagepupil, *topeyelid, *bottomeyelid;
	int i, j, k, m;
	int linecount;
	double *lines;
	int *xl, *yl;
	int *y2;
	int yla;

	//% define range of pupil & iris radii
	//LEE:Video Data
	//lpupilradius = 25;
	//lpupilradius = 22;
	//in small pupil, 12, 20 works very well.
	//in big pupil, 20, 55
	//the best result 14, 42;
	lpupilradius = 14;//
	upupilradius = 42;
	lirisradius = 62;
	uirisradius = 78;

	 /* //%CASIA
	lpupilradius = 28;
	upupilradius = 75;
	lirisradius = 80;
	uirisradius = 150;*/


	/*%    %LIONS
	%    lpupilradius = 32;
	%    upupilradius = 85;
	%    lirisradius = 145;
	%    uirisradius = 169;
	*/

	//% define scaling factor to speed up Hough transform
	scaling = 0.4;

	reflecthres = 240;
	//reflecthres = 100;

	//% find the iris boundary
	findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.20, 0.19, 1.00, 0.00, &rowi, &coli,&ri);
	//LEE:
	//findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.19, 0.13, 1.00, 0.00, &rowi, &coli,&ri);
	//findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.19, 0.11, 1.00, 0.00, &rowi, &coli,&ri);
	/*rowi = 215;
	coli = 345;
	ri = 115;*/
	/*rowi = 235;
	coli = 275;
	ri = 117;*/

	circleiris[0] = rowi;
	circleiris[1] = coli;
	circleiris[2] = ri;

	printf("iris is %d %d %d\n", rowi, coli, ri);

	rowid = (double)rowi;
	colid = (double)coli;
	rid = (double)ri;

	irl = roundND(rowid-rid);
	iru = roundND(rowid+rid);
	icl = roundND(colid-rid);
	icu = roundND(colid+rid);

	imgsize[0] = eyeimage->hsize[0];
	imgsize[1] = eyeimage->hsize[1];

	if (irl < 1 )
		irl = 1;


	if (icl < 1)
		icl = 1;


	if (iru > imgsize[0])
		iru = imgsize[0];


	if (icu > imgsize[1])
		icu = imgsize[1];
	printf("irl is %d, icl is %d iru is %d, icu is %d\n", irl , icl, iru, icu);

	//% to find the inner pupil, use just the region within the previously
	//% detected iris boundary
	imagepupil = (IMAGE*) malloc (sizeof(IMAGE));

	imagepupil->hsize[0] = iru-irl+1;
	imagepupil->hsize[1] = icu-icl+1;

	imagepupil->data = (unsigned char*)malloc(sizeof(unsigned char)*imagepupil->hsize[0]*imagepupil->hsize[1]);

	for (i = irl-1, k=0; i<iru; i++,k++)
	{
		for (j = icl-1, m=0; j<icu; j++, m++)
			imagepupil->data[k*imagepupil->hsize[1]+m] = eyeimage->data[i*eyeimage->hsize[1]+j];
	}

	//printimage(imagepupil, "imagepupil.txt");
	//%find pupil boundary
	findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.25,1.00,1.00, &rowp, &colp, &rp);
	//LEE:
	//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.21,1.00,1.00, &rowp, &colp, &rp);
	//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.26,0.24,1.00,1.00, &rowp, &colp, &rp);//Best
	//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.26,0.25,1.00,1.00, &rowp, &colp, &rp);//Best
	printf("1st: pupil is %d %d %d\n", rowp, colp, rp);

	oldrowp = rowp;
	rowpd = (double)rowp;
	colpd = (double)colp;
	rpd = (double)rp;

	rowpd = (double)irl + rowp;
	colpd = (double)icl + colp;

	rowp = roundND(rowpd);
	colp = roundND(colpd);
	 
	circlepupil[0] = rowp;
	circlepupil[1] = colp;
	circlepupil[2] = rp;
	printf("2nd: pupil is %d %d %d\n", rowp, colp, rp);

	//% set up array for recording noise regions
	//% noise pixels will have NaN values
	for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
		imagewithnoise[i] = eyeimage->data[i];

	if (eyelidon==1)
	{

		//%find top eyelid

		topeyelid = (IMAGE*)malloc(sizeof(IMAGE));
		topeyelid->hsize[0] = oldrowp-rp;
		topeyelid->hsize[1] = imagepupil->hsize[1];
		topeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*topeyelid->hsize[0]*topeyelid->hsize[1]);

		if (topeyelid->hsize[0]>0 && topeyelid->hsize[1]>0)
		{
			for (i = 0; i<(oldrowp-rp)*imagepupil->hsize[1]; i++)
				topeyelid->data[i] = imagepupil->data[i];

			linecount = findline(topeyelid, &lines);
		}
		else 
			linecount=0;

		if (linecount > 0)
		{
			xl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);
			yl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);

			linescoords(lines, topeyelid->hsize[0], topeyelid->hsize[1], xl, yl);

			yla = -1;
			for (i = 0; i<topeyelid->hsize[1]; i++)
			{
				yl[i] = yl[i]+irl-1;
				xl[i]=xl[i]+icl-1;
				if (yla<yl[i])
					yla = yl[i];

				imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
			}
			y2 = (int*)malloc(sizeof(int)*yla);
			for (i = 0; i<yla; i++)
			{
				y2[i] = i+1;
				for (j = 0; j<topeyelid->hsize[1]; j++)
					imagewithnoise[(y2[i]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
			}
			free (xl);
			free (yl);
			free(y2);
			free(lines);
		}

		
		//%find bottom eyelid
		bottomeyelid = (IMAGE*)malloc(sizeof(IMAGE));

		bottomeyelid->hsize[0] = imagepupil->hsize[0]-(oldrowp+rp)+1;
		bottomeyelid->hsize[1] = imagepupil->hsize[1];
		bottomeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);


		if (bottomeyelid->hsize[0]>0 && bottomeyelid->hsize[1]>0)
		{	
			memcpy(bottomeyelid->data, &imagepupil->data[(oldrowp+rp-1)*imagepupil->hsize[1]], bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);	
			linecount = findline(bottomeyelid, &lines);
		}
		else
			linecount=0;

		if (linecount > 0)
		{
			xl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);
			yl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);

			linescoords(lines, bottomeyelid->hsize[0], bottomeyelid->hsize[1], xl, yl);

			/*fid = fopen("x1.txt", "w");
			for (i=0; i<bottomeyelid->hsize[1]; i++)
				fprintf(fid, "%d %d\n", i+1, xl[i]);
			fclose(fid);

		fid = fopen("y1.txt", "w");
		for (i=0; i<bottomeyelid->hsize[1]; i++)
			fprintf(fid, "%d %d\n", i+1, yl[i]);
		fclose(fid);*/

			yla = eyeimage->hsize[0];
		
			for (i = 0; i<bottomeyelid->hsize[1]; i++)
			{
				yl[i] = yl[i]+irl+oldrowp+rp-2;
				xl[i]=xl[i]+icl-1;
				if ( yla>yl[i])
					yla = yl[i];

				imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
			}
			y2 = (int*)malloc(sizeof(int)*(eyeimage->hsize[0]-yla+1));
			for (i = yla-1; i<eyeimage->hsize[0]; i++)
			{
				y2[i-yla+1] = i+1;
				for (j = 0; j<bottomeyelid->hsize[1]; j++)
					imagewithnoise[(y2[i-yla+1]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
			}
			free (xl);
			free (yl);
			free(y2);
			free(lines);
		}
		free(topeyelid->data);
		free(topeyelid);
		free(bottomeyelid->data);
		free(bottomeyelid);

	}
	/*fid = fopen("imagewithnoise.txt", "w");
	for (i = 0; i<eyeimage->hsize[0]; i++)
		for (j = 0; j<eyeimage->hsize[1]; j++)
		{
			if (gccport::_isnan(imagewithnoise[i*eyeimage->hsize[1]+j]))
					fprintf(fid, "%d %d NaN\n", i+1, j+1);
			else
				fprintf(fid, "%d %d %f\n", i+1, j+1, imagewithnoise[i*eyeimage->hsize[1]+j]);
		}
	fclose(fid);
	*/

	/*%For CASIA, eliminate eyelashes by thresholding
	%ref = eyeimage < 100;
	%coords = find(ref==1);
	%imagewithnoise(coords) = NaN;
	*/
	if (highlighton==1)
	{
		for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
			if (eyeimage->data[i]>highlightvalue)
				imagewithnoise[i] = sqrt((double)-1); // Lee: added cast
	}

	free(imagepupil->data);
	free(imagepupil);
}
Exemplo n.º 2
0
int Masek::segmentiris_iridian(Masek::IMAGE *eyeimage, char *gndfilename, int *circleiris, int *circlepupil, double *imagewithnoise, int eyelidon, int highlighton, int highlightvalue)
{
	int lpupilradius, upupilradius, lirisradius, uirisradius, reflecthres;
	double scaling;	
	int rowi, coli, ri, rowp, colp, rp, oldrowp;
	double rowid, colid, rid;//LEE: delete rowpd, colpd, rpd;
	int irl, iru, icl, icu;
	int imgsize[2];
	IMAGE* imagepupil, *topeyelid, *bottomeyelid;
	int i, j, k, m;
	int linecount;
	double *lines;
	int *xl, *yl;
	int *y2;
	int yla;
//	int iris_xpart[8], iris_ypart[8], iris_valid[8], pupil_xpart[8], pupil_ypart[8], pupil_valid[8];//LEE:
//	char buffer[100];//LEE:
	FILE *gndfile;
//	char tmpchar;//LEE:
//	int count;//LEE:
//	int tmpr;//LEE:
//	double a, b;
//	int left, right, hasnoise;//LEE:

//% define range of pupil & iris radii

 /* //LEE:Video Data
lpupilradius = 25;
upupilradius = 58;
lirisradius = 62;
uirisradius = 78;*/

/*  //LEE:Video Data
lpupilradius = 12;
upupilradius = 58;
lirisradius = 60;
uirisradius = 80;*/

//%CASIA
lpupilradius = 28;
upupilradius = 75;
lirisradius = 80;
uirisradius = 150;

/*%    %LIONS
%    lpupilradius = 32;
%    upupilradius = 85;
%    lirisradius = 145;
%    uirisradius = 169;
*/

//% define scaling factor to speed up Hough transform
scaling = 0.4;

reflecthres = 240;

//read in iris and pupil boundaries.
gndfile = fopen(gndfilename, "r");
if (gndfile==NULL)
{
	printf("could not open gndfile %s \n", gndfilename);
	return -1;
}
fscanf(gndfile, "%d %d %d %d %d %d",&rowi, &coli, &ri, &rowp, &colp, &rp);
fclose(gndfile);


//% find the iris boundary


circleiris[0] = rowi;
circleiris[1] = coli;
circleiris[2] = ri;

//printf("iris is %d %d %d\n", rowi, coli, ri);

rowid = (double)rowi;
colid = (double)coli;
rid = (double)ri;

irl = roundND(rowid-rid);
iru = roundND(rowid+rid);
icl = roundND(colid-rid);
icu = roundND(colid+rid);

imgsize[0] = eyeimage->hsize[0];
imgsize[1] = eyeimage->hsize[1];

if (irl < 1 )
    irl = 1;


if (icl < 1)
    icl = 1;


if (iru > imgsize[0])
    iru = imgsize[0];


if (icu > imgsize[1])
    icu = imgsize[1];
//printf("irl is %d, icl is %d iru is %d, icu is %d\n", irl , icl, iru, icu);

//% to find the inner pupil, use just the region within the previously
//% detected iris boundary
imagepupil = (IMAGE*) malloc (sizeof(IMAGE));

imagepupil->hsize[0] = iru-irl+1;
imagepupil->hsize[1] = icu-icl+1;
imagepupil->data = (unsigned char*)malloc(sizeof(unsigned char)*imagepupil->hsize[0]*imagepupil->hsize[1]);

for (i = irl-1, k=0; i<iru; i++,k++)
{
	for (j = icl-1, m=0; j<icu; j++, m++)
		imagepupil->data[k*imagepupil->hsize[1]+m] = eyeimage->data[i*eyeimage->hsize[1]+j];
}

//printimage(imagepupil, "imagepupil.txt");
//%find pupil boundary
//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.25,1.00,1.00, &rowp, &colp, &rp);
//printf("pupil is %d %d %d\n", rowp, colp, rp);

oldrowp = rowp-irl;
/*rowpd = (double)rowp;
colpd = (double)colp;
rpd = (double)rp;

rowpd = (double)irl + rowp;
colpd = (double)icl + colp;

rowp = roundND(rowpd);
colp = roundND(colpd);
 */
circlepupil[0] = rowp;
circlepupil[1] = colp;
circlepupil[2] = rp;

//printf("pupil is %d %d %d\n", rowp, colp, rp);

//% set up array for recording noise regions
//% noise pixels will have NaN values
for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
	imagewithnoise[i] = eyeimage->data[i];

if (eyelidon==1)
{
//%find top eyelid

	topeyelid = (IMAGE*)malloc(sizeof(IMAGE));
	topeyelid->hsize[0] = oldrowp-rp;
	topeyelid->hsize[1] = imagepupil->hsize[1];
	topeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*topeyelid->hsize[0]*topeyelid->hsize[1]);

	if (topeyelid->hsize[0]>0 && topeyelid->hsize[1]>0)
	{
		for (i = 0; i<(oldrowp-rp)*imagepupil->hsize[1]; i++)
			topeyelid->data[i] = imagepupil->data[i];

		linecount = findline(topeyelid, &lines);
	}
	else 
		linecount=0;

	if (linecount > 0)
	{
		xl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);
		yl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);

		linescoords(lines, topeyelid->hsize[0], topeyelid->hsize[1], xl, yl);

		yla = -1;
		for (i = 0; i<topeyelid->hsize[1]; i++)
		{
			yl[i] = yl[i]+irl-1;
			xl[i]=xl[i]+icl-1;
			if (yla<yl[i])
				yla = yl[i];

			imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
		}
		y2 = (int*)malloc(sizeof(int)*yla);
		for (i = 0; i<yla; i++)
		{
			y2[i] = i+1;
			for (j = 0; j<topeyelid->hsize[1]; j++)
				imagewithnoise[(y2[i]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
		}
		free (xl);
		free (yl);
		free(y2);
		free(lines);
	}


//%find bottom eyelid
	bottomeyelid = (IMAGE*)malloc(sizeof(IMAGE));

	bottomeyelid->hsize[0] = imagepupil->hsize[0]-(oldrowp+rp)+1;
	bottomeyelid->hsize[1] = imagepupil->hsize[1];
	bottomeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);

	if (bottomeyelid->hsize[0]>0 && bottomeyelid->hsize[1]>0)
	{
		memcpy(bottomeyelid->data, &imagepupil->data[(oldrowp+rp-1)*imagepupil->hsize[1]], bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);


		linecount = findline(bottomeyelid, &lines);
	}
	else
		linecount=0;


	if (linecount > 0)
	{
		xl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);
		yl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);

		linescoords(lines, bottomeyelid->hsize[0], bottomeyelid->hsize[1], xl, yl);

	/*fid = fopen("x1.txt", "w");
	for (i=0; i<bottomeyelid->hsize[1]; i++)
		fprintf(fid, "%d %d\n", i+1, xl[i]);
	fclose(fid);

	fid = fopen("y1.txt", "w");
	for (i=0; i<bottomeyelid->hsize[1]; i++)
		fprintf(fid, "%d %d\n", i+1, yl[i]);
	fclose(fid);*/

		yla = eyeimage->hsize[0];
	
		for (i = 0; i<bottomeyelid->hsize[1]; i++)
		{
			yl[i] = yl[i]+irl+oldrowp+rp-2;
			xl[i]=xl[i]+icl-1;
			if ( yla>yl[i])
				yla = yl[i];

			imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
		}
		y2 = (int*)malloc(sizeof(int)*(eyeimage->hsize[0]-yla+1));
		for (i = yla-1; i<eyeimage->hsize[0]; i++)
		{
			y2[i-yla+1] = i+1;
			for (j = 0; j<bottomeyelid->hsize[1]; j++)
				imagewithnoise[(y2[i-yla+1]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
		}
		free (xl);
		free (yl);
		free(y2);
		free(lines);
	}	   
	free(topeyelid->data);
	free(topeyelid);
	free(bottomeyelid->data);
	free(bottomeyelid);

}
/*fid = fopen("imagewithnoise.txt", "w");
for (i = 0; i<eyeimage->hsize[0]; i++)
	for (j = 0; j<eyeimage->hsize[1]; j++)
	{
		if (gccport::_isnan(imagewithnoise[i*eyeimage->hsize[1]+j]))
				fprintf(fid, "%d %d NaN\n", i+1, j+1);
		else
			fprintf(fid, "%d %d %f\n", i+1, j+1, imagewithnoise[i*eyeimage->hsize[1]+j]);
	}
fclose(fid);
*/

/*%For CASIA, eliminate eyelashes by thresholding
%ref = eyeimage < 100;
%coords = find(ref==1);
%imagewithnoise(coords) = NaN;
*/
	if (highlighton==1)
	{
		for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
			if (eyeimage->data[i]>highlightvalue)
				imagewithnoise[i] = sqrt((double)-1);
	}

	free(imagepupil->data);
	free(imagepupil);
	printf("leaving segmentiris\n");
	return 0;

}
Exemplo n.º 3
0
void Masek::normaliseiris(Masek::filter *image, int xiris, int yiris, int riris, 
                          int xpupil, int ypupil, int rpupil,
                          char *eyeimage_filename,
						  int radpixels, int angulardiv, 
						  Masek::filter *polar_array, Masek::IMAGE *polar_noise)
{
//global DIAGPATH
int radiuspixels;
int angledivisions;
double r;
double *theta, *b, xcosmat, xsinmat, rmat;
filter xo, yo;
int i, j;
double x_iris, y_iris, r_iris, x_pupil, y_pupil, r_pupil, ox, oy;
int sgn;
double phi;
double a;
//FILE *fid;
//IMAGE tmpimage;
int *x, *y, *xp, *yp;
int len;
double sum, avg;
int count;

//printfilter(image, "image.txt");
radiuspixels = radpixels + 2;
angledivisions = angulardiv-1;


theta = (double*)malloc(sizeof(double)*(angledivisions+1));
for (i = 0; i<angledivisions+1; i++)
	theta[i] = 2*i*PI/angledivisions;

x_iris = (double)xiris;
y_iris = (double)yiris;
r_iris = (double)riris;

x_pupil = (double)xpupil;
y_pupil = (double)ypupil;
r_pupil = (double)rpupil;

//% calculate displacement of pupil center from the iris center
ox = x_pupil - x_iris;
oy = y_pupil - y_iris;

if (ox <= 0)
    sgn = -1;
else if (ox > 0)
    sgn = 1;


if (ox==0 && oy > 0)
    sgn = 1;


//a = ones(1,angledivisions+1)* (ox^2 + oy^2);
a = ox*ox+oy*oy;

//% need to do something for ox = 0
if (ox == 0)
    phi = PI/2;
else
    phi = atan(oy/ox);

b = (double*)malloc(sizeof(double)*(angledivisions+1));
xo.hsize[0] = (radiuspixels-2);
xo.hsize[1] = angledivisions+1;
xo.data = (double*)malloc(sizeof(double)*(angledivisions+1)*(radiuspixels-2));

yo.hsize[0] = (radiuspixels-2);
yo.hsize[1] = angledivisions+1;
yo.data = (double*)malloc(sizeof(double)*(angledivisions+1)*(radiuspixels-2));

//% calculate radius around the iris as a function of the angle
for (i = 0; i<angledivisions+1; i++)
{
	b[i] = sgn*cos(PI - phi - theta[i]);
	r = sqrt(a)*b[i]+sqrt(a*b[i]*b[i]-(a-r_iris*r_iris));
	r -= r_pupil;
	
	//% calculate cartesian location of each data point around the circular iris
	//% region
	xcosmat = cos(theta[i]);
	xsinmat = sin(theta[i]);
/*% exclude values at the boundary of the pupil iris border, and the iris scelra border
% as these may not correspond to areas in the iris region and will introduce noise.
%
% ie don't take the outside rings as iris data.*/

	for (j = 0; j<radiuspixels; j++)
	{
		rmat = r*j/(radiuspixels-1);
		rmat += r_pupil;
		if (j>0 && j<radiuspixels-1)
		{
			xo.data[(j-1)*(angledivisions+1)+i] = rmat*xcosmat+x_pupil;
			yo.data[(j-1)*(angledivisions+1)+i] = -rmat*xsinmat+y_pupil;
		}
	}
}

/*

% extract intensity values into the normalised polar representation through
% interpolation
[x,y] = meshgrid(1:size(image,2),1:size(image,1)); */
interp2(image, &xo, &yo, polar_array);

//% create noise array with location of NaNs in polar_array
polar_noise->hsize[0] = polar_array->hsize[0];
polar_noise->hsize[1] = polar_array->hsize[1];
polar_noise->data = (unsigned char*)malloc(sizeof(unsigned char)*polar_noise->hsize[0]*polar_noise->hsize[1]);
memset(polar_noise->data, 0, polar_noise->hsize[0]*polar_noise->hsize[1]);

count=0;

for (i = 0; i<polar_noise->hsize[0]*polar_noise->hsize[1]; i++)
{
    if (isnan(polar_array->data[i])) // Lee: renamed from "isnan"
	{
		polar_noise->data[i] = 1;
		count++;
	}
	else
	{
		polar_noise->data[i] = 0;
        polar_array->data[i] = polar_array->data[i]/255;
	}
}

//printfilter(polar_array, "polar.txt");
//printimage(polar_noise, "polar_noise.txt");

//% start diagnostics, writing out eye image with rings overlayed

//% get rid of outling points in order to write out the circular pattern
for (i = 0; i<xo.hsize[0]*xo.hsize[1]; i++)
{
	if (xo.data[i]>image->hsize[1])
		xo.data[i] = image->hsize[1];
	else if (xo.data[i]<1)
		xo.data[i] = 1;
	xo.data[i] = roundND(xo.data[i]);
}

for (i = 0; i<yo.hsize[0]*yo.hsize[1]; i++)
{
	if (yo.data[i]>image->hsize[0])
		yo.data[i] = image->hsize[0];
	else if (yo.data[i]<1)
		yo.data[i] = 1;
	yo.data[i] = roundND(yo.data[i]);
}


/*tmpimage.hsize[0] = image->hsize[0];
tmpimage.hsize[1] = image->hsize[1];
tmpimage.data = (unsigned char*)malloc(sizeof(unsigned char)*tmpimage.hsize[0]*tmpimage.hsize[1]);
for (i = 0; i<tmpimage.hsize[0]*tmpimage.hsize[1]; i++)
{
	if (_isnan(image->data[i]))  // Lee: renamed from "isnan"
		tmpimage.data[i] = 0;
	else
		tmpimage.data[i] = (int)image->data[i];
}*/



/*for (i = 0; i<yo.hsize[0]*yo.hsize[1]; i++)
	tmpimage.data[(int)((yo.data[i]-1)*tmpimage.hsize[1]+(xo.data[i])-1)] = 255;
*/

//%get pixel coords for circle around iris
len = circlecoords(x_iris,y_iris,r_iris,image->hsize, -1, &x, &y);


//ind2 = sub2ind(size(image),double(y),double(x));
/*fid = fopen("xy.txt", "w");
for (i = 0; i<len; i++)
{
	fprintf(fid, "%d %d %d\n", i+1, x[i], y[i]);
	tmpimage.data[(y[i]-1)*tmpimage.hsize[1]+(x[i]-1)] = 255;
}
fclose(fid);*/
//%get pixel coords for circle around pupil

len = circlecoords(x_pupil,y_pupil,r_pupil,image->hsize, -1, &xp, &yp);
/*for (i = 0; i<len; i++)
	tmpimage.data[(yp[i]-1)*tmpimage.hsize[1]+(xp[i]-1)] = 255;*/
//printimage(&tmpimage, "tmpimage.txt");


/*% write out rings overlaying original iris image
%w = cd;
%cd(DIAGPATH);
imwrite(image,[eyeimage_filename,'-normal.jpg'],'jpg');

%cd(w);

% end diagnostics
*/
//%replace NaNs before performing feature encoding
sum = 0;
for (i = 0; i<polar_array->hsize[0]*polar_array->hsize[1]; i++)
{
    if (isnan(polar_array->data[i])) // Lee: renamed from "isnan"
		sum+=0.5;
	else
		sum+=polar_array->data[i];
}
avg = sum/(polar_array->hsize[0]*polar_array->hsize[1]);

for (i = 0; i<polar_array->hsize[0]*polar_array->hsize[1]; i++)
{
    if (isnan(polar_array->data[i]))
		//polar_array->data[i] = sqrt((double)-1);//LEE:added
		polar_array->data[i] = avg;
}

free(xp);
free(yp);
free(x);
free(y);

free(theta);
free(b);
free(xo.data);
free(yo.data);

//printfilter(polar_array, "polar_array.txt");
}