《多媒体软件设计技术》课程设计报告.docx
《《多媒体软件设计技术》课程设计报告.docx》由会员分享,可在线阅读,更多相关《《多媒体软件设计技术》课程设计报告.docx(11页珍藏版)》请在冰豆网上搜索。
《多媒体软件设计技术》课程设计报告
《多媒体软件设计技术》课程设计报告
学号
姓名
Email
项目名称
利用VB进行图像处理滤镜
本项目功能及目标
实现4个滤镜效果:
浮雕、油画、木刻、灯光。
其中浮雕深度效果可通过拉杆改变调节,灯光位置调节使用鼠标单击。
设计思路及其算法
根据教程P153页图像的滤镜效果。
VB中有两个操作像素的基本方法:
Pset和Point。
使用PSet方法可以生成像素,使用Point可以读取像素值,并在显示器上显示的颜色用RGB的值来表示。
首先,新建一个窗体Form1,在窗体上建立两个图片框picture1和picture2(picture1为经过滤镜处理后的图像,picture2为原图片),将其autosize的值设为true,然后用LoadPicture()命令给Picture1&2装入一副图像,在通过四个命令commond1,commond2,commond3,commond4的click事件调用过滤过程。
浮雕滤镜通过拉杆改变参数使浮雕效果发生改变,灯光通过单击鼠标获取鼠标坐标,将鼠标坐标作为参数传递给灯光滤镜,使灯光位置随鼠标移动。
浮雕滤镜的算法是:
在相邻像素的差值加上一个常数,使黑暗区域加亮一些,我们可以去同一行、同意列或对角线的相邻像素间的差值加一个常数。
油画滤镜的算法是:
用当前点四周一定范围内任一点的颜色来代替当前的颜色。
木刻滤镜算法是:
只需判断当前点是浅色还是深色即可,浅色用白色代替,深色用黑色代替。
灯光滤镜算法是:
取一点为光源,从光线末端开始想光源点逐渐增加亮度。
2源程序文件的组成
Lezg.jpg
工程1.vbp
Form1.frm
工程1.vbw
程序的源代码
Publicflag1AsInteger
Publicflag2AsInteger
‘标记
PrivateSubclear_Click()
'清除滤镜效果
Picture1.Picture=Picture2.Picture
‘清除标记
flag1=0
flag2=0
EndSub
'浮雕滤镜
PrivateSubCommand1_Click()
flag1=1
Dimpi1&,pi2&
Dimx,y
Dima,bAsLong
DimRed,Green,BlueAsInteger
a=1
b=1
xx=Picture1.ScaleWidth
yy=Picture1.ScaleHeight
Forx=1Toxx-2
Fory=1Toyy-2
pi1&=Picture1.Point(x,y)
pi2&=Picture1.Point(x+a,y+b)
Red=Abs((pi1&Mod256)-(pi2&Mod256)+128)
Green=Abs((((pi1&And&HFF00)/256&)Mod256&)-(((pi2&And&HFF00)/256&)Mod256&)+128)
Blue=Abs(((pi1&And&HFF0000)/65536)-((pi2&And&HFF0000)/65536)+128)
Picture1.PSet(x,y),RGB(Red,Green,Blue)
Nexty
Nextx
Picture1.Refresh
'Printflag1
EndSub
'油画滤镜
PrivateSubCommand2_Click()
Dimpi&
Dimx,y
Dima,bAsInteger
DimRed,Green,BlueAsInteger
xx=Picture1.ScaleWidth
yy=Picture1.ScaleHeight
Forx=2Toxx-3
Fory=2Toyy-3
a=Rnd*3-1
b=Rnd*3-1
pi=Picture1.Point(x+a,y+b)
Red=(pi&Mod256)
Green=(((pi&And&HFF00)/256&)Mod256&)
Blue=((pi&And&HFF0000)/65536)
Picture1.PSet(x,y),RGB(Red,Green,Blue)
Nexty
DoEvents
Nextx
Picture1.Refresh
EndSub
'木刻滤镜
PrivateSubCommand3_Click()
Dimpi&
Dimx,y
Dima,bAsInteger
DimRed,Green,BlueAsInteger
a=1
b=1
xx=Picture1.ScaleWidth
yy=Picture1.ScaleHeight
Forx=0Toxx
Fory=0Toyy
pi=Picture1.Point(x,y)
Red=(pi&Mod256)
Green=(((pi&And&HFF00)/256&)Mod256&)
Blue=((pi&And&HFF0000)/65536)
If(Red+Green+Blue)/3<128Then
Picture1.PSet(x,y),RGB(0,0,0)
Else
Picture1.PSet(x,y),RGB(255,255,255)
EndIf
Nexty
Nextx
Picture1.Refresh
EndSub
'灯光滤镜
PrivateSubCommand4_Click()
flag2=1‘标记启动灯光滤镜
Dimindex1AsInteger
Dimindex2AsInteger
index1=100
index2=100
CallDengguang(index1,index2)
'Printflag2
EndSub
PrivateSubForm_Load()
Form1.AutoRedraw=True
Form1.ScaleMode=3
flag1=0
flag2=0
EndSub
'浮雕拉杆调节参数
PrivateSubHScroll1_Change()
Ifflag1>0Then‘启动浮雕滤镜,才能通过拉杆改变浮雕效果
Picture1.Picture=Picture2.Picture
DimfdAsInteger
HScroll1.Min=5
HScroll1.Max=20
Text1.Text=HScroll1.Value
fd=HScroll1.Value
Dimpi1&,pi2&
Dimx,y
Dima,bAsLong
DimRed,Green,BlueAsInteger
a=fd/10
b=fd/10
xx=Picture1.ScaleWidth
yy=Picture1.ScaleHeight
Forx=1Toxx-2
Fory=1Toyy-2
pi1&=Picture1.Point(x,y)
pi2&=Picture1.Point(x+a,y+b)
Red=Abs((pi1&Mod256)-(pi2&Mod256)+128)
Green=Abs((((pi1&And&HFF00)/256&)Mod256&)-(((pi2&And&HFF00)/256&)Mod256&)+128)
Blue=Abs(((pi1&And&HFF0000)/65536)-((pi2&And&HFF0000)/65536)+128)
Picture1.PSet(x,y),RGB(Red,Green,Blue)
Nexty
Nextx
Picture1.Refresh
EndIf
EndSub
PrivateSubopen_Click()
Picture1.Picture=LoadPicture(App.Path+"\lezg.jpg")
Picture2.Picture=Picture1
Picture1.AutoRedraw=True
Picture2.AutoRedraw=True
Picture1.ScaleMode=3
Picture2.ScaleMode=3
'单位设为像素
Picture1.AutoSize=True
Picture2.Width=Picture1.Width
Picture2.Height=Picture1.Height
'自动调节Picture1和Picture2的大小
EndSub
'灯光滤镜
PrivateSubDengguang(ByRefin1AsInteger,ByRefin2AsInteger)
Dimpi1&,pi2&
DimX1,Y1
Dima,bAsInteger
DimRed,Green,BlueAsInteger
a=in1
b=in2
xx=Picture1.ScaleWidth
yy=Picture1.ScaleHeight
ForX1=1Toxx
ForY1=1Toyy
pi1=Picture1.Point(X1,Y1)
IfSqr((a-X1)*(a-X1)+(b-Y1)*(b-Y1))-40<0Then
Red=((pi1&Mod256)+200*(1-(Sqr((a-X1)*(a-X1)+(b-Y1)*(b-Y1))+1)/40))
Green=((((pi1&And&HFF00)/256&)Mod256&)+200*(1-(Sqr((a-X1)*(a-X1)+(b-Y1)*(b-Y1))+1)/40))
Blue=(((pi1&And&HFF0000)/65536)+200*(1-(Sqr((a-X1)*(a-X1)+(b-Y1)*(b-Y1))+1)/40))
IfRed<0ThenRed=0
IfRed>255ThenRed=255
IfGreen<0ThenGreen=0
IfGreen>255ThenGreen=255
IfBlue<0ThenBlue=0
IfBlue>255ThenBlue=255
Picture1.PSet(X1,Y1),RGB(Red,Green,Blue)
EndIf
NextY1
NextX1
Picture1.Refresh
EndSub
'根据鼠标坐标改变灯光位置
PrivateSubPicture1_MouseUp(ButtonAsInteger,ShiftAsInteger,xAsSingle,yAsSingle)
Dimindex1AsInteger
Dimindex2AsInteger
Picture1.Picture=Picture2.Picture
'获取当前鼠标坐标
Me.Cls
Me.Caption=x&","&y
'Label1.Left=X
'Label1.Top=Y
'Label1.Caption="当前位置:
X="&X&"Y="&Y
index1=x
index2=y
Ifflag2>0Then‘启动灯光滤镜,才能改变灯光位置
CallDengguang(index1,index2)
EndIf
EndSub
'退出程序
PrivateSubquit_Click()
UnloadMe
EndSub
程序运行效果及其操作指南
操作指南:
首先单击打开图片,就可以使用滤镜了。
浮雕滤镜可以通过拉杆改变参数,由于运行慢,请稍等片刻。
使用灯光滤镜,单击图片框1可以改变灯光位置。
每次要更换滤镜请点击清除,清除滤镜后的图像,以免影响下一个滤镜效果。
程序运行结果:
浮雕滤镜效果:
灯光滤镜效果:
木刻滤镜效果:
油画滤镜效果: