📄 用vc++实现图像检索技术2.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0040)http://www.yesky.com/466/1649466_1.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>用VC++实现图像检索技术</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN>
<META content=all name=robots>
<META content="index, follow" name=googlebot>
<META content="MSHTML 6.00.2800.1586" name=GENERATOR>
<META content="天极Yesky | 全球中文IT第一门户" name=author>
<META content=,用VC++实现图像检索技术 name=description></META>
<META content=,硬件,软件,数码,游戏,e时代,下载,社区,评测,笔记本; name=keywords><LINK media=all
href="用VC++实现图像检索技术2.files/yesky-content-cs.css" type=text/css
rel=stylesheet></HEAD>
<BODY><!--头部-->
<DIV class=hidden>yesky内容</DIV><LINK media=all
href="用VC++实现图像检索技术2.files/y_headlogo0612.css" type=text/css
rel=stylesheet><LINK media=all href="用VC++实现图像检索技术2.files/headlink0612.css"
type=text/css rel=stylesheet><!--注册登陆及广告两行开始-->
<DIV class=top_head0607>
<DIV class=left_head0607><IMG src="用VC++实现图像检索技术2.files/ssleft_0608.gif"
border=0></DIV>
<FORM name=search action=http://search.yesky.com/search.do method=get>
<DIV class=dqbody_head0607><A href="http://my.yesky.com/">用户登录</A> <A
href="http://passport.yesky.com/customer/agreement.jsp">注册</A> <B>天极IT搜索</B>
<INPUT type=hidden value=0 name=stype><INPUT id=searchzz
onmouseover=this.focus() onfocus=this.select() size=12 name=wd> <INPUT class=searchbtn_head0607 type=submit value="搜 索"><INPUT type=hidden
value=1 name=categoryIds><INPUT type=hidden value=2 name=categoryIds><INPUT
type=hidden value=3 name=categoryIds><INPUT type=hidden value=4
name=categoryIds><INPUT type=hidden value=5 name=categoryIds><INPUT type=hidden
value=6 name=categoryIds><INPUT type=hidden value=1 name=sortType> 天极网站群:<A
href="http://www.yesky.com/">Yesky</A> | <A
href="http://www.chinabyte.com/">ChinaByte</A> | <A
href="http://www.techtarget.com.cn/">IT专家网</A> | <A
href="http://www.impresswatch.com.cn/">Impress中文站</A> </DIV></FORM>
<SCRIPT language=JavaScript>var abcurl=document.URL;if(window.location.href.indexOf("big5.yesky.com")!=-1) {var pcurl=abcurl.substring(25);document.write('<div class="jtft_head0607"><a href="' + 'http' + '://'+pcurl+'"><img src="http://www.yesky.com/TLimages/head/img/jianti_0608.gif" alt="简体版" border="0" /></a> <a href="http://rss.yesky.com/"><img src="http://www.yesky.com/TLimages/head/img/ras_0608.gif" alt="RSS订阅" border="0" /></a></div>');} else {var pcurl2=abcurl.substring(7);document.write('<div class="jtft_head0607"><a href="http://big5.yesky.com/b5/'+pcurl2+'"><img src="http://www.yesky.com/TLimages/head/img/fanti_0608.gif" alt="繁体版" border="0" /></a> <a href="http://rss.yesky.com/"><img src="http://www.yesky.com/TLimages/head/img/ras_0608.gif" alt="RSS订阅" border="0" /></a></div>');} </SCRIPT>
<DIV class=right_head0607><IMG src="用VC++实现图像检索技术2.files/ssright_0608.gif"
border=0></DIV></DIV>
<SCRIPT language=JavaScript>function MM_jumpMenu(targ,selObj,restore){ eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0;}</SCRIPT>
<DIV class=head_head0607>
<DIV class=logo_head0607><A href="http://www.yesky.com/"><IMG title=天极Yesky
alt=天极Yesky src="用VC++实现图像检索技术2.files/logo.gif"></A></DIV>
<DIV class=ad_head0607><SPAN id=ad1></SPAN></DIV>
<DIV class=other_head0607>
<DIV class=fzbt_head0607>
<DIV class=left_head0607 style="PADDING-TOP: 4px">天极网分站</DIV>
<DIV class=right_head0607 style="PADDING-TOP: 2px"><SELECT class=fzselect
onchange='MM_jumpMenu("parent",this,0)' name=form><OPTION value=1
selected>更多</OPTION> <OPTION
value=http://nx.yesky.com/>宁夏站</OPTION></SELECT></DIV></DIV>
<DIV class=fzlj_head0607><A href="http://bj.yesky.com/">北京站</A> <A
href="http://sh.yesky.com/">上海站</A> <A href="http://gd.yesky.com/">广东站</A><BR><A
href="http://cq.yesky.com/">重庆站</A> <A href="http://cd.yesky.com/">成都站</A> <A
href="http://sy.yesky.com/">沈阳站</A></DIV></DIV></DIV><!--注册登陆及广告两行结束--><!--产品及导航两行开始--><!--产品开始-->
<DIV class=pro_head0607>
<DIV class=proleft_head0607><IMG src="用VC++实现图像检索技术2.files/proleft.gif"
border=0></DIV>
<DIV class=prorightbody_head0607>
<LI><A href="http://notebook.yesky.com/"><IMG alt=笔记本电脑
src="用VC++实现图像检索技术2.files/cp01.gif" border=0></A><BR><A
href="http://notebook.yesky.com/">笔记本</A> </LI>
<LI><A href="http://pc.yesky.com/"><IMG alt=台式电脑
src="用VC++实现图像检索技术2.files/cp02.gif" border=0></A><BR><A
href="http://pc.yesky.com/">台式机</A> </LI>
<LI><A href="http://mobile.yesky.com/"><IMG alt=手机
src="用VC++实现图像检索技术2.files/cp03.gif" border=0></A><BR><A
href="http://mobile.yesky.com/">手机</A> </LI>
<LI
style="PADDING-RIGHT: 3px; PADDING-LEFT: 4px; PADDING-BOTTOM: 0px; PADDING-TOP: 10px"><IMG
src="用VC++实现图像检索技术2.files/cpline_0608.gif" border=0> </LI>
<LI><A href="http://diy.yesky.com/"><IMG alt=电脑硬件DIY
src="用VC++实现图像检索技术2.files/cp08.gif" border=0></A><BR><A
href="http://diy.yesky.com/"><FONT color=#ff6600>DIY硬件</FONT></A> </LI>
<LI class=prolinkli style="TEXT-ALIGN: left"><A
href="http://diy.yesky.com/cpu/">CPU</A><BR><A
href="http://diy.yesky.com/mainboard/">主板</A><BR><A
href="http://diy.yesky.com/speaker/">音箱</A> </LI>
<LI class=prolinkli><A href="http://diy.yesky.com/harddisk/">硬盘</A><BR><A
href="http://diy.yesky.com/vga/">显卡</A><BR><A
href="http://diy.yesky.com/input/">键鼠</A> </LI>
<LI class=prolinkli style="TEXT-ALIGN: left"><A
href="http://diy.yesky.com/rom/">刻录机</A><BR><A
href="http://diy.yesky.com/monitor/">显示器</A><BR><A
href="http://diy.yesky.com/power/">机箱电源</A> </LI>
<LI
style="PADDING-RIGHT: 4px; PADDING-LEFT: 6px; PADDING-BOTTOM: 0px; PADDING-TOP: 10px"><IMG
src="用VC++实现图像检索技术2.files/cpline_0608.gif" border=0> </LI>
<LI style="PADDING-TOP: 10px"><A href="http://digital.yesky.com/"><FONT
color=#ff6600>数<BR>码</FONT></A> </LI>
<LI><A href="http://dc.yesky.com/"><IMG alt=数码相机DC
src="用VC++实现图像检索技术2.files/cp06.gif" border=0></A><BR><A
href="http://dc.yesky.com/">数码相机</A> </LI>
<LI><A href="http://mp3.yesky.com/"><IMG alt=MP3播放器
src="用VC++实现图像检索技术2.files/cp04.gif" border=0></A><BR><A
href="http://mp3.yesky.com/">MP3</A> </LI>
<LI><A href="http://mp4.yesky.com/"><IMG alt=MP4播放器
src="用VC++实现图像检索技术2.files/cp05.gif" border=0></A><BR><A
href="http://mp4.yesky.com/">MP4</A> </LI>
<LI><A href="http://dv.yesky.com/"><IMG alt=数码摄像机DV
src="用VC++实现图像检索技术2.files/cp07.gif" border=0></A><BR><A
href="http://dv.yesky.com/">摄像机</A> </LI>
<LI
style="PADDING-RIGHT: 4px; PADDING-LEFT: 5px; PADDING-BOTTOM: 0px; PADDING-TOP: 10px"><IMG
src="用VC++实现图像检索技术2.files/cpline_0608.gif" border=0> </LI>
<LI><A href="http://oa.yesky.com/"><IMG alt=电脑外设
src="用VC++实现图像检索技术2.files/cp09.gif" border=0></A><BR><A
href="http://oa.yesky.com/">外设</A> </LI>
<LI><A href="http://net.yesky.com/"><IMG alt=网络
src="用VC++实现图像检索技术2.files/cp10.gif" border=0></A><BR><A
href="http://net.yesky.com/">网络</A> </LI>
<LI><A href="http://server.chinabyte.com/"><IMG alt=服务器
src="用VC++实现图像检索技术2.files/cp11.gif" border=0></A><BR><A
href="http://server.chinabyte.com/">服务器</A> </LI>
<LI><A href="http://dh.yesky.com/"><IMG alt=数字家庭
src="用VC++实现图像检索技术2.files/cp12.gif" border=0></A><BR><A
href="http://dh.yesky.com/">数字家庭</A> </LI></DIV>
<DIV class=proright_head0607><IMG src="用VC++实现图像检索技术2.files/proright.gif"
width=10 border=0></DIV></DIV><!--产品结束--><!--导航开始-->
<DIV class=dh_head0607>
<DIV class=dhbody_head0607><A href="http://product.yesky.com/">查产品</A> <A
href="http://cseek.yesky.com/">看行情</A> <A
href="http://www.yesky.com/jxs/">经销商</A> <A
href="http://price.yesky.com/">导购</A> <A href="http://lab.yesky.com/">评测</A> <A
href="http://z.yesky.com/">互动杂志</A> | <A href="http://soft.yesky.com/">软件</A> <A
href="http://design.yesky.com/">设计</A> <A
href="http://homepage.yesky.com/">网页</A> <A href="http://dev.yesky.com/">开发</A>
<A href="http://soft.yesky.com/security/">安全</A> <A
href="http://bbs.yesky.com/">论坛</A> | <A href="http://q.yesky.com/">群乐</A> <A
href="http://e.yesky.com/">E时代</A> <A href="http://game.yesky.com/">游戏</A> <A
href="http://pic.yesky.com/">图片</A> <A href="http://desktop.yesky.com/">壁纸</A>
<A href="http://comic.yesky.com/">动漫</A> <A href="http://my.yesky.com/">社区</A>
<A href="http://www.mydown.com/">下载</A> <A href="http://hot.yesky.com/">网摘</A>
<A href="http://blog.yesky.com/">博客</A> </DIV></DIV><!--导航结束--><!--产品及导航两行结束--><!--笔记本导航条-->
<DIV class=box>
<DIV class=bgpic>您现在的位置: <A href="http://www.yesky.com/index.shtml">天极Yesky</A>
> <A href="http://soft.yesky.com/index.shtml">软件</A> > <A
href="http://soft.yesky.com/lesson/index.shtml">专题教程</A> </DIV></DIV>
<DIV class=clear1></DIV>
<DIV class=box>
<DIV class=guanggao><SPAN id=contentAdv></SPAN></DIV> <B><FONT color=#ac000>二.
具体程序实现</FONT></B><BR><BR> <B>a)
基于子块颜色直方图方法的程序实现:</B><BR><BR> 将图片分成4×4格局,按从左到右、从上到下的顺序,分别计算各子块的颜色直方图,因此需要设定一个三维数组,前两维为子块的坐标,最后一维为颜色级,但现在采样得到的象素点的颜色值是RGB形式的,因此,需要将RGB形式转换为可以用比较合理的有限数表示的颜色级,而人眼对亮度是最为敏感的,因此可以将RGB转换为亮度值Y,公式为:<BR><BR> Y=R×0.299+G×0.587+B×0.114<BR><BR> 这样就确定的一个256级的颜色级别,而统计颜色直方图的三维数组就可以定义为:int
Color[4][4][256],当采样到某一颜色级时候,将相应的位置加一即可。<BR><BR> 根据以上的子块间的相似公式:<IMG height=54
src="用VC++实现图像检索技术2.files/jt-2003-0121-image011.gif"
width=246>,知道某一颜色级对应的数有可能是分母,当两个颜色级的数都为0的时候,显然是不能统计的,因此需要一个数组记录实际统计过的颜色级数,也需要一个数组记录4×4子块的两幅图像的各子块的相似度。<BR><BR> 对于用户选定的块其实是代表查询对象的,因此应该加大权重,相对来说就是减小其他块的权重,然后可以将乘过对应权重的块的相似度相加,得到最终的相似度,然后将所有目标图像与用户输入的图像的相似度从大到小排序,选出值最大的几张作为最后的查询结果显示出来返回。<BR><BR> 以上是具体实现设想,程序实现如下:<BR><BR>
<P></P>
<TABLE width="100%" bgColor=#ffffff>
<TBODY>
<TR>
<TD>
<P>//基于颜色直方图的方法<BR>pDC->TextOut(10,168,"检索结果:");<BR>CBmpProc
*pDestBmp;<BR>CString comp_pic_path;<BR>double fsim[15];
file://15张待比较的目标图片与用户输入图片的相似度存放的数组<BR>int psim[15];
file://与fsim想对应的图片编号数组,以便显示<BR>for(int
comp_pic=1;comp_pic<=15;comp_pic++){<BR>comp_pic_path.Format("image%d.bmp",comp_pic);<BR>bmp.LoadFromFile(comp_pic_path);
// 从库中读入位图<BR>pDestBmp = (CBmpProc*)new(CBmpProc); //
用new分配类目标<BR>pDestBmp->LoadFromObject(bmp,
&CRect(0,0,128,128));<BR>//
从bmp中的指定区域读入图像,以便图片匹配的进行<BR>pDestBmp->CalculateColor(*pDC);
file://计算目标图片的颜色直方图<BR>int
x1,x2,y1,y2,x3,x4,y3,y4;<BR>x1=obj_set.m_x1;x2=obj_set.m_x2;x3=obj_set.m_x3;x4=obj_set.m_x4;<BR>y1=obj_set.m_y1;y2=obj_set.m_y2;y3=obj_set.m_y3;y4=obj_set.m_y4;<BR>file://用户输入的对象所在子块(既用户选定的4个子块)的坐标<BR>double
sim[4][4]; file://子块之间的相似度数组<BR>int ccount[4][4];
file://有过统计的颜色数目记录数组<BR>for(int i=0;i<4;i++)<BR>for(int
j=0;j<4;j++){<BR>sim[i][j]=0;<BR>ccount[i][j]=0;<BR>}<BR>file://以下两个for按公式计算两幅图像的各对应子块之间的相似度<BR>for(i=0;i<4;i++)<BR>for(int
j=0;j<4;j++)<BR>for(int
k=0;k<256;k++){<BR>if((pDestBmp->Color[i][j][k]>=pBmp->Color[i][j][k])&&pDestBmp->Color[i][j][k]!=0){<BR>sim[i][j]+=(1-((fabs(pDestBmp->Color[i][j][k]-pBmp->Color[i][j][k]))/(pDestBmp->Color[i][j][k])));<BR>ccount[i][j]++;<BR>}<BR>if((pDestBmp->Color[i][j][k]<PBMP->Color[i][j][k])&&pBmp->Color[i][j][k]!=0){<BR>sim[i][j]+=(1-((fabs(pDestBmp->Colori][j][k]-pBmp->Color[i][j][k]))/(pBmp->Color[i][j][k])));<BR> ccount[i][j]++;<BR> }<BR> }<BR>for(i=0;i<4;i++)<BR>for(int
j=0;j<4;j++){<BR>sim[i][j]=sim[i][j]/ccount[i][j];<BR>}
<BR>file://计算两图像最终的相似度结果<BR>double
final_sim=0;<BR>for(i=0;i<4;i++)<BR>for(int
j=0;j<4;j++){<BR>file://对用户指定的块设置权重为1<BR>if((i==x1&&j==y1)||(i==x2&&j==y2)||(i==x3&&j==y3)||(i==x4&&j==y4))<BR>final_sim+=sim[i][j];<BR>else<BR>file://其他块降低权重为0.7,提高对对象匹配的精确度<BR>final_sim+=(sim[i][j]*0.7);<BR>}<BR>file://将15幅被比较图像与用户输入源图像的最后计算出来的相似度结果记录在数组中<BR>fsim[comp_pic-1]=final_sim;
<BR>delete (CBmpProc*)pDestBmp;<BR>}<BR>int count=15;double tempf;int
tempp;<BR>for(int l=0;l<15;l++){<BR>psim[l]=l+1;
file://设定编号数组<BR>}<BR>file://将15个相似度从大到小排列,并且改变次序的时候编号数组和跟着改变<BR>for(int
i=count;i>0;i--){<BR>for(int
j=0;j<I-1;J++)<BR>if(fsim[j]<FSIM[J+1]){<BR>tempf=fsim[j];<BR>tempp=psim[j];<BR>fsim[j]=fsim[j+1];<BR>psim[j]=psim[j+1];<BR>fsim[j+1]=tempf;<BR>psim[j+1]=tempp;<BR>}<BR>}<BR>int
disp=0;<BR>int space=-128;<BR>file://将相似度最大的的两张图片显示出来<BR>for(int
disp_pic=1;disp_pic<=2;disp_pic++){<BR>comp_pic_path.Format("image%d.bmp",psim[disp_pic]);<BR>bmp.LoadFromFile(comp_pic_path);
// 从库中读入位图<BR>pDestBmp = (CBmpProc*)new(CBmpProc); //
用new分配类目标<BR>pDestBmp->LoadFromObject(bmp, &CRect(0,0,128,128)); //
从bmp中的指定区域读入图像<BR>disp++;<BR>space+=128;<BR>pDC->Rectangle(10+space-1,190-1,138+space+1,318+1);<BR>pDestBmp->Draw(*pDC,
&CRect(10+space,190,138+space,318));<BR>//
将pBmp中的图像绘入DC的指定区域<BR>space+=6; <BR>}<BR>delete (CBmpProc*)pBmp; //
删除类目标,delete会自动调用类的析构函数。<BR>AfxMessageBox("检索完成");
<BR>}</P></TD></TR></TBODY></TABLE>
<P></P>
<DIV class=right>共3页。 <A class=page
href="http://www.yesky.com/466/1649466.shtml" target=_self><FONT
face=Webdings>9</FONT></A> <A class=page
href="http://www.yesky.com/466/1649466.shtml" target=_self><FONT
face=Webdings>7</FONT></A> <A class=page
href="http://www.yesky.com/466/1649466.shtml" target=_self><B>1</B></A> <A
class=page href="http://www.yesky.com/466/1649466_1.shtml" target=_self><FONT
color=#666666><B>2</B></FONT></A> <A class=page
href="http://www.yesky.com/466/1649466_2.shtml" target=_self><B>3</B></A> <A
class=page href="http://www.yesky.com/466/1649466_2.shtml" target=_self><FONT
face=Webdings>8</FONT></A> <A class=page
href="http://www.yesky.com/466/1649466_2.shtml" target=_self><FONT
face=Webdings>:</FONT></A></DIV></DIV>
<DIV class=clear></DIV><!--文章评论-->
<DIV class=box>
<SCRIPT language=JavaScript>
<!--
var aid = 1649466;
var channelid = 324;
var tagname = "";
//-->
</SCRIPT>
<DIV class=newxiangguan>
<DIV class=newxiangguanmenu><A href="http://my.yesky.com/"
target=_blank>天极社区</A>邀请您:<A class=red-s href="http://blog.yesky.com/"
target=_blank>写博客</A> <A class=red-s href="http://photo.yesky.com/"
target=_blank>上传相片</A> <A class=red-s href="http://bbs.yesky.com/"
target=_blank>论坛聊天</A> <A class=red-s href="http://maillist.yesky.com/"
target=_blank>订阅电子杂志</A> <A class=red-s
href="http://www.yeecai.com/mobileant/tjadd/tjload.html"
target=_blank>彩信蚂蚁</A> <A class=red-s
href="http://hot.yesky.com/">推荐网摘</A> <A class=red-s
href="http://training.yesky.com/">IT培训</A> <A class=red-s
href="javascript:sendemail()" target=_self>对此感兴趣</A> <A
title="推荐到天极网摘 http://hot.yesky.com [鼠标划选本文摘要,然后点击本图片]"
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(yesky=window.open('http://hot.yesky.com/dp.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t)+'&st=2','yesky','scrollbars=no,width=400,height=480,left=75,top=20,status=no,resizable=yes'));yesky.focus();"
target=_self><IMG src="用VC++实现图像检索技术2.files/souchang1.gif" border=0></A>
</DIV></DIV>
<DIV class=pinlunbox>
<DIV class=pinlunguan3><SPAN id=commentsSpanText>
<SCRIPT language=JavaScript><!--function getTagId(tName) { tName = tName.replace(/(^[\s ]*)|([\s ]*$)/g, ""); var tagid = 0; for(var ti = 0; ti < tName.length; ti++) { tagid += tName.charCodeAt(ti); } return tagid;}function UrlEncode(str){ var i,temp,p,q; var result=""; str = str.replace(/(^[\s ]*)|([\s ]*$)/g, ""); for(i=0;i<str.length;i++){ temp = str.charCodeAt(i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -