From: marlina on
Hi all,

Anyone could help me on translate this programming ROI detection written in Visual C into Matlab?
Actually this code about hand vein ROI extraction.

Thank you

//********************************ROI DETECTION***************************/
//surfaceIn-filled image (extracted finger region)
//surfaceOriGray-original grayscale image
//surfaceOut0-align filled image
//surfaceOut-align segmented grayscale image
void putBackAlignResize(SDL_Surface *surfaceIn, SDL_Surface *surfaceOriGray, SDL_Surface *surfaceOut0,SDL_Surface *surfaceOut, unsigned int refPointX, unsigned int refPointY)
{
//size of original image (320*240)
unsigned int width = surfaceIn->w;
unsigned int height= surfaceIn->h;
//size of resize image (320*150)
unsigned int widthResize = surfaceOut->w;
unsigned int heightResize= surfaceOut->h;
//looping parameter
unsigned int i=0, x=0, y=0;
int x1=0,y1=0; //negative, use int (cant reuse x & y)
//find reference point for finger
unsigned int fTipCoorX=0, coorY[2]={0,0},middleX=0, middleY=0;
//delta x & y for alignment
int tx, ty;
unsigned int **arraySurfaceIn, **arraySegment;
unsigned int **arraySurfaceInAligned, **arraySegmentAligned;
arraySurfaceIn= (unsigned int **) malloc ( (width)*sizeof(unsigned int) );
arraySegment= (unsigned int **) malloc ( (width)*sizeof(unsigned int) );
arraySurfaceInAligned= (unsigned int **) malloc ( (width)*sizeof(unsigned int) );
arraySegmentAligned= (unsigned int **) malloc ( (width)*sizeof(unsigned int) );
90
for (i = 0; i < width; i++ )
{
arraySurfaceIn[i] = (unsigned int *) malloc ( (height) * sizeof(unsigned int) );
arraySegment[i] = (unsigned int *) malloc ( (height) * sizeof(unsigned int) );
arraySurfaceInAligned[i] = (unsigned int *) malloc ( (height) * sizeof(unsigned int) );
arraySegmentAligned[i] = (unsigned int *) malloc ( (height) * sizeof(unsigned int) );
}
//initialize array
for (x=0; x<width; x++)
for (y=0; y<height; y++)
{
arraySurfaceIn[x][y]=0;
arraySegment[x][y]=255;
arraySurfaceInAligned[x][y]=0;
arraySegmentAligned[x][y]=255;
}
//******************************************************************************
//FIND tx & ty FOR ALIGNMENT
//finger tip coordinate X detection
for (x1=width-10; x1>0; x1--)
for (y=5; y<height-10; y++)
if (getpixel(surfaceIn, x1, y)==255)
{
fTipCoorX=x1;
printf("finger tip: %d",fTipCoorX);
goto DETECTED;
}
DETECTED:
middleX=fTipCoorX -170;
for (y=0; y<height; y++)
if (getpixel(surfaceIn, middleX-70, y)==255)
{
coorY[0]=y; //top coordinate y
break;
}
for (y1=height-1; y1>=0; y1--)
if (getpixel(surfaceIn, middleX-70, y1)==255)
{
coorY[1]=y1; //bottom coordinate y
break;
}
middleY =(coorY[1]+coorY[0])/2;
tx=(int)refPointX-(int)middleX;
ty=(int)refPointY-(int)middleY;

//FIND tx & ty FOR ALIGNMENT END
//******************************************************************************
//PUT BACK ORI IMAGE, surfaceOriGray
for (x=0; x<width; x++)
91
for (y=0; y<height; y++)
{
arraySurfaceIn[x][y]=getpixel(surfaceOriGray, x, y);
arraySegment[x][y]=getpixel(surfaceOriGray, x, y);
}
//=============================================================================
//TRANSLATE IMAGE
if ( (tx<0) && (ty<0) )
{
tx=abs(tx);
ty=abs(ty);
for (x=0; x<width-tx; x++)
for (y=0; y<height-ty; y++)
{
arraySurfaceInAligned[x][y]=arraySurfaceIn[x+tx][y+ty];
arraySegmentAligned[x][y]=arraySegment[x+tx][y+ty];
}
}
else if (tx<0)
{
tx=abs(tx);
for (x=0; x<width-tx; x++)
for (y=0; y<height-ty; y++)
{
arraySurfaceInAligned[x][y+ty]=arraySurfaceIn[x+tx][y];
arraySegmentAligned[x][y+ty]=arraySegment[x+tx][y];
}
}
else if (ty<0)
{
ty=abs(ty);
for (x=0; x<width-tx; x++)
for (y=0; y<height-ty; y++)
{
arraySurfaceInAligned[x+tx][y]=arraySurfaceIn[x][y+ty];
arraySegmentAligned[x+tx][y]=arraySegment[x][y+ty];
}
}
else
{
for (x=0; x<width-tx; x++)
for (y=0; y<height-ty; y++)
{
arraySurfaceInAligned[x+tx][y+ty]=arraySurfaceIn[x][y];
arraySegmentAligned[x+tx][y+ty]=arraySegment[x][y];

//TRANSLATE IMAGE END
//============================================================================
//resize image
for (x=0; x<widthResize; x++)
for (y=0; y<heightResize; y++)
{
putpixel(surfaceOut0, x,y,arraySurfaceInAligned[x][y]);
putpixel(surfaceOut, x,y,arraySegmentAligned[x][y]);
}
92
//free array
for (i = 0; i < width; i++)
{
free(arraySurfaceIn[i]);
free(arraySegment[i]);
free(arraySurfaceInAligned[i]);
free(arraySegmentAligned[i]);
}
free(arraySurfaceIn);
free(arraySegment);
free(arraySurfaceInAligned);
free(arraySegmentAligned);
}
From: us on
"marlina " <marlinayakno(a)gmail.com> wrote in message <i3oeg2$8j0$1(a)fred.mathworks.com>...
> Hi all,
>
> Anyone could help me on translate this programming ROI detection written in Visual C into Matlab?
> Actually this code about hand vein ROI extraction.
>
> Thank you

a hint:
- extract the algorithm as pseudo-code
- rewrite the sequence in ML language
- advantages:
you'll learn a lot about ML coding
you may be able to optimize the algorithm
- disadvantage:
the ML function most likely will be slower

us