您好,欢迎来到华拓网。
搜索
您的当前位置:首页图形图像处理课程设计报告

图形图像处理课程设计报告

来源:华拓网


2008.12 图形图像处理报告 计算机学院

Abstract

Sketch picture processing has a very close contact with modernization life , so as

the technology and research . As the sketch picture processing technique’s fast development , people’s life are subjected to very big of influence.

In the course design ,I have mainly practiced the basic operation sketch picture processing , which contains ash degree square diagram ,the Rui turn of pictures and smooth etc.. According to these principle of the picture processing , including the ash degree of picture , and the picture strengthen filter etc.., I use the C# language realized the picture processing operation.

Key Word: Sketch picture processing,ash degree square diagram,Rui turn,smooth

摘 要

图形图像处理是和现代化生活紧密联系不可分的,还有对科研方面等都有

很大的贡献。今年来随着图形图像处理技术的快速发展,人们的生活都受到了很大的影响。

在这次课程设计中,我主要练习了图像处理基本的操作,包括图像的灰度直方图,图像的锐化以及平滑等等。根据这些图像处理的原理,包括图像的灰度,图像增强滤波器等等,用C#语言实现了上述的图像处理操作。

关键词:图形图像处理,直方图,锐化,平滑

1

2008.12 图形图像处理报告 计算机学院

图形图像处理课程设计报告

一. 实验要求

(1). 读入一幅图像,要求统计各像素点灰度值并显示该图的灰度直方图 (2). 读入一幅图像,要求输出该图锐化后的图像 (3). 读入一幅图像,要求显示该图平滑后的图像

二. 实验设计

1.实验中的程序界面如下

Form1

Form2

2

2008.12 图形图像处理报告 计算机学院

2.图像处理设计

(1). 灰度直方图对一幅图所有像素点具有的不同灰度值进行统计并显示出来,给出了一股图的所有灰度值的整体描述。实验中,若以i表示某个灰度值,则有0<=i<=256,以pix[i]表示灰度为i的像素点的个数,当画直方图的命令由form1传递到form2时,即采用GDI+画出该直方图

(2). 锐化滤波器是图像增强滤波器中的一种,它能减弱或消除傅里叶空间的低频分量,但不影响高频分量(从视觉效果上来看,就是突出有关形体的边缘)。实验中采用线性锐化滤波器,系数模板取拉普拉斯算子:

Laplacian111191 111 (3). 平滑滤波器是图像增强滤波器中的另一种,它能减弱或消除傅里叶空

间中的高频分量,但不影响高频分量(从视觉效果上来看,就是把图像给柔化了)。

实验中采用线性的平滑滤波器,系数模板取高斯算子:

121Gauss242

121三. 具体实现

1. 程序中定义的全局参数有:

From1: public int height, width; public int[] pix = new int[256]; Form2 : public int hei, wid; public int[] pie 2.传参:

既然涉及到两个窗体,就必然要在两个窗体之间传递参数,当某副图片的像素与灰度信息已经采集好时,就将灰度值数组传递到Form2中,接着用图形设备接口函数画出灰度直方图 /////Form1中的代码

private void button1_Click(object sender, EventArgs e) {

Form2 fm = new Form2(this);

fm.Show();

}

/////Form2中的代码

public Form2(Form1 fm)

{

InitializeComponent(); hei = fm.height; wid = fm.width; pie = fm.pix;

}

3

2008.12 图形图像处理报告 计算机学院

3.图像灰度直方图显示

先在Form1中定义函数统计读入的图像的像素点灰度信息,然后调用Form2窗体进行绘图,代码如下:

/////Form1中的代码

height = this.pictureBox1.Image.Height; width = this.pictureBox1.Image.Width;

Bitmap bitmap = (Bitmap)this.pictureBox1.Image; Color pixel;

int r = 0, b = 0, g = 0;

for (int i = 0; i < 256; i++) pix[i] = 0; for (int i = 1; i < width; i++) for (int j = 1; j < height; j++) {

pixel = bitmap.GetPixel(i, j); r = pixel.R; g = pixel.G; b = pixel.B;

int a = (int)(r + b + g) / 3;

pix[a]++; ////统计灰度值为a的像素点数目

} /////Form2中的代码

Bitmap image = new Bitmap(300, 300);

Graphics g = Graphics.FromImage(image); g.Clear(Color.White);

Font font = new Font(\"宋体\", 10, FontStyle.Bold); Brush brush = Brushes.Blue;

g.DrawString(\"灰度直方图\", font, brush, new Point(15, 10)); Pen mypen = new Pen(brush, 1); //绘制X轴;

g.DrawLine(mypen, 10, 260, 280, 260); g.DrawLine(mypen, 276, 258, 280, 260); g.DrawLine(mypen, 276, 262, 280, 260); //绘制Y轴;

g.DrawLine(mypen, 10, 10, 10, 260); g.DrawLine(mypen, 8, 16, 10, 10); g.DrawLine(mypen, 12, 16, 10, 10); for (int i = 0; i < 256; i++) {

g.DrawLine(mypen, 10 + i, 260, 10 + i, 260 - (int)(7000 * pie[i] / (hei * wid))); if (i % 50 == 0)

g.DrawString(i.ToString(), new Font(\"正楷\", 8, FontStyle.Regular), brush, new Point(10 + i, 262)); }

this.pictureBox1.Image = image;

4

2008.12 图形图像处理报告 计算机学院

4.图像锐化处理

如实验设计所描述的,采用拉普拉斯算子对原图像进行锐化,程序如下:

int height = this.pictureBox1.Image.Height;

int width = this.pictureBox1.Image.Width; Bitmap newBitmap = new Bitmap(width, height); Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image; Color pixel;

int[] Laplacian ={ -1, -1, -1, -1, 9, -1, -1, -1, -1 }; ////拉普拉斯算子 for (int x = 1; x < width - 1; x++) for (int y = 1; y < height - 1; y++) {

int r = 0, g = 0, b = 0; int index = 0;

for (int col = -1; col <= 1; col++) for (int row = -1; row <= 1; row++) {

pixel = oldBitmap.GetPixel(x + row, y + col); r += pixel.R * Laplacian[index]; g += pixel.G * Laplacian[index];

b += pixel.B * Laplacian[index]; ////计算变换后的像素点的像素值 index++; }

r = r > 255 ? 255 : r; ////判断是否溢出 r = r < 0 ? 0 : r; g = g > 255 ? 255 : g; g = g < 0 ? 0 : g; b = b > 255 ? 255 : b; b = b < 0 ? 0 : b;

newBitmap.SetPixel(x - 1, y - 1, Color.FromArgb(r, b, g)); }

this.pictureBox2.Image = newBitmap;

5.图像平滑处理

如实验设计所描述的,采用高斯算子对原图像进行锐化,程序如下:

int height = this.pictureBox1.Image.Height;

int width = this.pictureBox1.Image.Width; Bitmap newBitmap = new Bitmap(width, height); Bitmap oldBitmap = (Bitmap)this.pictureBox1.Image; Color pixel;

int[] Gauss ={ 1, 2, 1, 2, 4, 2, 1, 2, 1 }; ////高斯算子 for (int x = 1; x < width - 1; x++) for (int y = 1; y < height - 1; y++) {

int r = 0, g = 0, b = 0;

5

2008.12 图形图像处理报告 计算机学院 int index = 0;

for (int col = -1; col <= 1; col++) for (int row = -1; row <= 1; row++) {

pixel = oldBitmap.GetPixel(x + row, y + col); r += pixel.R * Gauss[index]; g += pixel.G * Gauss[index]; b += pixel.B * Gauss[index]; index++; }

r /= 16; g /= 16; b /= 16; ////得到变换后的像素点像素值 r = r > 255 ? 255 : r; r = r < 0 ? 0 : r; g = g > 255 ? 255 : g; g = g < 0 ? 0 : g; b = b > 255 ? 255 : b;

b = b < 0 ? 0 : b; /////判断是否溢出 newBitmap.SetPixel(x - 1, y - 1, Color.FromArgb(r, b, g)); }

this.pictureBox2.Image = newBitmap;

6.变换后图像灰度直方图显示

这个模块同第三个模块差不多,只是读取图像的对象不同:

height = this.pictureBox2.Image.Height;

width = this.pictureBox2.Image.Width;

Bitmap bitmap = (Bitmap)this.pictureBox2.Image;

四. 实验结果

1.实验中采用的图像如下所示:

6

2008.12 图形图像处理报告 计算机学院

2.原图直方图显示

3.锐化后的图像显示

7

2008.12 图形图像处理报告 计算机学院

4.锐化后的图像灰度直方图显示:

5.平滑后的图像显示:

8

2008.12 图形图像处理报告 计算机学院

6.平滑后图像灰度直方图显示:

五. 实验总结

因为对C++语言的不熟悉,这次实验我是基于C#语言完成的,所以从效果上来说比不上用C++与语言做出的图像效果 。

在图形图像处理课程设计中,我学到了不少的东西,并且做出这些之后感

觉很兴奋,比较有趣味性,突然发现对这方面比较感兴趣了。不过鉴于自己对于图像处理方面了解的知识还很少,以后会慢慢加强学习的。 谢谢童老师在这次课程设计中的指导!!!

六. 参考资料

[1].明日科技,图形图像技术,《C#开发经验技巧宝典》,2008年4月,320-322.

9

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo3.cn 版权所有 湘ICP备2023017654号-3

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务