《多媒体技术》实验报告图像变换动画_第1页
《多媒体技术》实验报告图像变换动画_第2页
《多媒体技术》实验报告图像变换动画_第3页
《多媒体技术》实验报告图像变换动画_第4页
《多媒体技术》实验报告图像变换动画_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、多媒体技术实验报告图像变换动画 /大 学 学 生 实 验 报 告 实验课程名称 多媒体技术 开课实验室 学 院 学 生 姓 名 学 号 开 课 时 间 20xx 至 20xx 学年第 一 学期 总 成 绩 教师签名 软件学院制 多媒体技术实验报告 开课实验室: xx 年 x月x 日 学院 年级、专业、班 姓名 成绩 课程 名称 多媒体技术 实验工程 名 称 图像变换动画 指导教师 教师评语 教师签名: 年 月 日 一、实验目的 通过两幅图像的变换,实现动画效果。 二、实验原理 变形动画将一幅图像动态变换为另一幅大小相同、结构相似的图像。其中需要在两幅图像的主体结构中标注对应的变换点,在变换过程

2、中按照对应点进行形状结构的变换。 如果不考虑图像形状结构的变换,那么可简单地实现将一幅图像动态变换为另一幅大小相同的图像。其对应变换点就以对应的像素点确定。本实验即按照该方式实现。 对于大小不一样的图像需要更复杂的处理方式。需要一定的插值算法生成图像变换所产生的额外的像素值。最终效果因算法的不同而不同。本实验不考虑该情形。 变换结果先以图像文件方式存储,然后可采用两种方式实现动画展示:使用构造gif动画的软件将变换过程的图像连接成gif动画; 自行编制软件按照一定的速度翻开并展示变换过程的图像,形成动画展示效果。 理论上对于不同格式的图像文件均可以实现图像变换动画。这里为了简化操作,统一使用b

3、mp格式的图像文件。 对于24位真彩色bmp图像构造图像变换动画,主要就是对于图像数据阵列中的各对应像素点的rgb值进行插值变换,实现将一幅图像中的像素点的rgb值变换为另一幅图像中对应像素点的rgb值。 对于使用调色板的bmp索引图像,生成图像变换动画的过程稍稍复杂。其变换方式有三种:(1)保持调色板不变,对于像素点进行颜色变换。将一个像素点变换为其对应的像素点时,根据该像素点索引值所指向的调色板表项的rgb和其对应的像素点索引值所指向的调色板表项的rgb,计算其变换图像的rgb值,然后在调色板中查找与变换过程图像的rgb值最接近的表项,将其对应的索引值作为变换过程图像的像素索引值。该方式不

4、改变原始调色板,但需要将变换过程rgb值映射为调色板中最接近的表项; (2)允许改变调色板,对于像素点进行颜色变换。根据变换图像各像素点的索引值找到其对应的调色板表项,从而获取各像素点的rgb值。然后按照与24位真彩色bmp图像变换相似的方式,通过插值计算变换过程图像各像素点的rgb值。该方式将可能在变换过程图像中生成超过256种rgb组合的颜色。如果再采用索引图像方式存储该图像,那么需要自行构造新的调色板,并将变换过程图像各像素点的rgb值映射到调色板中的表项;(3)保持调色板不变,对于像素点进行索引值变换。即,对于变换图像像素点的索引值,通过插值计算变换过程图像的索引值,实现简单的图像变换

5、。 上述三种图像变换方式中,第三种难以实现平滑的图像颜色变换,效果较差; 第二种实现过程较为复杂,需要自行生成新的调色板;第一种最为可行。 三、实验内容 翻开两幅大小相同的bmp图像,分别指定为起始帧、终止帧,指定变换帧数,实现将图像从起始帧逐步变换到终止帧,将一副图像动态地变换为另一幅图像。 四、实验工具 vsxx 五、实验步骤 如果不在程序中实现图像的翻开显示和变换动画显示,可以利用控制台程序读入图像,处理后生成各中间帧。 如果要在程序中实现图像的翻开显示和变换动画显示,在这里将关键实验步骤分为c+和c#两个不同的版本表达,提供实验方法而不阐述具体实现步骤: 1 c#版:c#对于图像的操作

6、已经封装好了具体的类bitmap,参阅资料就可以熟悉bitmap类中所有成员函数及属性的作用,动态效果主要是利用timer控件。 1) mfc布局如下: time1的enabled 设置为true,interval设置为10000ms相当于10秒 main.cpp: using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using syst

7、em.threading.tasks; using system.windows.forms; namespace animation public partial class form1 : form public bitmap curbitmap; bitmap soubitmap; bitmap oribitmap; public form1() initializecomponent(); private void form1load(object sender, eventargs e) private void button1click(object sender, eventar

8、gs e) openfiledialog filedialog = new openfiledialog(); timer1.stop(); filedialog.title = “选择文件“; filedialog.filter = “bmp files (*.bmp)|*.bmp“; filedialog.filterindex = 1; filedialog.restoredirectory = true; if (filedialog.showdialog() = dialogresult.ok) string filename = filedialog.filename; strin

9、g name = filename.substring(filename.lastindexof(“) + 1); oribitmap = new bitmap(filename); picturebox1.image = oribitmap; curbitmap = new bitmap(filename); int bitmapheight = oribitmap.height; int bitmapwidth = oribitmap.width; private void button2click(object sender, eventargs e) openfiledialog fi

10、ledialog = new openfiledialog(); timer1.stop(); filedialog.title = “选择文件“; filedialog.filter = “bmp files(*.bmp)|*.bmp“; filedialog.filterindex = 1; filedialog.restoredirectory = true; if (filedialog.showdialog() = dialogresult.ok) string filename = filedialog.filename; oribitmap = new bitmap(filena

11、me); soubitmap = new bitmap(filename); picturebox2.image = oribitmap; private void timer1tick(object sender, eventargs e) if (curbitmap != null) curbitmap = (bitmap)picturebox1.image; rectangle rect = new rectangle(0, 0, curbitmap.width, curbitmap.height); rectangle rect1 = new rectangle(0, 0, soubi

12、tmap.width, soubitmap.height); system.drawing.imaging.bitmapdata bmpdata = curbitmap.lockbits(rect, system.drawing.imaging.imagelockmode.readwrite, curbitmap.pixelformat); system.drawing.imaging.bitmapdata bmpdata1 = soubitmap.lockbits(rect1, system.drawing.imaging.imagelockmode.readwrite, soubitmap

13、.pixelformat); /得到首地址 intptr ptr = bmpdata.scan0; intptr ptr1 = bmpdata1.scan0; /24位bmp位图字节 int bytes = curbitmap.width * curbitmap.height * 3; int bytes1 = curbitmap.width * curbitmap.height * 3; /定义位图数组 byte rgbvalues = new bytebytes; byte rgbvalues1 = new bytebytes1; /复制被锁定的位图像素值到该数组内 system.runt

14、ime.interopservices.marshal.copy(ptr, rgbvalues, 0, bytes); system.runtime.interopservices.marshal.copy(ptr1, rgbvalues1, 0, bytes1); /灰度化 / double colortemp = 0; for (int i = 0; i < rgbvalues.length; i += 3) byte incre1 = (byte)math.abs(rgbvalues1i - rgbvaluesi); byte incre2 = (byte)math.abs(rgb

15、values1i + 1 - rgbvaluesi + 1); byte incre3 = (byte)math.abs(rgbvalues1i + 2 - rgbvaluesi + 2); rgbvaluesi += incre1; rgbvaluesi + 1 += incre2; rgbvaluesi + 2 += incre3; /把数组复制回位图 system.runtime.interopservices.marshal.copy(rgbvalues, 0, ptr, bytes); system.runtime.interopservices.marshal.copy(rgbvalues1, 0,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论