資源簡介
利用matlab實現基于顏色的內容提取,對100副圖片進行分析,找出相互配對的圖形

代碼片段和文件信息
clc
clear
%?tic
%=====================================================================
%參數初始化
q=0;%0,不量化,非0時,將數值量化為16的整數倍值
rbnum=16;%指定分塊個數
cbnum=16;
distancetype=0;%0:絕對值的和?1:歐幾里德距離,
histtype=1;%histtype:直方圖(0)與累積直方圖(1)
%---------------
imagetype=‘bmp‘;%?圖片類型
imagesum=100;%要檢索的圖片庫中圖片的數目
imageadress=‘F:\張霖\多媒體\大作業要求\顏色作業圖庫\‘;
%=====================================================================
if?q==0
????len=256;
else
????len=16;
end
Lhist=zeros(imagesumrbnumcbnumlen);
for?number=1:imagesum
????I=imread([imageadressnum2str(number)‘.‘imagetype]);
????[mn]=size(I(::1));
????L=rgb2gray(I);
????if?q~=0
????????L=floor(double(L)*len/256);
????end
????for?i=1:rbnum
????????for?j=1:cbnum
????????????rs=floor((i-1)*m/rbnum+1);%獲得子塊行位置向量的起止
????????????re=floor(i*m/rbnum);
????????????cs=floor((j-1)*n/cbnum+1);%獲得子塊列位置向量的起止
????????????ce=floor(j*n/cbnum);
????????????LS=L(rs:recs:ce);
????????????sm=(re-rs+1);
????????????sn=(ce-cs+1);
????????????Lhist(numberij:)=hist(reshape(LS1sm*sn)0:len-1)/(sm*sn);%計算直方圖
????????end
????end
end
if?histtype==1
????for?i=2:len
????????Lhist(:::i)=?Lhist(:::i)+?Lhist(:::i-1);
????end
end
%toc
%=====================================================================
%讀入待檢索的圖像
reply?=?input(‘Do?you?want?to?search??Y/N?[Y]:?‘?‘s‘);
while?reply?==?‘Y‘?
????searchnum?=?input(‘Which?one?do?you?want?to?search??(1~100)?[1]:?‘);
????if?isempty(searchnum)
????????searchnum?=?1;
????end
????tic
????d=zeros(1001);
????for?k=1:imagesum
????????dd=zeros(rbnumcbnum);
????????for?i=1:rbnum
????????????for?j=1:cbnum
????????????????if?distancetype==0
????????????????????dd(ij)=sum(abs(Lhist(searchnumij:)-Lhist(kij:)));
????????????????else
????????????????????dd(ij)=sqrt(sum(abs(Lhist(searchnumij:)-Lhist(kij:)).^2));
????????????????end
????????????end
????????end
????????d(k)=sum(sum(dd.^2))/(rbnum*cbnum);
????end
????[imagesortdindex]=sort(d);
????%======================================================================
????%顯示檢索結果
????rows=2;
????cols=3;
????figure
????subplot(rowscols1);
????J=imread([imageadressnum2str(searchnum)‘.‘imagetype]);
????imshow(rgb2gray(J));
????title(‘待檢索圖象灰度圖‘);
????%按照相似度從小到大顯示圖像
????for?i=1:rows*cols-1%只顯示前rows*cols-1個距離最小的圖片
????????J=imread([imageadressnum2str(dindex(i))‘.‘imagetype]);
????????%J=imread([‘C:\imagesearches\imagedatabase1\‘image]);
????????subplot(rowscolsi+1)imshow(J);
????????title([‘No.‘num2str(dindex(i))‘d=‘num2str(imagesort(i))]);
????end
????%??toc
????reply?=?input(‘Do?you?want?to?search??Y/N?[Y]:?‘?‘s‘);
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4081??2009-06-15?11:27??sim_main1.m
?????文件???????2855??2009-06-23?09:32??sim_main.m
-----------?---------??----------?-----??----
?????????????????6936????????????????????2
評論
共有 條評論