#include <stdio.h>
#include "max_filter.h"
#include "stdlib.h"
#include "cmath"
#include <iostream>
#define LENGTH_NAME_BMP 120//bmp图片文件名的最大长度
using namespace std;
//变量定义
BITMAPFILEHEADER strHead;
RGBQUAD strPla[256];//256色调色板
BITMAPINFOHEADER strInfo;
int main(){
char strFile[LENGTH_NAME_BMP];//bmp文件名
IMAGEDATA *imagedata = NULL;//动态分配存储原图片的像素信息的二维数组
IMAGEDATA *imagedatalater = NULL;//动态分配存储旋转后的图片的像素信息的二维数组
int width,height;//图片的宽度和高度
cout<<"请输入所要读取的文件名:"<<endl;
cin>>strFile;
FILE *fpi,*fpw;
fpi=fopen(strFile,"rb");
if(fpi != NULL){
//先读取文件类型
WORD bfType;
fread(&bfType,1,sizeof(WORD),fpi);
if(0x4d42!=bfType)
{
cout<<"the file is not a bmp file!"<<endl;
return NULL;
}
//读取bmp文件的文件头和信息头
fread(&strHead,1,sizeof(tagBITMAPFILEHEADER),fpi);
fread(&strInfo,1,sizeof(tagBITMAPINFOHEADER),fpi);
//读取调色板
for(unsigned int nCounti=0;nCounti<strInfo.biClrUsed;nCounti++)
{
fread((char *)&(strPla[nCounti].rgbBlue),1,sizeof(BYTE),fpi);
fread((char *)&(strPla[nCounti].rgbGreen),1,sizeof(BYTE),fpi);
fread((char *)&(strPla[nCounti].rgbRed),1,sizeof(BYTE),fpi);
fread((char *)&(strPla[nCounti].rgbReserved),1,sizeof(BYTE),fpi);
}
width = strInfo.biWidth;
height = strInfo.biHeight;
//图像每一行的字节数必须是4的整数倍
width = (width + 3) / 4 * 4;
imagedata = (IMAGEDATA*)malloc(width * height * sizeof(IMAGEDATA));
imagedatalater = (IMAGEDATA*)malloc( width * height * sizeof(IMAGEDATA));
//初始化原始图片的像素数组
for(int i = 0;i < height;++i)
{
for(int j = 0;j < width;++j)
{
imagedata [ i * width + j].blue = 0;
}
}
//初始化均衡化后图片的像素数组
for(int i =0;i < height;++i)
{
for(int j = 0;j < width;++j)
{
imagedatalater[i * width + j].blue = 0;
}
}
//读出图片的像素数据
fread(imagedata,sizeof(struct tagIMAGEDATA) * width,height,fpi);
fclose(fpi);
}
else
{
cout<<"file open error!"<<endl;
return NULL;
}
for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)
{
imagedatalater[i*width+j].blue=imagedata[i*width+j].blue;
}
}
int size;
cout<<"please enter size:";
cin>>size;
int scale=size*size;
int * tem=new int[scale];
for(int i=0;i<scale;i++)
{tem[i]=1;}
int * Ma=new int[scale];
for(int i=0;i<scale;i++)
{Ma[i]=0;}
int py,px,t;
for(int i=size/2;i<height-size/2;i++)
{for(int j=size/2;j<width-size/2;j++)
{for(int m=0;m<size;m++)
{for(int n=0;n<size;n++)
{
py=j-size/2+m;
px=i-size/2+n;
Ma[m*size+n]=imagedata[px*width+py].blue;
}
}
for(int c=0;c<scale;c++)
{for (int d=0;d<scale-c;d++)
{
if(Ma[c]>Ma[c+1])
{
t=Ma[c];
Ma[c]=Ma[c+1];
Ma[c+1]=t;
}
}
}
imagedatalater[i*width+j].blue=Ma[scale-1];
}
}
//保存bmp图片
if((fpw=fopen("E:\\max_filter.bmp","wb"))==NULL)
{
cout<<"create the bmp file error!"<<endl;
return NULL;
}
WORD bfType_w=0x4d42;
fwrite(&bfType_w,1,sizeof(WORD),fpw);
fwrite(&strHead,1,sizeof(tagBITMAPFILEHEADER),fpw);
strInfo.biWidth = width;
strInfo.biHeight = height;
fwrite(&strInfo,1,sizeof(tagBITMAPINFOHEADER),fpw);
//保存调色板数据
for(unsigned int nCounti=0;nCounti<strInfo.biClrUsed;nCounti++)
{
fwrite(&strPla[nCounti].rgbBlue,1,sizeof(BYTE),fpw);
fwrite(&strPla[nCounti].rgbGreen,1,sizeof(BYTE),fpw);
fwrite(&strPla[nCounti].rgbRed,1,sizeof(BYTE),fpw);
fwrite(&strPla[nCounti].rgbReserved,1,sizeof(BYTE),fpw);
}
//保存像素数据
for(int i =0;i < height;++i)
{
for(int j = 0;j < width;++j)
{
fwrite( &((*(imagedatalater + i * width + j)).blue),1,sizeof(BYTE),fpw);
}
}
fclose(fpw);
//释放内存
delete[] imagedata;
delete[] imagedatalater;
delete[] tem;
return 0;
system("pause");
}
没有合适的资源?快使用搜索试试~ 我知道了~
max_filter.rar_max Filter_最大值滤波
共39个文件
tlog:18个
manifest:2个
pdb:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 145 浏览量
2022-09-19
21:53:19
上传
评论
收藏 3.53MB RAR 举报
温馨提示
最大值滤波器,代码完整,有需要的请下载吧,即下即用
资源推荐
资源详情
资源评论
收起资源包目录
max_filter.rar (39个子文件)
max_filter
max_filter.sln 897B
max_filter.suo 12KB
ipch
max_filter-695455a6
max_filter-ff964277.ipch 14.56MB
Debug
max_filter.pdb 723KB
max_filter.ilk 500KB
max_filter.exe 57KB
max_filter
max_filter.vcxproj.filters 1KB
max_filter.h 1KB
max_filter.cpp 4KB
max_filter.vcxproj.user 143B
max_filter.vcxproj 4KB
Debug
max_filter.log 831B
vc100.idb 283KB
max_filter.exe.embed.manifest 406B
CL.write.1.tlog 736B
CL.read.1.tlog 19KB
mt.read.1.tlog 670B
rc.write.1.tlog 630B
rc.read.1.tlog 614B
mt.command.1.tlog 808B
cl.command.1.tlog 1KB
link-cvtres.read.1.tlog 2B
link.9896.read.1.tlog 2B
max_filter_manifest.rc 210B
link.9896-cvtres.read.1.tlog 2B
max_filter.obj 76KB
link.write.1.tlog 2KB
link-cvtres.write.1.tlog 2B
link.command.1.tlog 3KB
rc.command.1.tlog 1KB
link.read.1.tlog 6KB
max_filter.lastbuildstate 63B
mt.write.1.tlog 318B
link.9896.write.1.tlog 2B
link.9896-cvtres.write.1.tlog 2B
max_filter.exe.embed.manifest.res 472B
max_filter.exe.intermediate.manifest 381B
vc100.pdb 236KB
max_filter.sdf 5.33MB
共 39 条
- 1
资源评论
刘良运
- 粉丝: 67
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功