媒体特征提取.docx

上传人:b****5 文档编号:7542406 上传时间:2023-01-24 格式:DOCX 页数:13 大小:222.72KB
下载 相关 举报
媒体特征提取.docx_第1页
第1页 / 共13页
媒体特征提取.docx_第2页
第2页 / 共13页
媒体特征提取.docx_第3页
第3页 / 共13页
媒体特征提取.docx_第4页
第4页 / 共13页
媒体特征提取.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

媒体特征提取.docx

《媒体特征提取.docx》由会员分享,可在线阅读,更多相关《媒体特征提取.docx(13页珍藏版)》请在冰豆网上搜索。

媒体特征提取.docx

媒体特征提取

媒体计算方法课程

 

实验总结报告

 

实验名称:

媒体特征提取

学号:

姓名:

日期:

2014-12-23

 

一、实验目的

1、实验目标

以图像媒体为例,对指定的图像数据进行颜色特征、形状特征、局部不变等特征提取处理,体会不同的图像特征提取方法的特点和适用范围。

2、实验涉及到的学习内容

颜色特征提取、形状特征提取、局部不变特征提取(SIFT)。

二、实验具体完成情况

1、总体实验方案

利用matlab编程实现对图像的颜色特征提取、形状特征提取和局部不变特征提取(SIFT)。

2、具体技术途径

matlab图像处理函数。

3、实验结果与分析

(1)颜色特征提取

编写图像的灰度直方图特征提取算法,实现与imHist函数类似的效果。

算法思想:

利用for循环对原始图像进行遍历,统计每个颜色值在图像中的像素个数,根据统计结果绘制直方图。

实验结果

图1本算法绘制的原始图像的直方图

图2imhist函数绘制的原始图像直方图

(2)形状特征提取

通过边缘检测等方法提取简单图像的边界特征,并用链码的方式保存图像的形状特征。

算法思想:

对原始图像进行边缘提取,在得到的边缘特征矩阵中寻找一个非零点,即边缘像素点,从该点开始,沿顺时针方向遍历其相邻8个像素点,记录第一个非零点的相对位置。

再遍历这个边缘像素点周围的像素点,寻找下一个边缘像素点,直到重新遍历到初始点停止。

实验结果

图3原始图像

图4提取的图像边缘特征

算法只提取了图像的边缘特征,并直接调用matlab的fchcode函数对图像边缘特征链码表示。

(3)局部不变特征提取

对于选定的某幅图像,提取SIFT局部不变特征,体会该特征的旋转、尺度、光照等不变性。

算法思想:

构建原始图像高斯金字塔;再同尺度相邻相差构建差分高斯金字塔;寻找尺度空间极值点,并删除错误点,其余为关键点;计算关键点坐标和所处的尺度;以关键点邻域梯度的主方向作为该点的方向特征。

这里是使用别人写好的SIFT特征提取类函数,自己对其进行调用来实现特征提取以及匹配。

实验结果

图5原始图像

图6提取的原始图像的SIFT特征信息

图7相似图像的SIFT特征匹配

三、存在的主要问题和建议

三个小的实验算法思想并不难,但是在实现过程中发现自己的编程水平还有欠缺,理解了算法的思想,但是由于技术所限不能够按照算法思想自己编写一套程序。

只能调用别人写好的函数实现自己预想的功能。

另外此次实验都是在matlab中实现的,但在以后的工程实践中可能更多的是使用opencv,所以接下来要学习一下opencv的使用,现已在自己电脑的vs2010上配置好了opencv2.4.2,自己会在学习使用opencv的过程中重新实现以上实验。

附:

程序核心源代码

(1)颜色特征提取

closeall

%imhist直方图特征提取

f1=imread('Fig1202(c)(WashingtonDC_Band3_512).tif');

subplot(1,2,1),imshow(f1),title('WashingtonDC_Band');

subplot(1,2,2),imhist(f1),title('imhist');

%自己编写imhist提取函数

[m,n]=size(f1);

a=zeros(1,256);

fori=1:

m

forj=1:

n

a(f1(i,j)+1)=a(f1(i,j)+1)+1;

end

end

figure();

subplot(1,2,1),imshow(f1),title('WashingtonDC_Band');

subplot(1,2,2),bar(a,'b');

axis([02550max(a)+1000]),title('myself--imhist');

(2)形状特征提取

f=imread('Fig1107(a)(mapleleaf).tif');

g=edge(f,'sobel');

B=boundaries(g);

b=B{1,1};

c=fchcode(b);

(3)尺度不变特征提取(Demo见附件)

%sift.m

%[image,descriptors,locs]=sift(imageFile)

%

%ThisfunctionreadsanimageandreturnsitsSIFTkeypoints.

%Inputparameters:

%imageFile:

thefilenamefortheimage.

%

%Returned:

%image:

theimagearrayindoubleformat

%descriptors:

aK-by-128matrix,whereeachrowgivesaninvariant

%descriptorforoneoftheKkeypoints.Thedescriptorisavector

%of128valuesnormalizedtounitlength.

%locs:

K-by-4matrix,inwhicheachrowhasthe4valuesfora

%keypointlocation(row,column,scale,orientation).The

%orientationisintherange[-PI,PI]radians.

%

%Credits:

ThanksforinitialversionofthisprogramtoD.Alvaroand

%J.J.Guerrero,UniversidaddeZaragoza(modifiedbyD.Lowe)

function[image,descriptors,locs]=sift(imageFile)

%Loadimage

image=imread(imageFile);

%IfyouhavetheImageProcessingToolbox,youcanuncommentthefollowing

%linestoallowinputofcolorimages,whichwillbeconvertedtograyscale.

%ifisrgb(image)

%image=rgb2gray(image);

%end

[rows,cols]=size(image);

%ConvertintoPGMimagefile,readableby"keypoints"executable

f=fopen('tmp.pgm','w');

iff==-1

error('Couldnotcreatefiletmp.pgm.');

end

fprintf(f,'P5\n%d\n%d\n255\n',cols,rows);

fwrite(f,image','uint8');

fclose(f);

%Callkeypointsexecutable

ifisunix

command='!

./sift';

else

command='!

siftWin32';

end

command=[command'tmp.key'];

eval(command);

%Opentmp.keyandcheckitsheader

g=fopen('tmp.key','r');

ifg==-1

error('Couldnotopenfiletmp.key.');

end

[header,count]=fscanf(g,'%d%d',[12]);

ifcount~=2

error('Invalidkeypointfilebeginning.');

end

num=header

(1);

len=header

(2);

iflen~=128

error('Keypointdescriptorlengthinvalid(shouldbe128).');

end

%Createsthetwooutputmatrices(useknownsizeforefficiency)

locs=double(zeros(num,4));

descriptors=double(zeros(num,128));

%Parsetmp.key

fori=1:

num

[vector,count]=fscanf(g,'%f%f%f%f',[14]);%rowcolscaleori

ifcount~=4

error('Invalidkeypointfileformat');

end

locs(i,:

)=vector(1,:

);

[descrip,count]=fscanf(g,'%d',[1len]);

if(count~=128)

error('Invalidkeypointfilevalue.');

end

%Normalizeeachinputvectortounitlength

descrip=descrip/sqrt(sum(descrip.^2));

descriptors(i,:

)=descrip(1,:

);

end

fclose(g);

%showkeys.m

%showkeys(image,locs)

%

%ThisfunctiondisplaysanimagewithSIFTkeypointsoverlayed.

%Inputparameters:

%image:

thefilenamefortheimage(grayscale)

%locs:

matrixinwhicheachrowgivesakeypointlocation(row,

%column,scale,orientation)

functionshowkeys(image,locs)

disp('DrawingSIFTkeypoints...');

%Drawimagewithkeypoints

figure('Position',[5050size(image,2)size(image,1)]);

colormap('gray');

imagesc(image);

holdon;

imsize=size(image);

fori=1:

size(locs,1)

%Drawanarrow,eachlinetransformedaccordingtokeypointparameters.

TransformLine(imsize,locs(i,:

),0.0,0.0,1.0,0.0);

TransformLine(imsize,locs(i,:

),0.85,0.1,1.0,0.0);

TransformLine(imsize,locs(i,:

),0.85,-0.1,1.0,0.0);

end

holdoff;

%------Subroutine:

TransformLine-------

%Drawthegivenlineintheimage,butfirsttranslate,rotate,and

%scaleaccordingtothekeypointparameters.

%

%Parameters:

%Arrays:

%imsize=[rowscolumns]ofimage

%keypoint=[subpixel_rowsubpixel_columnscaleorientation]

%

%Scalars:

%x1,y1;beginingofvector

%x2,y2;endingofvector

functionTransformLine(imsize,keypoint,x1,y1,x2,y2)

%Thescalingoftheunitlengtharrowissettoapproximatelytheradius

%oftheregionusedtocomputethekeypointdescriptor.

len=6*keypoint(3);

%Rotatethekeypointsby'ori'=keypoint(4)

s=sin(keypoint(4));

c=cos(keypoint(4));

%Applytransform

r1=keypoint

(1)-len*(c*y1+s*x1);

c1=keypoint

(2)+len*(-s*y1+c*x1);

r2=keypoint

(1)-len*(c*y2+s*x2);

c2=keypoint

(2)+len*(-s*y2+c*x2);

line([c1c2],[r1r2],'Color','c');

%match.m

%num=match(image1,image2)

%

%Thisfunctionreadstwoimages,findstheirSIFTfeatures,and

%displayslinesconnectingthematchedkeypoints.Amatchisaccepted

%onlyifitsdistanceislessthandistRatiotimesthedistancetothe

%secondclosestmatch.

%Itreturnsthenumberofmatchesdisplayed.

%

%Example:

match('scene.pgm','book.pgm');

functionnum=match(image1,image2)

%FindSIFTkeypointsforeachimage

[im1,des1,loc1]=sift(image1);

[im2,des2,loc2]=sift(image2);

%ForefficiencyinMatlab,itischeapertocomputedotproductsbetween

%unitvectorsratherthanEuclideandistances.Notethattheratioof

%angles(acosofdotproductsofunitvectors)isacloseapproximation

%totheratioofEuclideandistancesforsmallangles.

%

%distRatio:

Onlykeepmatchesinwhichtheratioofvectoranglesfromthe

%nearesttosecondnearestneighborislessthandistRatio.

distRatio=0.6;

%Foreachdescriptorinthefirstimage,selectitsmatchtosecondimage.

des2t=des2';%Precomputematrixtranspose

fori=1:

size(des1,1)

dotprods=des1(i,:

)*des2t;%Computesvectorofdotproducts

[vals,indx]=sort(acos(dotprods));%Takeinversecosineandsortresults

%CheckifnearestneighborhasanglelessthandistRatiotimes2nd.

if(vals

(1)

(2))

match(i)=indx

(1);

else

match(i)=0;

end

end

%Createanewimageshowingthetwoimagessidebyside.

im3=appendimages(im1,im2);

%Showafigurewithlinesjoiningtheacceptedmatches.

figure('Position',[100100size(im3,2)size(im3,1)]);

colormap('gray');

imagesc(im3);

holdon;

cols1=size(im1,2);

fori=1:

size(des1,1)

if(match(i)>0)

line([loc1(i,2)loc2(match(i),2)+cols1],...

[loc1(i,1)loc2(match(i),1)],'Color','c');

end

end

holdoff;

num=sum(match>0);

fprintf('Found%dmatches.\n',num);

%appendimages.m

%im=appendimages(image1,image2)

%

%Returnanewimagethatappendsthetwoimagesside-by-side.

functionim=appendimages(image1,image2)

%Selecttheimagewiththefewestrowsandfillinenoughemptyrows

%tomakeitthesameheightastheotherimage.

rows1=size(image1,1);

rows2=size(image2,1);

if(rows1

image1(rows2,1)=0;

else

image2(rows1,1)=0;

end

%Nowappendbothimagesside-by-side.

im=[image1image2];

 

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

当前位置:首页 > 高等教育 > 理学

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

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