📄 mean5x5.c
字号:
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//东南H8
void h8prewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9;
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp2 = (*(inputbuffer16+i-cols))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp4 = (*(inputbuffer16+i-1 ))&0xff00;
temp6 = (*(inputbuffer16+i+1 ))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp7 = (*(inputbuffer16+i+cols-1))&0xff00;
temp8 = (*(inputbuffer16+i+cols))&0xff00;
temp9 = (*(inputbuffer16+i+cols+1))&0xff00;
temp = temp1 + temp2 + temp3 +temp4-(temp5<<1) - temp6+temp7-temp8 - temp9;
temp=abs(temp);
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//hprewitt
void hprewitt(Uint16 * inputbuffer16,Uint16 * outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 temp,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9;
Int32 h1temp,h2temp,h3temp,h4temp,h5temp,h6temp,h7temp,h8temp;
for( i=cols; i<cols*rows-cols; i++ ) //区域模板运算
{
temp1 = (*(inputbuffer16+i-cols-1))&0xff00;
temp2 = (*(inputbuffer16+i-cols))&0xff00;
temp3 = (*(inputbuffer16+i-cols+1))&0xff00;
temp4 = (*(inputbuffer16+i-1 ))&0xff00;
temp6 = (*(inputbuffer16+i+1 ))&0xff00;
temp5 = (*(inputbuffer16+i))&0xff00;
temp7 = (*(inputbuffer16+i+cols-1))&0xff00;
temp8 = (*(inputbuffer16+i+cols))&0xff00;
temp9 = (*(inputbuffer16+i+cols+1))&0xff00;
h1temp = temp1 + temp2 - temp3 +temp4-(temp5<<1) - temp6+temp7+temp8 - temp9;
h2temp = temp1 - temp2 - temp3 +temp4-(temp5<<1) - temp6+temp7+temp8 + temp9;
h3temp = - temp1 - temp2 - temp3 + temp4 -(temp5<<1) + temp6 + temp7 + temp8 + temp9;
h4temp = - temp1 - temp2 + temp3 - temp4 - (temp5<<1) + temp6 + temp7 + temp8 + temp9;
h5temp = - temp1 + temp2 + temp3 - temp4 - (temp5<<1) + temp6 - temp7 + temp8 + temp9;
h6temp = temp1 + temp2 + temp3 - temp4-(temp5<<1) + temp6 - temp7 - temp8 + temp9;
h7temp = temp1 + temp2 + temp3 +temp4-(temp5<<1) + temp6 - temp7 - temp8 - temp9;
h8temp = temp1 + temp2 + temp3 +temp4-(temp5<<1) - temp6+temp7-temp8 - temp9;
temp=h1temp+h2temp+h3temp+h4temp+h5temp+h6temp+h7temp+h8temp;
temp=abs(temp)/4;
if(temp > 0xff00)
*(Uint16 *)(outputbuffer16+i) = 0xff80;
else
*(Uint16 *)(outputbuffer16+i) = (((Uint16)temp)&0xff00) + 0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16 + i) = *((Uint16 *)outputbuffer16-cols+i);
}
//prewitt5x5
//prewitt5x5_1
void prewitt5x5_1(Uint16 *inputbuffer16,Uint16 *outputbuffer16,int cols,int rows)
{
int i;
Int32 temp,temp0,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp10,temp11,temp12,temp13;
Int32 temp14,temp15,temp16,temp17,temp18,temp19,temp20,temp21,temp22,temp23,temp24,temp25; //模板元素定义
for (i=cols;i<cols*rows-cols;i++) //区域模板运算
{ temp1=(*(inputbuffer16+i-2*cols-2))&0xff00;
temp2=(*(inputbuffer16+i-2*cols-1))&0xff00;
temp3=(*(inputbuffer16+i-2*cols))&0xff00;
temp4=(*(inputbuffer16+i-2*cols+1))&0xff00;
temp5=(*(inputbuffer16+i-2*cols+2))&0xff00;
temp6=(*(inputbuffer16+i-cols-2))&0xff00;
temp7=(*(inputbuffer16+i-cols-1))&0xff00;
temp8=(*(inputbuffer16+i-cols))&0xff00;
temp9=(*(inputbuffer16+i-cols+1))&0xff00;
temp10=(*(inputbuffer16+i-cols+2))&0xff00;
temp11=(*(inputbuffer16+i-2))&0xff00;
temp12=(*(inputbuffer16+i-1))&0xff00;
temp14=(*(inputbuffer16+i+1))&0xff00;
temp15=(*(inputbuffer16+i+2))&0xff00;
temp16=(*(inputbuffer16+i+cols-2))&0xff00;
temp17=(*(inputbuffer16+i+cols-1))&0xff00;
temp18=(*(inputbuffer16+i+cols))&0xff00;
temp19=(*(inputbuffer16+i+cols+1))&0xff00;
temp20=(*(inputbuffer16+i+cols+2))&0xff00;
temp21=(*(inputbuffer16+i+2*cols-2))&0xff00;
temp22=(*(inputbuffer16+i+2*cols-1))&0xff00;
temp23=(*(inputbuffer16+i+2*cols))&0xff00;
temp24=(*(inputbuffer16+i+2*cols+1))&0xff00;
temp25=(*(inputbuffer16+i+2*cols+2))&0xff00;
temp=temp1+temp2-temp4-temp5+temp6+temp7-temp9-temp10+temp11+temp12-temp14-temp15+temp16+temp17-temp19-temp20+temp21+temp22-temp24-temp25; //列梯度
temp0=-temp1-temp2-temp3-temp4-temp5-temp6-temp7-temp8-temp9-temp10+temp16+temp17+temp18+temp19+temp20+temp21+temp22+temp23+temp24+temp25; //行梯度
temp=temp;
temp0=temp0;
temp=(temp+temp0)/2;
if(temp>0xff00)
*(Uint16 *)(outputbuffer16+i)=0xff80;
else
*(Uint16 *)(outputbuffer16+i)=(((Uint16)temp)&0xff00)+0x80;
}
for(i=0;i<cols;i++) //边界处理
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16+cols+i);
for(i=cols*rows-cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16-cols+i);
}
//prewitt5x5_2
void prewitt5x5_2(Uint16 *inputbuffer16,Uint16 *outputbuffer16,int cols,int rows)
{
int i;
Int32 temp,temp0,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp10,temp11,temp12,temp13;
Int32 temp14,temp15,temp16,temp17,temp18,temp19,temp20,temp21,temp22,temp23,temp24,temp25; //模板元素定义
for (i=2*cols;i<cols*rows-2*cols;i++) //区域模板运算
{ temp1=(*(inputbuffer16+i-2*cols-2))&0xff00;
temp2=(*(inputbuffer16+i-2*cols-1))&0xff00;
temp3=(*(inputbuffer16+i-2*cols))&0xff00;
temp4=(*(inputbuffer16+i-2*cols+1))&0xff00;
temp5=(*(inputbuffer16+i-2*cols+2))&0xff00;
temp6=(*(inputbuffer16+i-cols-2))&0xff00;
temp7=(*(inputbuffer16+i-cols-1))&0xff00;
temp8=(*(inputbuffer16+i-cols))&0xff00;
temp9=(*(inputbuffer16+i-cols+1))&0xff00;
temp10=(*(inputbuffer16+i-cols+2))&0xff00;
temp11=(*(inputbuffer16+i-2))&0xff00;
temp12=(*(inputbuffer16+i-1))&0xff00;
temp14=(*(inputbuffer16+i+1))&0xff00;
temp15=(*(inputbuffer16+i+2))&0xff00;
temp16=(*(inputbuffer16+i+cols-2))&0xff00;
temp17=(*(inputbuffer16+i+cols-1))&0xff00;
temp18=(*(inputbuffer16+i+cols))&0xff00;
temp19=(*(inputbuffer16+i+cols+1))&0xff00;
temp20=(*(inputbuffer16+i+cols+2))&0xff00;
temp21=(*(inputbuffer16+i+2*cols-2))&0xff00;
temp22=(*(inputbuffer16+i+2*cols-1))&0xff00;
temp23=(*(inputbuffer16+i+2*cols))&0xff00;
temp24=(*(inputbuffer16+i+2*cols+1))&0xff00;
temp25=(*(inputbuffer16+i+2*cols+2))&0xff00;
temp=temp1+temp2-temp4-temp5+temp6+(temp7<<1)-(temp9<<1)-temp10+temp11+(temp12/3)-temp14-(temp15/3)+temp16+(temp17<<1)-(temp19<<1)-
temp20+temp21+temp22-temp24-temp25; //列梯度
temp0=-temp1-temp2-temp3-temp4-temp5-temp6-(temp<<1)-(temp8/3)-(temp9<<1)-temp10+temp16+(temp17<<1)+(temp18/3)+(temp19<<1)
+temp20+temp21+temp22+temp23+temp24+temp25; //行梯度
temp=abs(temp);
temp0=abs(temp0);
temp=(temp+temp0)/4;
if(temp>0xff00)
*(Uint16 *)(outputbuffer16+i)=0xff80;
else
*(Uint16 *)(outputbuffer16+i)=(((Uint16)temp)&0xff00)+0x80;
}
for(i=0;i<2*cols;i++) //边界处理
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16+2*cols+i);
for(i=cols*rows-2*cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16-2*cols+i);
}
//prewitt7x7
void prewitt7x7_1(Uint16 *inputbuffer16,Uint16 *outputbuffer16,int cols,int rows) //模板元素定义
{
int i;
Int32 htemp,ltemp,temp;
Int32 temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp10,temp11,temp12,temp13;
Int32 temp14,temp15,temp16,temp17,temp18,temp19,temp20,temp21,temp22,temp23,temp24,temp25;
Int32 temp26,temp27,temp28,temp29,temp30,temp31,temp32,temp33,temp34,temp35,temp36,temp37,temp38;
Int32 temp39,temp40,temp41,temp42,temp43,temp44,temp45,temp46,temp47,temp48,temp49;
for (i=3*cols;i<cols*rows-3*cols;i++) //区域模板运算
{ temp1=(*(inputbuffer16+i-3*cols-3))&0xff00;
temp2=(*(inputbuffer16+i-3*cols-2))&0xff00;
temp3=(*(inputbuffer16+i-3*cols-1))&0xff00;
temp4=(*(inputbuffer16+i-3*cols))&0xff00;
temp5=(*(inputbuffer16+i-3*cols+1))&0xff00;
temp6=(*(inputbuffer16+i-3*cols+2))&0xff00;
temp7=(*(inputbuffer16+i-3*cols+3))&0xff00;
temp8=(*(inputbuffer16+i-2*cols-3))&0xff00;
temp9=(*(inputbuffer16+i-2*cols-2))&0xff00;
temp10=(*(inputbuffer16+i-2*cols-1))&0xff00;
temp11=(*(inputbuffer16+i-2*cols))&0xff00;
temp12=(*(inputbuffer16+i-2*cols+1))&0xff00;
temp13=(*(inputbuffer16+i-2*cols+2))&0xff00;
temp14=(*(inputbuffer16+i-2*cols+3))&0xff00;
temp15=(*(inputbuffer16+i-cols-3))&0xff00;
temp16=(*(inputbuffer16+i-cols-2))&0xff00;
temp17=(*(inputbuffer16+i-cols-1))&0xff00;
temp18=(*(inputbuffer16+i-cols))&0xff00;
temp19=(*(inputbuffer16+i-cols+1))&0xff00;
temp20=(*(inputbuffer16+i-cols+2))&0xff00;
temp21=(*(inputbuffer16+i-cols+3))&0xff00;
temp22=(*(inputbuffer16+i-3))&0xff00;
temp23=(*(inputbuffer16+i-2))&0xff00;
temp24=(*(inputbuffer16+i-1))&0xff00;
temp26=(*(inputbuffer16+i+1))&0xff00;
temp27=(*(inputbuffer16+i+2))&0xff00;
temp28=(*(inputbuffer16+i+3))&0xff00;
temp29=(*(inputbuffer16+i+cols-3))&0xff00;
temp30=(*(inputbuffer16+i+cols-2))&0xff00;
temp31=(*(inputbuffer16+i+cols-1))&0xff00;
temp32=(*(inputbuffer16+i+cols))&0xff00;
temp33=(*(inputbuffer16+i+cols+1))&0xff00;
temp34=(*(inputbuffer16+i+cols+2))&0xff00;
temp35=(*(inputbuffer16+i+cols+3))&0xff00;
temp36=(*(inputbuffer16+i+2*cols-3))&0xff00;
temp37=(*(inputbuffer16+i+2*cols-2))&0xff00;
temp38=(*(inputbuffer16+i+2*cols-1))&0xff00;
temp39=(*(inputbuffer16+i+2*cols))&0xff00;
temp40=(*(inputbuffer16+i+2*cols+1))&0xff00;
temp41=(*(inputbuffer16+i+2*cols+2))&0xff00;
temp42=(*(inputbuffer16+i+2*cols+3))&0xff00;
temp43=(*(inputbuffer16+i+3*cols-3))&0xff00;
temp44=(*(inputbuffer16+i+3*cols-2))&0xff00;
temp45=(*(inputbuffer16+i+3*cols-1))&0xff00;
temp46=(*(inputbuffer16+i+3*cols))&0xff00;
temp47=(*(inputbuffer16+i+3*cols+1))&0xff00;
temp48=(*(inputbuffer16+i+3*cols+2))&0xff00;
temp49=(*(inputbuffer16+i+3*cols+3))&0xff00;
htemp=temp1+temp2+temp3+temp8+temp9+temp10+temp15+temp16+temp17+temp22+temp23+temp24+temp29+temp30+temp31+temp36+temp37+temp38+temp43+temp44+temp45
-temp5-temp6-temp7-temp12-temp13-temp14-temp19-temp20-temp21-temp26-temp27-temp28-temp33-temp34-temp35-temp40-temp41-temp42-temp47-temp48-temp49; //列梯度
ltemp=-temp1-temp2-temp3-temp4-temp5-temp6-temp7-temp6-temp9-temp10-temp11-temp12-temp13-temp14-temp15-temp16-temp17-temp18-temp19-temp20-
temp21+temp29+temp30+temp31+temp32+temp33+temp34+temp35+temp36+temp37+temp38+temp39+temp40+temp41+temp42+temp43+temp44+temp45+temp46+temp47+temp48+temp49; //行梯度
htemp=abs(htemp);
ltemp=abs(ltemp);
temp=(temp+temp)/4;
if(temp>0xff00)
*(Uint16 *)(outputbuffer16+i)=0xff80;
else
*(Uint16 *)(outputbuffer16+i)=(((Uint16)temp)&0xff00)+0x80;
}
for(i=0;i<3*cols;i++) //边界处理
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16+3*cols+i);
for(i=cols*rows-3*cols;i<cols*rows;i++)
*((Uint16 *)outputbuffer16+i)=*((Uint16 *)outputbuffer16-3*cols+i);
}
//end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -