matlab界面UI设计资料

一个实现图像灰度处理并归类于某已知相似图片的程序

软件:matlab2017a

算法:HU检索图像算法、Zernike算法

资料:

①:

matlab遍历文件夹下所有图片和遍历所有子文件夹下图片 - 专于技术,相信自我 - 博客园

https://www.cnblogs.com/tansuoxinweilai/p/9990191.html

②:

matlab设计gui文本框,怎么获取文本框输入的字符呢?_百度知道
https://zhidao.baidu.com/question/751372596254114212.html

ARMA Model Specifications - MATLAB & Simulink - MathWorks 中国
https://ww2.mathworks.cn/help/econ/arma-models.html?searchHighlight=arma&s_tid=doc_srchtitle

④:

MATLAB产生各种分布的随机数 - 百度文库
https://wenku.baidu.com/view/daa8cfeb02020740bf1e9b70.html

HU算法:用返回的七维向量作为一个图像的特征

  1 %**************************************************************************
  2 %图像检索——形状特征提取
  3 %利用HU的七个不变矩作为形状特征向量
  4 %Image : 输入图像数据
  5 %n: 返回七维形状特征行向量
  6 %**************************************************************************
  7 function n = Shape(Image)
  8 
  9  Image = imread('C:\Users\linuas\Desktop\test.jpg');
 10  [M,N,O] = size(Image);
 11 M = 256;
 12 N = 256;
 13 
 14 %--------------------------------------------------------------------------
 15 %彩色图像灰度化
 16 %--------------------------------------------------------------------------
 17 Gray = double(0.3*Image(:,:,1)+0.59*Image(:,:,2)+0.11*Image(:,:,3));
 18 
 19 %--------------------------------------------------------------------------
 20 %用Canny边缘检测提取边缘保留边缘灰度图像
 21 %--------------------------------------------------------------------------
 22 % BW = uint8(edge(Gray,'canny'));
 23 Egray = uint8(edge(Gray,'canny'));
 24 for i = 1:M
 25     for j = 1:N
 26         if Egray(i,j)==0
 27             Gray(i,j)=0;
 28         end
 29     end
 30 end
 31 
 32 %--------------------------------------------------------------------------
 33 %Otsu提出的类判别分析法自动为每一幅廓图像选定阈值,然后用该阈值对图像二值化
 34 %--------------------------------------------------------------------------
 35 %计算灰度级归一化直方图
 36 for i = 0:255
 37     h(i+1) = size(find(Gray==i),1);
 38 end
 39 p = h/sum(h);
 40 %计算灰度均值
 41 ut = 0;
 42 for i = 0:255
 43     ut = i*p(i+1)+ut;
 44 end
 45 %计算直方图的零阶累积矩和一阶累积矩:
 46 for k = 0:254
 47     w(k+1) = sum(p(1:k+1));
 48     u(k+1) = sum((0:k).*p(1:k+1));
 49 end
 50 %计算类分离指标
 51 deltaB = zeros(1,255);
 52 for k = 0:254    
 53     if w(k+1)~=0&w(k+1)~=1
 54         deltaB(k+1) = (ut*w(k+1)-u(k+1))^2/(w(k+1)*(1-w(k+1)));
 55     end
 56 end
 57 [value,thresh] = max(deltaB);
 58 % deltaB = zeros(1,255);
 59 % delta1 = zeros(1,255);
 60 % delta2 = zeros(1,255);
 61 % deltaW = zeros(1,255);
 62 % for k = 0:254
 63 %     if w(k+1)~=0&w(k+1)~=1
 64 %         deltaB(k+1) = (ut*w(k+1)-u(k+1))^2/(w(k+1)*(1-w(k+1)));
 65 %         delta1(k+1) = 0;
 66 %         delta2(k+1) = 0;
 67 %         for i = 0:k
 68 %             delta1(k+1) = (i-u(k+1)/w(k+1))^2*p(i+1)+delta1(k+1);
 69 %         end
 70 %         for i = k+1:255
 71 %             delta2(k+1) = (i-(ut-u(k+1))/(1-w(k+1)))^2*p(k+1)+delta2(k+1);
 72 %         end
 73 %         deltaW(k+1) = delta1(k+1)+delta2(k+1);
 74 %     end
 75 % end
 76 % for i = 1:255
 77 %     if deltaB==0
 78 %         yita=0;
 79 %     else
 80 %         yita(i) = 1/(1+deltaW(i)./deltaB(i));
 81 %     end
 82 % end
 83 % % D的最大值作为最佳阈值
 84 % [value,thresh] = max(yita);
 85 
 86 %对图像二值化
 87 for i = 1:M
 88     for j = 1:N
 89         if Gray(i,j)>=thresh
 90             BW(i,j) = 1;
 91         else
 92             BW(i,j) = 0;
 93         end
 94     end
 95 end
 96 
 97 %--------------------------------------------------------------------------
 98 %计算图像质心:(I,J)
 99 %--------------------------------------------------------------------------
100 m00 = sum(sum(BW)); %零阶矩
101 m01 = 0;              %一阶矩 
102 m10 = 0;              %一阶矩
103 for i = 1:M
104     for j = 1:N
105         m01 = BW(i,j)*j+m01;
106         m10 = BW(i,j)*i+m10;
107     end
108 end
109 I = (m10)/(m00);
110 J = m01/m00;
111 
112 %--------------------------------------------------------------------------
113 %中心矩:
114 %--------------------------------------------------------------------------
115 u11 = 0;
116 u20 = 0; u02 = 0;
117 u30 = 0; u03 = 0;
118 u12 = 0; u21 = 0;
119 for i = 1:M
120     for j = 1:N
121         u20 = BW(i,j)*(i-I)^2+u20;
122         u02 = BW(i,j)*(j-J)^2+u02;
123         u11 = BW(i,j)*(i-I)*(j-J)+u11;
124         u30 = BW(i,j)*(i-I)^3+u30;
125         u03 = BW(i,j)*(j-J)^3+u03;
126         u12 = BW(i,j)*(i-I)*(j-J)^2+u12;
127         u21 = BW(i,j)*(i-I)^2*(j-J)+u21;
128     end
129 end
130 u20 = u20/m00^2;
131 u02 = u02/m00^2;
132 u11 = u11/m00^2;
133 u30 = u30/m00^(5/2);
134 u03 = u03/m00^(5/2);
135 u12 = u12/m00^(5/2);
136 u21 = u21/m00^(5/2);
137 %--------------------------------------------------------------------------
138 %7个Hu不变矩:
139 %--------------------------------------------------------------------------
140 n(1) = u20+u02;
141 n(2) = (u20-u02)^2+4*u11^2;
142 n(3) = (u30-3*u12)^2+(u03-3*u21)^2;
143 n(4) = (u30+u12)^2+(u03+u21)^2;
144 n(5) = (u30-3*u12)*(u30+u12)*((u30+u12)^2-3*(u03+u21)^2)+(u03-3*u21)*(u03+u21)*((u03+u21)^2-3*(u30+u12)^2);
145 n(6) = (u20-u02)*((u30+u12)^2-(u03+u21)^2)+4*u11*(u30+u12)*(u03+u21);
146 n(7) = (3*u21-u03)*(u30+u12)*((u30+u12)^2-3*(u03+u21)^2)+(u30-3*u12)*(u03+u21)*((u03+u21)^2-3*(u30+u12)^2);% %--------------------------------------------------------------------------
147 % %内部归一化:
148 % %--------------------------------------------------------------------------
149  en = mean(n);
150  delta = sqrt(cov(n));
151  n = abs(n-en)/(3*delta);

 

上一篇:使用Socket简单模拟C/S消息传递——Java(31)


下一篇:寻找瞳孔初级