📄 omlib.cpp
字号:
a22 = cos(theta);
a21 =(-sin(theta));
if(dir == NOCLOCKWISE)
{
a12 *= -1;
a21 *= -1;
}
for( int i=0 ; i<dr; i++)
for( int j=0 ; j<dc; j++)
{
int m = int ( a11*(j - x0) + a12*(i - y0) ); // x
int n = int ( a21*(j - x0) + a22*(i - y0) ); // y
int x = int ( m + sx0 ) ;
int y = int ( n + sy0 );
if( x>=0 && x<sc && y>=0 && y<sr )
des[i][j] = src[y][x];
else
des[i][j] = nBackgrd;
}
*/
// Rotate matrix
BYTE **src;
src=input.p;
int sr,sc;
sr=input.row;
sc=input.col;
double a11, a12, a21, a22,theta;
theta=(corner/180.0*PI);
a11 =cos(theta);
a12 = sin(theta);
a22 = cos(theta);
a21 =(-sin(theta));
if(dir == NOCLOCKWISE)
{
a12 *= -1;
a21 *= -1;
}
double sx0 = sc / 2;
double sy0 = sr / 2;
double rad = sqrt(sx0*sx0+sy0*sy0);
double alpha0 = atan( sr /(double) sc );
double alphaY =( alpha0 + theta);
double alphaX = alpha0 - theta;
dr = (int) abs(2*rad*sin(alphaY) + 1);
dc = (int) abs(2*rad*cos(alphaX) + 1);
double x0 = dc/2.0;
double y0 = dr/2.0;
BYTE ** des =fspace_2d(dr,dc);
for( int i=0 ; i<dr; i++)
for( int j=0 ; j<dc; j++)
{
int m = int ( a11*(j - x0) + a12*(i - y0) ); // x
int n = int ( a21*(j - x0) + a22*(i - y0) ); // y
int x = int ( m + sx0 ) ;
int y = int ( n + sy0 );
if( x>=0 && x<sc && y>=0 && y<sr )
des[i][j] = src[y][x];
else
des[i][j] = nBackgrd;
}
return des ;
}
//===========LOG======
BOOL Log(int m_log_k,double m_log_sigma,Picture input,Picture output)
{
int i,j,k;
int row=input.row;//图象row
int col=input.col;//图象col
BYTE **m_gray;
m_gray=input.p;
// TODO: Add your command handler code here
int m_half=(int)(3*sqrt(2)*m_log_sigma+0.5);
int* m_ha=new int[m_half];
int* m_hb=new int[m_half];
float fun;
float fun2;
for( i=0;i<m_half;i++)
{
fun=float(i*i);
fun2=fun;
fun=(float)((1-fun/(m_log_sigma*m_log_sigma))*exp(-fun/(2*m_log_sigma*m_log_sigma)));
m_ha[i]=(int)(fun*sqrt(m_log_k));
fun2=(float)exp(-fun2/m_log_sigma);
m_hb[i]=(int)(sqrt(m_log_k)*fun2);
}
long** m_logsa;
m_logsa=new long *[row];
for(i=0; i<row;i++)
m_logsa[i] = new long[col];
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
m_logsa[i][j]=0;
}
long**m_logsb;
m_logsb=new long *[row];
for ( i =0;i<row;i++)
m_logsb[i]=new long[col];
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
m_logsb[i][j]=0;
}
int *m_rowline =new int[col+2*m_half];
int *m_colline =new int[row+2*m_half];
for(i=0;i<m_half;i++)
{
m_rowline[i]=0;m_rowline[col+m_half+i]=0;
m_colline[i]=0;m_colline[row+m_half+i]=0;
}
long sum;
for(i=0;i<row;i++)
{
for(k=m_half;k<m_half+col;k++)
{
m_rowline[k]=m_gray[i][k-m_half];
}
for(j=0;j<col;j++)
{
sum=m_ha[0]*m_rowline[j+m_half];
for(k=1;k<m_half;k++)
{
sum=sum+m_ha[k]*(m_rowline[j+m_half-k]+m_rowline[j+m_half+k]);
}
m_logsa[i][j]=(int)sum;
}//end for(j);
}//end for(i)
for(j=0;j<col;j++)
{
for(k=m_half;k<m_half+row;k++)
{
m_colline[k]=m_logsa[k-m_half][j];
}
for(i=0;i<row;i++)
{
sum=m_hb[0]*m_colline[i+m_half];
for(k=1;k<m_half;k++)
sum=sum+m_hb[k]*(m_colline[i+m_half+k]+m_colline[i+m_half-k]);
m_logsb[i][j]=(int)sum;
}//end for(i)
}//end for(j);
////second translation
for(i=0;i<m_half;i++)
{
m_rowline[i]=0;m_rowline[col+m_half+i]=0;
m_colline[i]=0;m_colline[row+m_half+i]=0;
}//end for
for(i=0;i<row;i++)
{
for(k=m_half;k<m_half+col;k++)
{
m_rowline[k]=m_gray[i][k-m_half];
}
for(j=0;j<col;j++)
{
sum=m_hb[0]*m_rowline[j+m_half];
for(k=1;k<m_half;k++)
{
sum=sum+m_hb[k]*(m_rowline[j+m_half-k]+m_rowline[j+m_half+k]);
}
m_logsa[i][j]=(int)sum;
}//end for(j);
}
for(j=0;j<col;j++)
{
for(k=m_half;k<m_half+row;k++)
{
m_colline[k]=m_logsa[k-m_half][j];
}
for(i=0;i<row;i++)
{
sum=m_ha[0]*m_colline[i+m_half];
for(k=1;k<m_half;k++)
{
sum=sum+m_ha[k]*(m_colline[i+m_half+k]+m_colline[i+m_half-k]);
}
m_logsb[i][j]=sum+m_logsb[i][j];
}//end for(i)
}//end for(j);
for(i=1;i<row-1;i++)
for(j=1;j<col-1;j++)
{
//m_gray[i][j]=0;
if(m_logsb[i][j-1]<0&&m_logsb[i][j]>0)
{
output.p[i][j]=255;
}
if(m_logsb[i][j-1]>0&&m_logsb[i][j]<0)
{
output.p[i][j]=255;
}
if(m_logsb[i-1][j]<0&&m_logsb[i][j]>0)
{
output.p[i][j]=255;
}
if(m_logsb[i-1][j]>0&&m_logsb[i][j]<0)
{
output.p[i][j]=255;
}
}
//处理后的结果
delete m_ha;
delete m_hb;
delete m_rowline;
delete m_colline;
for(i=0;i<row;i++)
delete[] m_logsa[i];
for(i=0;i<row;i++)
delete[] m_logsb[i];
return TRUE;
}
BOOL Extraction8(CString InputFileName,CString OutputFileName)
{
Picture input;
BYTE** temp;
// int tempx;
input.p=InputImageWithName(InputFileName,input.row ,input.col );
if (input.p==NULL)
return FALSE;
temp=fspace_2d(input.row,input.col);
if (temp==NULL)
return FALSE;
for (int k=0;k<5;k++)
{
for(int i=0;i<input.row;i++)
for(int j=0;j<input.col;j++)
{
temp[i][j]=input.p[i][j]&127;//(31<<k);
if(temp[i][j]!=0)
temp[i][j]=255;
}
::OutputImageWithName(temp,input.row,input.col,OutputFileName);
ChangeNameExtension(OutputFileName);
}
dspace_2d(temp,input.row,input.col);
return TRUE;
}
int ChangeNameExtension(const char *s1)
{
int i,j;
char *ExtendedName;
int length;
length=strlen(s1);
if ((ExtendedName=strchr(s1,'.'))==NULL)
{
return -1;
}
ExtendedName++;
if (*ExtendedName>'9' || *ExtendedName<'0')
return -1;
for (i=s1+length-ExtendedName-1;i>=0;i--)
{
if (*(ExtendedName+i)<'9')
{
(*(ExtendedName+i))++;
j=i+1;
while (j<s1+length-ExtendedName)
{
(*(ExtendedName+j))='0';
j++;
}
return 1;
}
}
return 0;
}
int ChangeNameExtension1(const char *s1)
{
int i,j;
char temp[5];
int length=strlen(s1);
for(i=0;i<4;i++)
{
temp[i]=*(s1+length-8+i);
}
temp[4]='\0';
for (i=3;i>=0;i--)
{
if (*(temp+i)<'9')
{
(*(temp+i))++;
j=i+1;
while (j<4)
{
(*(temp+j))='0';
j++;
}
strncpy( (char *)s1+length-8,temp, 4 );
return 1;
}
}
return 0;
}
int ChangeFloatName(const char *s1)
{
int i,j,k;
char *temp=NULL;
int length=strlen(s1);
temp=(char *)(s1+length-4);
for (i=3;i>=0;i--)
{
if (*(temp+i)<'9')
{
(*(temp+i))++;
j=i+1;
while (j<4)
{
(*(temp+j))='0';
j++;
}
return 1;
}
}
return 0;
}
BOOL rradon(unsigned char **pic,int *row,int *col,int *outpic)
{
/*
for (int i=0;i<*col;i++)
for (int j=0;j<*row;j++)
{
outpic[i]=outpic[i]+pic[j][i];
}
return TRUE;
*/
int num=0;
for (int i=0;i<*col;i++)
{
num=0;
for (int j=0;j<*row;j++)
{
if (pic[j][i]==0)
{
outpic[i]++;
}
// if(pic[j][i]!=100)
{
// num++;
}
}
// if(num==0)
// outpic[i]=0;
// else
// outpic[i]=(int)(outpic[i]*100/(float)num);
}
return TRUE;
}
int **RRadon(Picture input,int *step0,int &cornernum,int &rhoMax)
{
unsigned char **pic;
int row,col;
float step;
pic=input.p;
row=input.row;
col=input.col;
step=float(1.0/(float)(*step0));
int Xb,Yb,Ix,Iy;
float *x,*y,*theta_sin,*theta_cos;
int **temp;
unsigned char **temppic;
static count=0;
rhoMax=(int)(sqrt((col)*(col)+(row)*(row)));
temppic=fspace_2d(rhoMax,rhoMax);
x=new float [rhoMax];
y=new float [rhoMax];
for(int i=0; i<row; i++)
x[i] = (float)(i-(col)/2.0);
for(i=0; i<col; i++)
y[i] = (float)(i-(row)/2.0);
cornernum=(int)(180/(step));
theta_sin =new float [cornernum];
theta_cos =new float [cornernum];
for (i=0;i<cornernum;i++)
theta_sin[i]=(float)sin(((float)i)*PI/((float)cornernum));
for (i=0;i<cornernum;i++)
theta_cos[i]=(float)cos(((float)i)*PI/((float)cornernum));
temp=new int *[cornernum];
for (i=0;i<cornernum;i++)
{
temp[i]=new int [rhoMax];
}
for (i=0;i<cornernum;i++)
for (int j=0;j<rhoMax;j++)
temp[i][j]=0;
for (i=0;i<rhoMax;i++)
for (int j=0;j<rhoMax;j++)
temppic[i][j]=100;
for (int k=0;k<cornernum;k++)
{
for (i=0;i<col;i++)
{
for (int j=0;j<row;j++)
{
Xb=(int)(x[i]*(theta_cos[k])-y[j]*(theta_sin[k]));//xb对应着col
Yb=(int)(-x[i]*(theta_sin[k])-y[j]*(theta_cos[k]));//yb对应着row
Ix=Xb+(int)(rhoMax/2.0);
Iy=Yb+(int)(rhoMax/2.0);
if(rhoMax-Iy-1<rhoMax&&Ix<rhoMax&&rhoMax-Iy-1>=0&&Ix>=0)
temppic[rhoMax-Iy-1][Ix]=pic[j][i];
}
}
rradon(temppic,&rhoMax,&rhoMax,temp[k]);
}
//=========================================
//===========释放空间===========
delete [] x;
delete [] y;
delete [] theta_sin;
delete [] theta_cos;
dspace_2d(temppic,rhoMax,rhoMax);
int nnn=0;
for (i=0;i<cornernum;i++)
for (int j=0;j<rhoMax;j++)
{
if (temp[i][j]>70)
nnn++;
}
return temp;
}
void HOF(unsigned char **OrigImg, unsigned char **SmoothImg, int Row, int Col)
{
const int grayLevel=256;
int i,j;
int k,m;
int n=1; /*平滑窗口尺寸*/
int x=0; /*记录迭代次数*/
int s; /*记录和值的临时变量*/
int h0; /*记录中心区域的均匀性*/
int h1; /*记录左上区域的均匀性*/
int h2; /*记录右上区域的均匀性*/
int h3; /*记录左下区域的均匀性*/
int h4; /*记录右下区域的均匀性*/
int imageWidth; /*波门尺寸*/
int imageHeight;
int a; /*标记循环是否结束?a=1时迭代结束*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -