数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx

上传人:b****3 文档编号:16418353 上传时间:2022-11-23 格式:DOCX 页数:9 大小:17.01KB
下载 相关 举报
数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx_第1页
第1页 / 共9页
数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx_第2页
第2页 / 共9页
数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx_第3页
第3页 / 共9页
数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx_第4页
第4页 / 共9页
数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx

《数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx(9页珍藏版)》请在冰豆网上搜索。

数字图像处理实验报告邻域平均法和中值滤波法Word文档下载推荐.docx

<

邻域平均法>

(3*3) 

#include 

stdio.h>

stdlib.h>

memory.h>

"

hdr.h"

/*------定义结构指针------*/ 

struct 

bmphdr 

*hdr;

//定义用于直方图变量

unsigned 

char 

*bitmap,*count,*new_color;

/*------main()函数编------*/ 

int 

main() 

//定义整数 

i,j 

用于函数循环时的,nr_pixels为图像中像素的个数

i, 

nr_pixels,nr_w,nr_h;

//定义两个文件指针分别用于提取原图的数据和生成直方图均衡化后的图像

FILE 

*fp, 

*fpnew;

//定义主函数的参数包括:

输入的位图文件名和输出的位图文件名,此处内容可以不要,在DOS下执行命令的时候再临时输入也可,为了方便演示,我这里直接把函数的参数确定了。

// 

argc=3;

// 

argv[1]="

test.bmp"

;

argv[2]="

testzf.bmp"

//参数输入出错显示

/* 

if 

(argc 

!

3) 

printf("

please 

input 

the 

name 

of 

and 

out 

bitmap 

files\n"

);

exit

(1);

}*/ 

获取位图文件相关信息// 

hdr 

get_header(argv[1]);

get_header("

testnoise.bmp"

(!

hdr) 

//以二进制可读方式打开输入位图文件 

fp 

fopen("

 

rb"

fp) 

File 

open 

error!

\n"

文件指针指向数据区域

fseek(fp, 

hdr->

offset, 

SEEK_SET);

//计算位图像素的个数

nr_pixels 

width 

height;

nr_w 

width;

nr_h 

malloc(nr_pixels);

new_color 

count 

malloc((nr_w+2)*(+nr_h+2));

//读取位图数据到bitmap中

fread(bitmap, 

nr_pixels, 

1, 

fp);

fclose(fp);

//因为图像边缘无法使用邻域平均,所以根据邻近颜色填补图像的周围一圈,存入count[]数组中

//中心图像存入count[] 

for(i=nr_w+3;

i<

(nr_w+2)*(+nr_h+2)-nr_w-3;

i++) 

j=i/(nr_w+2);

if(i%(nr_w+2)!

=0&

&

(i+1)%(nr_w+2)!

=0) 

count[i]=bitmap[i-nr_w-1-2*j];

//填补第一排

for(i=1;

nr_w+1;

count[i]=bitmap[i-1];

//填补最后一排

count[(nr_w+2)*(nr_h+1)+i]=bitmap[nr_w*(nr_h-1)+i-1];

//填补左边一排

for(i=0;

nr_h+3;

count[i*(nr_w+2)]=count[i*(nr_w+2)+1];

//填补右边一排 

count[(i+1)*(nr_w+2)-1]=count[(i+1)*(nr_w+2)-2];

//邻域平均3*3 

for(j=nr_w+3,i=0;

j<

j++) 

if(j%(nr_w+2)!

(j+1)%(nr_w+2)!

new_color[i]=(count[j]+count[j-1]+count[j+1]+count[j-nr_w-2]+count[j-1-nr_w-2]+count[j+1-nr_w-2]+count[j+nr_w+2]+count[j-1+nr_w+2]+ 

count[j+1+nr_w+2])/9,i++;

//结果存入bitmap[]中

for 

(i 

0;

nr_pixels;

i++;

bitmap[i]=new_color[i];

打开一个以输出文件名命名的文件,设为可写的二进制形式

fpnew 

test_lynoise.bmp"

wb+"

//由于位图文件的头部信息并没有因直方图均衡化而改变,因此输出图像的头部信息从原位图文件中拷贝即可:

fwrite(hdr->

signature, 

2, 

fpnew);

fwrite(&

size, 

4, 

reserved, 

hdr_size, 

width, 

height, 

nr_planes, 

bits_per_pixel, 

compress_type, 

data_size, 

resol_hori, 

resol_vert, 

nr_colors, 

important_color, 

(hdr->

offset 

>

54) 

info, 

54), 

//直方图均衡化的数据(bitmap)赋值fwrite(bitmap, 

//关闭

fclose(fpnew);

//释放内存(优化程序必需)

free(hdr);

free(bitmap);

free(new_color);

free(count);

return 

中值滤波>

/*------定义结构指针------*/ 

/*------main()函数编写------*/ 

//定义整数 

i, 

j, 

m, 

n, 

nr_pixels,nr_w,nr_h,temp,t[9];

//定义两个文件指针分别用于提取原图像的数据和生成直方图均衡化后的图像

输入的位图文件名和输出的位图文件名,此处内容可以不要,在DOS下执行命令的时候再临时输入也可. 

 

//以二进制可读方式打开输入位图文件

//读取位图数据到bitmap中 

//因为图像边缘无法使用邻域平均,所以根据邻近颜色填补图像的周围一圈,存入count[]数组中 

//填补第一排

count[i]=bitmap[i-1];

count[i*(nr_w+2)]=count[i*(nr_w+2)+1];

//填补右边一排 

count[(i+1)*(nr_w+2)-1]=count[(i+1)*(nr_w+2)-2];

//中值平均3*3 

t[0]=count[j];

t[1]=count[j-1];

t[2]=count[j+1];

t[3]=count[j-nr_w-2];

t[4]=count[j-1-nr_w-2];

t[5]=count[j+1-nr_w-2];

t[6]=count[j+nr_w+2];

t[7]=count[j-1+nr_w+2];

t[8]=count[j+1+nr_w+2];

for(m=0;

m<

9;

m++) 

for(n=0;

n<

9-m;

n++) 

if(t[n]>

t[n+1]) 

temp=t[n];

t[n]=t[n+1];

t[n+1]=temp;

new_color[i]=t[4];

//结果存入bitmap[]中 

test_zznoise.bmp"

//直方图均衡化的数据(bitmap)赋值

fwrite(bitmap, 

//关闭 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1