怎样用matlab提取图像的纹理特征?

如题所述

其实学数字图像处理,关键的不是源代码(和一般编程还是有区别的,这个是经验之谈,其实一般博导未必会编程,但是你和他说说你的方法,他一般都能切中要害),而是你能理解基于概念及适用场所。
基于颜色、纹理、形状都属于低层特征,这些你理解就够了,关键是对你的课题适合哪种方法来映射到高层语义上面,例如:识别物体轮廓,那可能形状就比较适合等。
我之所以写上面那段话,主要是我感觉你索取代码也不说明具体要求,也就是方向不明确。
如今颜色特征提取算法有很多,诸如颜色直方图、颜色矩、颜色集、颜色聚合向量、颜色相关图等,既然你没说,我就给个IEEE CSVT 2001的一篇关于颜色直方图法的论文(源码版权归作者所有):
function colorhist = colorhist(rgb)
% CBIR_colorhist() --- color histogram calculation
% input: MxNx3 image data, in RGB
% output: 1x256 colorhistogram == (HxSxV = 16x4x4)
% as the MPEG-7 generic color histogram descriptor
% [Ref] Manjunath, B.S.; Ohm, J.-R.; Vasudevan, V.V.; Yamada, A., "Color and texture descriptors"
% IEEE Trans. CSVT, Volume: 11 Issue: 6 , Page(s): 703 -715, June 2001 (section III.B)
% check input
if size(rgb,3)~=3
error('3 components is needed for histogram');
end
% globals
H_BITS = 4; S_BITS = 2; V_BITS = 2;
%rgb2hsv可用rgb2hsi代替,见你以前的提问。
hsv = uint8(255*rgb2hsv(rgb));

imgsize = size(hsv);
% get rid of irrelevant boundaries
i0=round(0.05*imgsize(1)); i1=round(0.95*imgsize(1));
j0=round(0.05*imgsize(2)); j1=round(0.95*imgsize(2));
hsv = hsv(i0:i1, j0:j1, :);

% histogram
for i = 1 : 2^H_BITS
for j = 1 : 2^S_BITS
for k = 1 : 2^V_BITS
colorhist(i,j,k) = sum(sum( ...
bitshift(hsv(:,:,1),-(8-H_BITS))==i-1 &...
bitshift(hsv(:,:,2),-(8-S_BITS))==j-1 &...
bitshift(hsv(:,:,3),-(8-V_BITS))==k-1 ));
end
end
end
colorhist = reshape(colorhist, 1, 2^(H_BITS+S_BITS+V_BITS));
% normalize
colorhist = colorhist/sum(colorhist);

%基于纹理特征提取灰度共生矩阵用于纹理判断
% Calculates cooccurrence matrix
% for a given direction and distance
%
% out = cooccurrence (input, dir, dist, symmetric);
%
% INPUT:
% input: input matrix of any size
%
% dir: direction of evaluation
% "dir" value Angle
% 0 0
% 1 -45
% 2 -90
% 3 -135
% 4 -180
% 5 +135
% 6 +90
% 7 +45
%
% dist: distance between pixels
%
% symmetric: 1 for symmetric version
% 0 for non-symmetric version
%
% eg: out = cooccurrence (input, 0, 1, 1);
% Author: Baran Aydogan (15.07.2006)
% RGI, Tampere University of Technology
% baran.aydogan@tut.fi

function out = cooccurrence (input, dir, dist, symmetric);

input = round(input);
[r c] = size(input);

min_intensity = min(min(input));
max_intensity = max(max(input));

out = zeros(max_intensity-min_intensity+1);
if (dir == 0)
dir_x = 0; dir_y = 1;
end

if (dir == 1)
dir_x = 1; dir_y = 1;
end

if (dir == 2)
dir_x = 1; dir_y = 0;
end

if (dir == 3)
dir_x = 1; dir_y = -1;
end

if (dir == 4)
dir_x = 0; dir_y = -1;
end

if (dir == 5)
dir_x = -1; dir_y = -1;
end

if (dir == 6)
dir_x = -1; dir_y = 0;
end

if (dir == 7)
dir_x = -1; dir_y = 1;
end

dir_x = dir_x*dist;
dir_y = dir_y*dist;

out_ind_x = 0;
out_ind_y = 0;

for intensity1 = min_intensity:max_intensity
out_ind_x = out_ind_x + 1;
out_ind_y = 0;

[ind_x1 ind_y1] = find (input == intensity1);
ind_x1 = ind_x1 + dir_x;
ind_y1 = ind_y1 + dir_y;

for intensity2 = min_intensity:max_intensity
out_ind_y = out_ind_y + 1;

[ind_x2 ind_y2] = find (input == intensity2);

count = 0;

for i = 1:size(ind_x1,1)
for j = 1:size(ind_x2,1)
if ( (ind_x1(i) == ind_x2(j)) && (ind_y1(i) == ind_y2(j)) )
count = count + 1;
end
end
end

out(out_ind_x, out_ind_y) = count;

end
end

if (symmetric)

if (dir < 4)
dir = dir + 4;
else
dir = mod(dir,4);
end
out = out + cooccurrence (input, dir, dist, 0);
end
温馨提示:内容为网友见解,仅供参考
第1个回答  2022-12-06
其实学数字图像处理,关键的不是源代码(和一般编程还是有区别的,这个是经验之谈,其实一般博导未必会编程,但是你和他说说你的方法,他一般都能切中要害),而是你能理解基于概念及适用场所。\x0d\x0a基于颜色、纹理、形状都属于低层特征,这些你理解就够了,关键是对你的课题适合哪种方法来映射到高层语义上面,例如:识别物体轮廓,那可能形状就比较适合等。\x0d\x0a我之所以写上面那段话,主要是我感觉你索取代码也不说明具体要求,也就是方向不明确。\x0d\x0a如今颜色特征提取算法有很多,诸如颜色直方图、颜色矩、颜色集、颜色聚合向量、颜色相关图等,既然你没说,我就给个IEEECSVT2001的一篇关于颜色直方图法的论文(源码版权归作者所有):\x0d\x0afunctioncolorhist=colorhist(rgb)\x0d\x0a%CBIR_colorhist()---colorhistogramcalculation\x0d\x0a%input:MxNx3imagedata,inRGB\x0d\x0a%output:1x256colorhistogram==(HxSxV=16x4x4)\x0d\x0a%astheMPEG-7genericcolorhistogramdescriptor\x0d\x0a%[Ref]Manjunath,B.S.;Ohm,J.-R.;Vasudevan,V.V.;Yamada,A.,"Colorandtexturedescriptors"\x0d\x0a%IEEETrans.CSVT,Volume:11Issue:6,Page(s):703-715,June2001(sectionIII.B)\x0d\x0a%checkinput\x0d\x0aifsize(rgb,3)~=3\x0d\x0aerror('3componentsisneededforhistogram');\x0d\x0aend\x0d\x0a%globals\x0d\x0aH_BITS=4;S_BITS=2;V_BITS=2;\x0d\x0a%rgb2hsv可用rgb2hsi代替,见你以前的提问。\x0d\x0ahsv=uint8(255*rgb2hsv(rgb));\x0d\x0a\x0d\x0aimgsize=size(hsv);\x0d\x0a%getridofirrelevantboundaries\x0d\x0ai0=round(0.05*imgsize(1));i1=round(0.95*imgsize(1));\x0d\x0aj0=round(0.05*imgsize(2));j1=round(0.95*imgsize(2));\x0d\x0ahsv=hsv(i0:i1,j0:j1,:);\x0d\x0a\x0d\x0a%histogram\x0d\x0afori=1:2^H_BITS\x0d\x0aforj=1:2^S_BITS\x0d\x0afork=1:2^V_BITS\x0d\x0acolorhist(i,j,k)=sum(sum(...\x0d\x0abitshift(hsv(:,:,1),-(8-H_BITS))==i-1&...\x0d\x0abitshift(hsv(:,:,2),-(8-S_BITS))==j-1&...\x0d\x0abitshift(hsv(:,:,3),-(8-V_BITS))==k-1));\x0d\x0aend\x0d\x0aend\x0d\x0aend\x0d\x0acolorhist=reshape(colorhist,1,2^(H_BITS+S_BITS+V_BITS));\x0d\x0a%normalize\x0d\x0acolorhist=colorhist/sum(colorhist);\x0d\x0a\x0d\x0a%基于纹理特征提取灰度共生矩阵用于纹理判断\x0d\x0a%Calculatescooccurrencematrix\x0d\x0a%foragivendirectionanddistance\x0d\x0a%\x0d\x0a%out=cooccurrence(input,dir,dist,symmetric);\x0d\x0a%\x0d\x0a%INPUT:\x0d\x0a%input:inputmatrixofanysize\x0d\x0a%\x0d\x0a%dir:directionofevaluation\x0d\x0a%"dir"valueAngle\x0d\x0a%00\x0d\x0a%1-45\x0d\x0a%2-90\x0d\x0a%3-135\x0d\x0a%4-180\x0d\x0a%5+135\x0d\x0a%6+90\x0d\x0a%7+45\x0d\x0a%\x0d\x0a%dist:distancebetweenpixels\x0d\x0a%\x0d\x0a%symmetric:1forsymmetricversion\x0d\x0a%0fornon-symmetricversion\x0d\x0a%\x0d\x0a%eg:out=cooccurrence(input,0,1,1);\x0d\x0a%Author:BaranAydogan(15.07.2006)\x0d\x0a%RGI,TampereUniversityofTechnology\x0d\x0a%baran.aydogan@tut.fi\x0d\x0a\x0d\x0afunctionout=cooccurrence(input,dir,dist,symmetric);\x0d\x0a\x0d\x0ainput=round(input);\x0d\x0a[rc]=size(input);\x0d\x0a\x0d\x0amin_intensity=min(min(input));\x0d\x0amax_intensity=max(max(input));\x0d\x0a\x0d\x0aout=zeros(max_intensity-min_intensity+1);\x0d\x0aif(dir==0)\x0d\x0adir_x=0;dir_y=1;\x0d\x0aend\x0d\x0a\x0d\x0aif(dir==1)\x0d\x0adir_x=1;dir_y=1;\x0d\x0aend\x0d\x0a\x0d\x0aif(dir==2)\x0d\x0adir_x=1;dir_y=0;\x0d\x0aend\x0d\x0a\x0d\x0aif(dir==3)\x0d\x0adir_x=1;dir_y=-1;\x0d\x0aend\x0d\x0a\x0d\x0aif(dir==4)\x0d\x0adir_x=0;dir_y=-1;\x0d\x0aend\x0d\x0a\x0d\x0aif(dir==5)\x0d\x0adir_x=-1;dir_y=-1;\x0d\x0aend\x0d\x0a\x0d\x0aif(dir==6)\x0d\x0adir_x=-1;dir_y=0;\x0d\x0aend\x0d\x0a\x0d\x0aif(dir==7)\x0d\x0adir_x=-1;dir_y=1;\x0d\x0aend\x0d\x0a\x0d\x0adir_x=dir_x*dist;\x0d\x0adir_y=dir_y*dist;\x0d\x0a\x0d\x0aout_ind_x=0;\x0d\x0aout_ind_y=0;\x0d\x0a\x0d\x0aforintensity1=min_intensity:max_intensity\x0d\x0aout_ind_x=out_ind_x+1;\x0d\x0aout_ind_y=0;\x0d\x0a\x0d\x0a[ind_x1ind_y1]=find(input==intensity1);\x0d\x0aind_x1=ind_x1+dir_x;\x0d\x0aind_y1=ind_y1+dir_y;\x0d\x0a\x0d\x0aforintensity2=min_intensity:max_intensity\x0d\x0aout_ind_y=out_ind_y+1;\x0d\x0a\x0d\x0a[ind_x2ind_y2]=find(input==intensity2);\x0d\x0a\x0d\x0acount=0;\x0d\x0a\x0d\x0afori=1:size(ind_x1,1)\x0d\x0aforj=1:size(ind_x2,1)\x0d\x0aif((ind_x1(i)==ind_x2(j))&&(ind_y1(i)==ind_y2(j)))\x0d\x0acount=count+1;\x0d\x0aend\x0d\x0aend\x0d\x0aend\x0d\x0a\x0d\x0aout(out_ind_x,out_ind_y)=count;\x0d\x0a\x0d\x0aend\x0d\x0aend\x0d\x0a\x0d\x0aif(symmetric)\x0d\x0a\x0d\x0aif(dir<4)\x0d\x0adir=dir+4;\x0d\x0aelse\x0d\x0adir=mod(dir,4);\x0d\x0aend\x0d\x0aout=out+cooccurrence(input,dir,dist,0);\x0d\x0aend
    官方服务
      官方网站官方网站
相似回答
大家正在搜