当前位置:文档之家› 系统实验(DSP)--图像的锐化处理、图像的边缘检测

系统实验(DSP)--图像的锐化处理、图像的边缘检测

DSP 实验报告
一、 图像的锐化处理(高通滤波处理)
1、 实验原理
处理模板如下:
⎥⎥⎥⎦
⎤⎢⎢⎢⎣⎡--+--=004100
ααα
ααM 25.0=α
对应数学表达式:
()[])1,(),1()1,(),1(),(41),(++++-+--+=y x f y x f y x f y x f y x f y x g αα
2、 C 程序及运行结果
程序:
Acute_RGB_Image(int *buffer)
{
int x,y;
for (y=0;y<ImageHeight;y++)
for (x=0;x<ImageWidth;x++)
{
buffer[y*ImageWidth+x]=2*buffer[y*ImageWidth+x]-(buffer[y*ImageWidth+x-1]+b uffer[(y-1)*ImageWidth+x]+buffer[y*ImageWidth+x+1]+buffer[(y+1)*ImageWidth+x])/4;
if(buffer[ImageWidth*y+x]>255)
buffer[ImageWidth*y+x]=255;
else if (buffer[ImageWidth*y+x]<0)
buffer[ImageWidth*y+x]=0;
}
}
运行结果:
锐化前锐化后
分析:从上面两幅图可以看出锐化后的图像轮廓变得明显,且噪声变得强烈。

3、汇编程序及运行结果
程序:
ImageAcuteSub(ImageWidth,ImageHeight,buffer_red);
ImageAcuteSub(ImageWidth,ImageHeight,buffer_green);
ImageAcuteSub(ImageWidth,ImageHeight,buffer_blue);
.mmregs
.def _ImageAcuteSub
.text
_ImageAcuteSub:
mov t0,brc1 ;IMAGE WIDTH
mov t1,brc0 ;IMAGE HEIGHT
rptb y_loop
rptb x_loop
mov *ar0(#1),ac1;f(x+1,y)
add *ar0(#-1),ac1 ;f(x-1,y)
add *ar0(#-250),ac1 ;f(x,y-1)
add *ar0(#250),ac1 ;f(x,y+1)
sfts ac1,#-2
mov *ar0<<#1,ac0;2f(x,y)
sub ac1,ac0
bcc branch1,ac0<0
sub #255,ac0,ac1
bcc branch2,ac1>0
mov ac0,*ar0+
b x_loop
branch1: mov #0,*ar0+
b x_loop
branch2: mov #255,*ar0+
x_loop: nop
y_loop: nop
RET
运行结果:
锐化前 锐化后
分析:可以看出汇编的结果和C 程序的结果是一致的。

二、 图像的边缘检测
1、 实验原理
方向方向和y x 的梯度分别为: ⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡---=∆10110110131x f ⎥⎥⎥⎦
⎤⎢⎢⎢⎣⎡---=∆11100011131y f 总梯度幅度
y
x f f f ∆+∆=∆[]13||(1
,1)(1,)(1,1)(1,1)(1,)(1,1)x f f x y f x y f x y f x y f x y f x y ∆=+-+++++-------+[])1,1()1,()1,1()1,1()1,()1,1(||3
1
++-+-+---++-+--=∆y x f y x f y x f y x f y x f y x f f y ⎩⎨⎧≥∆=else T f if y x g 01),(
实验中的阈值设为120。

2、 C 程序及运行结果
程序:
Edge_Grey_Image()
{
int x,y;
int delta_x,delta_y;
for (y=0;y<ImageHeight;y++)
for (x=0;x<ImageWidth;x++)
{
delta_x=abs(buffer_grey[ImageWidth*(y-1)+x+1]+buffer_grey[ImageWidth*y+x +1]+buffer_grey[ImageWidth*(y+1)+x+1]-buffer_grey[ImageWidth*(y-1)+x-1]-b uffer_grey[ImageWidth*y+x-1]-buffer_grey[ImageWidth*(y+1)+x-1])/3;
delta_y=abs(buffer_grey[ImageWidth*(y-1)+x-1]+buffer_grey[ImageWidth*(y-1)+x]+buffer_grey[ImageWidth*(y-1)+x+1]-buffer_grey[ImageWidth*(y+1)+x-1]-buffer_grey[ImageWidth*(y+1)+x]-buffer_grey[ImageWidth*(y+1)+x+1])/3;
if((delta_x+delta_y)>=Threshhold)
buffer_org[ImageWidth*y+x]=255;
else buffer_org[ImageWidth*y+x]=0;
}
}
运行结果:
边缘处理前边缘处理后
分析:从上面两幅图可以看出,原图像的边缘经过处理后可以很好的用白线来勾勒出,没有边缘的地方都用黑色表示,可以很清楚的从处理后的图片看出斑马的形状。

3、汇编程序及运行结果
程序:
ImageEdgeSub(ImageWidth,ImageHeight,buffer_org);
.mmregs
.def _ImageEdgeSub
.bss TEMP,1
.text
_ImageEdgeSub:
mov t0,BRC1
mov t1,BRC0
mov xar0,ac3
mov #256<<#11,ac2
mov ac2,xar1
RPTB Y_LOOP
RPTB X_LOOP
mov *ar0+,*ar1+;将ar0的内容复制到ar1里面
X_LOOP: nop
Y_LOOP: nop
mov t0,brc1 ;IMAGE WIDTH
mov t1,brc0 ;IMAGE HEIGHT
mov ac2,xar1
mov ac3,xar0
rptb y_loop
rptb x_loop
mov *ar1+,ac0
mov *ar1(#-149),ac0;f(x+1,y-1)
add *ar1(#1),ac0 ;f(x+1,y)
add *ar1(#151),ac0 ;f(x+1,y+1)
sub *ar1(#-151),ac0;f(x-1,y-1)
sub *ar1(#-1),ac0 ;f(x-1,y)
sub *ar1(#149),ac0;f(x-1,y+1)
abs ac0
mov *ar1(#-151),ac1 ;f(x-1,y-1)
add *ar1(#-150),ac1 ;f(x,y-1)
add *ar1(#-149),ac1 ;f(x+1,y-1)
sub *ar1(#149),ac1 ;f(x-1,y+1)
sub *ar1(#150),ac1 ;f(x,y+1)
sub *ar1(#151),ac1 ;f(x+1,y+1)
abs ac1
add ac1,ac0
call DIVION
sub #120,ac0,ac0
bcc branch1,ac0>0
mov #0,*ar0+
b x_loop
branch1: mov #255,*ar0+
x_loop: nop
y_loop: nop
RET
DIVION:
amov #080000h,XAR7
mov #3,*ar7
mov #16,t0
mov ac0,ac1
branch2: subc *ar7,ac1,ac2
mov ac2,ac1
sub #1,t0
bcc branch2,t0>0
mov ac1,t1
mov t1,ac0
RET
运行结果:
边缘处理前边缘处理后
分析:可以看出汇编的结果和C程序的结果是一致的。

相关主题