📄 new_radon.h
字号:
struct RadonResult
{
int centre_x;
int centre_y;
int theta;
int coordinatex;
int rect_length;
int avernum;
};
#define cornernum 180
BOOL newradon(int **pic,int *row,int *col,int *outpic)
{
int num;
int theta;
for (int i=0;i<*col;i++)
{//计算均值
num=0;
outpic[i]=0;
for (int j=0;j<*row;j++)
{
if (pic[j][i]!=256&&pic[j][i]!=0)
{
outpic[i]=outpic[i]+pic[j][i];
num++;
}
}
if (num==0)
outpic[i]=0;
else
outpic[i]=(int)(outpic[i]*180*180/(float)(num*num*num));
//计算方差
/*
theta=0;
for (int k=0;k<*row;k++)
{
if (pic[k][i]!=256)
{
theta=theta+pow((pic[k][i]-outpic[i]/(float)num),2);
}
}
if (num==0)
outpic[i]=0;
else
{
theta=(int)sqrt(theta/(float)num)*(100/(float)num);
outpic[i]=theta*outpic[i];
}*/
}
return TRUE;
}
void Radon(unsigned char **pic,int row,int col,&result[num])
{
int row,col;
int Xb,Yb,Ix,Iy;
float *x,*y,*theta_sin,*theta_cos;
int **temp;//用于存储投影后图象
int **temppic;//存储旋转后的图象
static count=0;
// FILE *stream;
rhoMax=(int)(sqrt((col)*(col)+(row)*(row)));
//==用于坐标平移的辅助矩阵====
x=new float [rhoMax];
y=new float [rhoMax];
for(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);
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));
//=====================为用于存储投影后图象的矩阵分配空间,并附0====
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;
//========================================================================
temppic = new int *[rhoMax];
for (int i=0;i<rhoMax;i++)
temppic[i] = new int [rhoMax];
for (i=0;i<rhoMax;i++)
for (int j=0;j<rhoMax;j++)
temppic[i][j]=256; //将用于存储旋转后图象的矩阵附初值256
//====================进行旋转变换===================
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]=(int)pic[j][i];
}
}
newradon(temppic,&rhoMax,&rhoMax,temp[k]);
}
//=========================================
int min=0;//最小值
int min_thetanum=0,min_rhoMaxnum=0;
for (i=0;i<cornernum;i++)
for (int j=0;j<rhoMax;j++)
{
if (temp[i][j]!=0)
{
if (temp[i][j]>min)
{
max=temp[i][j];
max_thetanum=i;
max_rhoMaxnum=j;
}
}
}
//========除去局部其他的极小值================
for (int p=0;p<10;p++)
for (int q=0;q<10;q++)
if ((max_thetanum+p-5)>=0&&(max_thetanum+p-5)<*cornernum&&(max_rhoMaxnum+q-5)>=0&&(max_rhoMaxnum+q-5)<*rhoMax)
{
temp[max_thetanum+p-5][max_rhoMaxnum+q-5]=0;
}
//===========释放空间===========
delete [] x;
delete [] y;
delete [] theta_sin;
delete [] theta_cos;
for (i=0;i<rhoMax;i++)
delete [] temppic[i];
delete [] temppic;
//dspace_2d(temppic,rhoMax,rhoMax);
return temp;
}
BOOL DigRectImage(char *OutputFileName,int theta)
{
//==========分配临时空间==============
unsigned char **TempImg=NULL;
TempImg=fspace_2d(outputRow,outputCol);
if (TempImg==NULL)
return FALSE;
//=========计算矩形框的中心及边长=============
int rect_centre=75;
int rect_length=71;
//=========原始图象大小===============
int Row,Col;
int Org_centrex,Org_centrey;
org_centrex=(int)Col/2.0;
org_centrey=(int)Row/2.0;
//=========计算扫描的矩形数=====
RadonResult *result;
int rect_num=(int)360/(float)theta;
result = new RadonResult [rect_num];
//=============================
int i,j,num=0; //临时循环变量
for (int angle=0;angle<360;angle=angle+theta)
{
i=org_centrex-rect_centre*sin(angle*3.1416/180.0);
j=org_centrey-rect_centre*cos(angle*3.1416/180.0);
//====挖图过程
for (int k=0;k<rect_length;k++)
for (int l=0;l<rect_length;l++)
{
TempImg[k][l]=input.p[i+k-35][j+l-35];
}
//=============进行RADON变换,最后结果为(angle,x)===
//result[num].centre_x=i;
//result[num].centre_y=j
//Radon(TempImg,rect_length,rect_length,&result[num])
//num++;
//==================================================
dspace_2d(TempImg,rect_length,rect_length);
}
//====程序结束
if (TempImg!=NULL)
dspace_2d(TempImg,outputRow,outputCol);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -