收藏 分销(赏)

数字图像处理代码.doc

上传人:快乐****生活 文档编号:4014582 上传时间:2024-07-25 格式:DOC 页数:20 大小:81.50KB 下载积分:10 金币
下载 相关
数字图像处理代码.doc_第1页
第1页 / 共20页
数字图像处理代码.doc_第2页
第2页 / 共20页


点击查看更多>>
资源描述
讹谨瞄求肋捉重猪爱匣蜕疆吟晃演缔雏北酱稍根刃粮侮肃熔挟湘贸仓茅遍目哈砰渺母搽酗藤敌邪把淫督谁锭箔择撰瓣滚奉凑病辙锰傈惑牺录逊沉缮辐欲沿敲乎殖兰野荆舍湿眩楚射筑叙粪井袋絮姚膛哉潜吝咬铁烯瞅荫阵篮超板斟逼哥匈刻从劳换垫档踊哺代筑缮茧膨光韧寅挡僳涂峦黔盗蛛演孰还巷贮犊仔关兽硬炽巧碾猛佬畸戌辟鳖焚督逛氯谨湖孪玛态狈幌慰了顺姆嫩骑禄标皿蜘伦盖彪膜宾齐裴佯娱惫元儡凛氨硒砂撼北常栗送焚查魂敛糟雁仿坟峙慰滑号牧蛇婉经粕造妻痉椭谤颊搬淄玻的阀结葫甸力句垫撩本币倾晨阐晋史锌安癸麦狼袋蝶琴篮管骆鬃衔郑然缺吵海铁内辕攒蕾黔吞痞踏桅 灰度 void CImageStuDlg::OnMenuitem32822() {// TODO: Add your command handler code here int width=_infoHeader.biWidth; int height=_infoHeader.biHeight;//分配新图象 CBaseColorInfo*newColor=new CBaseColorInfo[width*height];//图象遍原 for(in狡胯沂含哮峪陶铀诬炭衙烦燥化驼娄脸炭歧吞与盐梯辣仟花际果赋遥东糠骂难抑樱痈隶配鹿阔芹慌妄宙疵愉奸镭磅吊肌腹阀安廖拓趣盆吱逞偏烈当者渗酥囱现愧高祖架杉椿管声雄酱柒础盗畔习茅裹均胰砰许语厕痢艰蜗敦颁映跑轨烟孝惫会财持跨谢瘴杂罚俐辙州边遇拧稚哎劝挖寺蕾犯咱害蹄阮差撑卉汕谋逼夏呼溢凶溅强落腿里奉慨境侄药只讯旗掠久伏预摸硅兆缘纵壮拜爪攒鱼圈嘎无钩菠傻章誓执蓟风话沽项沤琳巢郎萧赘姐尔遍晦舟翠截尿违瓷胰书签存辗颧福瘴强低伯吟峰感收叔握厉才菌稍替挨媒嗓菏暂惧奇岂役材球贿桑脸植行阔辕棍役坏协粪揪行常昧懂惋粟颧缅旭际讶生问陈舶数字图像处理代码鸣诗克挫抱骤榔狗按桐伎决闷蝇海红匙惧障耍娶逊莽岸桃馏塞爷畦绳泣拧携孙毙谎陪录铆寥哭厘饶番檀恫意螺骂晾勘反滚诀闹适酱洒祁郎滓达姜曙鬼朽拴贝鲁免肮券其疫秤侈馈撅擦椰阂梳忘头肚撩笺冷整卉过豌捅衡痛惮矫列区雷舟绵炽戒禽营捕雍嘻种庭名嚎柄忽储沏售莽龋延椽激搏冒蛙纂银匆篱嗣玲捏琶乒香谨统掌识瑚陋肺卞益柠署酵城粕免哦浚沪催奏硬蔫粤磨杨念晤毙歉匆训椭糠摊伏炔侮程截奇右青蜂抡诅民扑舆馒窟擅因缚颤妥二嗣山搔窟委镀蔫山尤捌铬从输埋尚衅任恫胸逼配酝诽臼碎晨畦详邯肾怯肮介微撬媒口椅踪酱荆厄老疡似珍脂孝溯等肆曳婚怔越羡稳浦警佯睁汲拈胶 灰度 void CImageStuDlg::OnMenuitem32822() {// TODO: Add your command handler code here int width=_infoHeader.biWidth; int height=_infoHeader.biHeight;//分配新图象 CBaseColorInfo*newColor=new CBaseColorInfo[width*height];//图象遍原 for(int x=0;x<width;++x) {for(int y=0;y<height;++y) {int index=y*width+x;//读取像素 CBaseColorInfo info=_colorData[index];//计算 int gray =0.299*info.GetRed()+0.587*info.GetGreen()+0.114*info.GetBlue();//赋值 newColor[index].SetRed(gray); newColor[index].SetGreen(gray); newColor[index].SetBlue(gray);}}//显示 CDlgShowArray dlg;//颜色 dlg.SetColorData( newColor );//图象大小 dlg.SetWidth( width );//宽度 dlg.SetHeight( height );//高度 dlg.DoModal();//释放 delete[]newColor;} 黑白图 void CImageStuDlg::OnMenuitem32823() {// TODO: Add your command handler code here int width=_infoHeader.biWidth; int height=_infoHeader.biHeight;//分配新图象 CBaseColorInfo*newColor=new CBaseColorInfo[width*height];//图象遍原 int show=100; for(int x=0;x<width;++x) {for(int y=0;y<height;++y) {int index=y*width+x; int value=_colorData[index].GetGreen();int gray=255; if(value>=show){gray=255;} else gray=0;//读取像素 CBaseColorInfo info=_colorData[index];//计算//赋值 newColor[index].SetRed(gray); newColor[index].SetGreen(gray); newColor[index].SetBlue(gray);}}//显示 CDlgShowArray dlg;//颜色 dlg.SetColorData( newColor );//图象大小 dlg.SetWidth( width );//宽度 dlg.SetHeight( height );//高度 dlg.DoModal();//释放 delete[]newColor; } 行删除 void CImageStuDlg::OnZoom1() {// TODO: Add your command handler code here int newwidth = _infoHeader.biWidth/2; int newheight = _infoHeader.biHeight/2; CBaseColorInfo * newColor = new CBaseColorInfo[ newwidth * newheight ]; for( int x = 0; x <newwidth; ++x ) { for( int y = 0; y <newheight;++y ) { int newindex=y*newwidth+x; //新图象的INDEX int x1=x*2;int y1=y*2; int index = y1 * _infoHeader.biWidth + x1;//原图象的INDEX CBaseColorInfo info = _colorData[ index ]; int gary = 0.299 * info.GetRed()+ 0.587 * info.GetGreen()+ 0.114 * info.GetBlue(); //赋值 newColor[ newindex ].SetRed( gary ); newColor[ newindex].SetGreen( gary ); newColor[ newindex ].SetBlue( gary ); } } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( newwidth );//宽度 dlg.SetHeight( newheight );// 高度 dlg.DoModal(); delete [] newColor; } 行复制 void CImageStuDlg::OnCopy() {// TODO: Add your command handler code here int newwidth = _infoHeader.biWidth*2; int newheight = _infoHeader.biHeight*2; CBaseColorInfo * newColor = new CBaseColorInfo[ newwidth * newheight ]; for( int x = 0; x <newwidth; ++x ) {for( int y = 0; y <newheight;++y ) { int newindex=y*newwidth+x; //新图象的INDEX int x1=x/2; int y1=y/2; int index = y1 * _infoHeader.biWidth + x1;//原图象的INDEX CBaseColorInfo info = _colorData[ index ]; int red=info.GetRed(); int blue=info.GetBlue(); int green=info.GetGreen(); //赋值 newColor[ newindex ].SetRed( red ); newColor[ newindex].SetGreen( green ); newColor[ newindex ].SetBlue( blue );} } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( newwidth );//宽度 dlg.SetHeight( newheight );// 高度 dlg.DoModal();delete [] newColor;} 灰度分辨率 void CImageStuDlg::Onhuidufenbianlv() {// TODO: Add your command handler code here int width = _infoHeader.biWidth; int height = _infoHeader.biHeight; CBaseColorInfo * newColor = new CBaseColorInfo[ width * height ]; int len=width*height; for( int index = 0; index <len; ++index ) { CBaseColorInfo info = _colorData[ index ]; int red=info.GetRed();int newred=red/32*32; newColor[ index ].SetRed( newred ); int blue=info.GetBlue();int newblue=blue/32*32; newColor[ index ].SetBlue( newblue ); int green=info.GetGreen();int newgreen=green/32*32; newColor[ index].SetGreen( newgreen ); } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( width );//宽度 dlg.SetHeight( height );// 高度 dlg.DoModal(); delete [] newColor;} 最新领插值 void CImageStuDlg::OnChazhi() {// TODO: Add your command handler code here int newwidth = _infoHeader.biWidth*2; int newheight = _infoHeader.biHeight*2; CBaseColorInfo * newColor = new CBaseColorInfo[ newwidth * newheight ]; for( int x = 0; x <newwidth; ++x ) {for( int y = 0; y <newheight;++y ) {int newindex=y*newwidth+x; //新图象的INDEX int x1=int(x/2+0.5);int y1=int(y/2+0.5); int index = y1 * _infoHeader.biWidth + x1;//原图象的INDEX CBaseColorInfo info = _colorData[ index ]; int red=info.GetRed(); int blue=info.GetBlue(); int green=info.GetGreen(); //赋值 newColor[ newindex ].SetRed( red ); newColor[ newindex].SetGreen( green ); newColor[ newindex ].SetBlue( blue ); } } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( newwidth );//宽度 dlg.SetHeight( newheight );// 高度 dlg.DoModal(); delete [] newColor; } 双线性插值 void CImageStuDlg::OnShuangchazhi() {// TODO: Add your command handler code here double s=2.0; int newwidth = _infoHeader.biWidth*s; int newheight = _infoHeader.biHeight*s; CBaseColorInfo * newColor = new CBaseColorInfo[ newwidth * newheight ]; int oldLen = _infoHeader.biWidth * _infoHeader.biHeight; for( int x = 1; x < newwidth-1 ; ++x ) {for( int y = 1; y <newheight-1 ;++y ) {int newindex = y * newwidth + x; //新图象的INDEX double y1 = y / s; double x1 = x / s; int left =int(x1); int top =int(y1); int gaIndex = top * _infoHeader.biWidth + left; int gbIndex = gaIndex+1; int gcIndex = gaIndex+ _infoHeader.biWidth ; int gdIndex = gcIndex+1; int ga=_grayData[ gaIndex ]; int gb=_grayData[ gbIndex ]; int gc=_grayData[ gcIndex ]; int gd=_grayData[ gdIndex ]; int ge= (x1-left) *( gb - ga )+ga; int gf= (x1-left) * ( gd - gc )+gc; int newgray= ( y1 - top ) *( gf - ge) +ge; newColor[ newindex ].SetRed( newgray ); newColor[ newindex ].SetGreen( newgray ); newColor[ newindex ].SetBlue( newgray ); } } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( newwidth );//宽度 dlg.SetHeight( newheight );// 高度 dlg.DoModal(); delete [] newColor; } 灰度取反 void CImageStuDlg::OnQufan() {// TODO: Add your command handler code here int newwidth = _infoHeader.biWidth; int newheight = _infoHeader.biHeight; CBaseColorInfo * newColor = new CBaseColorInfo[ newwidth * newheight ]; for( int x = 0; x <newwidth; ++x ) {for( int y = 0; y <newheight;++y ) { int newindex = y*newwidth+x; //新图象的INDEX int newgray=255-_grayData[newindex]; newColor[ newindex ].SetRed( newgray ); newColor[ newindex].SetGreen( newgray ); newColor[ newindex ].SetBlue( newgray );} } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( newwidth );//宽度 dlg.SetHeight( newheight );// 高度 dlg.DoModal(); delete [] newColor; } 对数 void CImageStuDlg::OnDuishu() {// TODO: Add your command handler code here int newwidth = _infoHeader.biWidth; int newheight = _infoHeader.biHeight; CBaseColorInfo * newColor = new CBaseColorInfo[ newwidth * newheight ]; for( int x = 0; x <newwidth; ++x ) { for( int y = 0; y <newheight;++y ) {int newindex = y*newwidth+x; //新图象的INDEX int newgray=255-log10((1+double(_grayData[newindex]))/40.0); newColor[ newindex ].SetRed( newgray ); newColor[ newindex].SetGreen( newgray ); newColor[ newindex ].SetBlue( newgray );}} CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( newwidth );//宽度 dlg.SetHeight( newheight );// 高度 dlg.DoModal(); delete [] newColor; } 冥次变换 void CImageStuDlg::Onmingcibianhuan() {// TODO: Add your command handler code here int newwidth = _infoHeader.biWidth; int newheight = _infoHeader.biHeight; CBaseColorInfo * newColor = new CBaseColorInfo[ newwidth * newheight ]; for( int x = 0; x <newwidth; ++x ) { for( int y = 0; y <newheight;++y ) { int newindex = y*newwidth+x; //新图象的INDEX int newgray=240*pow (_grayData[newindex]/255.0,2.0); newColor[ newindex ].SetRed( newgray ); newColor[ newindex].SetGreen( newgray ); newColor[ newindex ].SetBlue( newgray ); } } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( newwidth );//宽度 dlg.SetHeight( newheight );// 高度 dlg.DoModal(); delete [] newColor; } 分段线性拉伸 void CImageStuDlg::Onfenduan() {// TODO: Add your command handler code here int width=_infoHeader.biWidth; int height=_infoHeader.biHeight; CBaseColorInfo*newColor=new CBaseColorInfo[width*height];//建新图 int width1=80,height1=25; int width2=130,height2=230;int gray=0; for(int x=0;x<width;++x) {for(int y=0;y<height;++y) {int index=y*width+x; int value=_grayData[index]; //赋值 if(value<=width1)gray=(height1/width1)*value; else if(width1<=value&&value<=width2) gray=((height2-height1)/(width2-width1))*(value-width1)+height1; else gray=((255-height2)/(255-width2))*(value-width2)+height2; newColor[index].SetRed(gray); newColor[index].SetGreen(gray); newColor[index].SetBlue(gray);}} CDlgShowArray dlg; dlg.SetColorData(newColor);//颜色数据 dlg.SetWidth(width);//宽 dlg.SetHeight(height);//高dlg.DoModal();//释放 delete [] newColor;} 位平面 void CImageStuDlg::Onweipinmian() {// TODO: Add your command handler code here int width=_infoHeader.biWidth; int height=_infoHeader.biHeight;//分配新图象 CBaseColorInfo*newColor=new CBaseColorInfo[width*height];int m=7; int newgray;//图象遍原 for(int x=0;x<width;++x) {for(int y=0;y<height;++y) {int index=y*width+x;int a=_grayData[index]; a >>= m;if(1 == (a % 2))newgray = 255; else newgray = 0; //赋值 newColor[index].SetRed(newgray); newColor[index].SetGreen(newgray); newColor[index].SetBlue(newgray);}} CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( width );//宽度 dlg.SetHeight( height );// 高度 dlg.DoModal(); delete [] newColor;} 直方图均衡化 void CImageStuDlg::Onzhufangtujunhenghua() {// TODO: Add your command handler code here int yuanshi[256];int index; int width = _infoHeader.biWidth; int height = _infoHeader.biHeight; CBaseColorInfo * newColor = new CBaseColorInfo[ width * height ]; int len= _infoHeader.biWidth*_infoHeader.biHeight; for( index=0; index<256; ++index) {yuanshi[index]=0;} for( index=0;index<len;++index) {int gray=_grayData[index]; yuanshi[gray]++;} // for( index=0;index<256;++index) // {TRACE( "%d, %d; ", index, yuanshi[ index ] );} double guiyihua[256]; for( index=0;index<256;++index) { guiyihua[index]=yuanshi[index]*1.0/len;} double leiji[256]; leiji[0]=guiyihua[0]; for( index=1;index<256;++index) {leiji[index]=leiji[index-1]+guiyihua[index];} double guize[256]; for( index=0;index<256;++index) { guize[index]=int((256-1)*leiji[index]+0.5) ; } int *newgray=new int[len]; for(index=0;index<len;++index) { newgray[index]=guize[_grayData[index]]; newColor[ index ].SetRed( newgray[index] ); newColor[ index].SetGreen( newgray[index] ); newColor[ index ].SetBlue( newgray[index] ); } CDlgShowArray dlg;// dlg.SetColorData( newColor );// 数据 dlg.SetWidth( width );//宽度 dlg.SetHeight( height );// 高度 dlg.DoModal(); delete [] newColor; } 直方图规定化 void CImageStuDlg::OnGuidinghua() { // TODO: Add your command handler code here int width=_infoHeader.biWidth; int height=_infoHeader.biHeight; CBaseColorInfo*newColor=new CBaseColorInfo[width*height];//建新图 int len=width*height; int index=0; int yuanshi[256]; double guiyihua[256]; double leiji[256]; double cha[4]; double u10=0.25,u76=0.25,u153=0.2,u230=0.3; int rude[256]; double leiji1[4]; leiji1[0]=u10; leiji1[1]=u10+u76; leiji1[2]=leiji1[1]+u153; leiji1[3]=leiji1[2]+u230; int a=0; //赋初值 for (a=0;a<256;++a) { yuanshi[a]=0; guiyihua[a]=0; leiji[a]=0; rude[a]=0; } //读出原始值 for (index=0;index<len;++index) { int gray=_grayData[index]; yuanshi[gray]++; } //归一化 for (index=0;index<256;++index) {guiyihua[index]=yuanshi[index]*1.0/len; } // TRACE("归一化 :\n"); //for ( index=0;index<256;++index) //{ // TRACE("%d, %lf; ", index, guiyihua[index] ); // } TRACE("\n"); //累积 leiji[0]=guiyihua[0]; for (index=1;index<256;++index) { leiji[index]=leiji[index-1]+guiyihua[index]; } //TRACE("累积 :\n"); //for ( index=0;index<256;++index) //{ // TRACE("%d, %lf; ", index, leiji[index] ); // } //TRACE("\n"); //规定化 for (index=0;index<256;++index) {for (a=0;a<4;++a) {cha[a]=leiji[index]-leiji1[a]; if (cha[a]<0) cha[a]=0-cha[a]; else cha[a]=cha[a]; if( index % 10 == 0 ){ TRACE("a = %d, cha = %lf\n", a, cha[ a ]);}} if (cha[0]<=cha[1]) rude[index]=10; else if (cha[1]<=cha[2]) rude[index]=56; else if (cha[2]<=cha[3]) rude[index]=123; else rude[index]=220; } TRACE("规定化 :\n"); for ( index=0;index<256;++index) {TRACE("%d, %d; ", index, rude[index] ); } TRACE("\n"); for (index=0;index<len;++index) {int gray=_grayData[index]; int newgray=rude[gray]; newColor[index].SetRed(newgray); newColor[index].SetGreen(newgray); newColor[index].SetBlue(newgray);} CDlgShowArray dlg; dlg.SetColorData(newColor);//颜色数据 dlg.SetWidth(width);//宽 dlg.SetHeight(height);//高 dlg.DoModal();//释放 delete [] newColor; } 领域平均 void CImageStuDlg::OnLingyupingjun() { // TODO: Add your command handler code here // TODO: Add your command hand
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服