飞道的博客

【图像识别】基于k-means聚类的手势识别matlab 源码

211人阅读  评论(0)

一、简介

提取手部轮廓特征,k-means聚类算法,训练得到手势识别模型,然后用测试数据测试。

1 K-means算法原理
K-means算法是最常用的一种聚类算法。算法的输入为一个样本集(或者称为点集),通过该算法可以将样本进行聚类,具有相似特征的样本聚为一类。

针对每个点,计算这个点距离所有中心点最近的那个中心点,然后将这个点归为这个中心点代表的簇。一次迭代结束之后,针对每个簇类,重新计算中心点,然后针对每个点,重新寻找距离自己最近的中心点。如此循环,直到前后两次迭代的簇类没有变化。

下面通过一个简单的例子,说明K-means算法的过程。如下图所示,目标是将样本点聚类成3个类别。
2 基本的步骤为:

step1:选定要聚类的类别数目k(如上例的k=3类),选择k个中心点。

step2:针对每个样本点,找到距离其最近的中心点(寻找组织),距离同一中心点最近的点为一个类,这样完成了一次聚类。

step3:判断聚类前后的样本点的类别情况是否相同,如果相同,则算法终止,否则进入step4。

step4:针对每个类别中的样本点,计算这些样本点的中心点,当做该类的新的中心点,继续step2。

3 上述步骤的关键两点是:

  1. 找到距离自己最近的中心点。
  2. 更新中心点。

二、源代码


  
  1. %------------------hand shape analysis
  2. %
  3. close all
  4. format long %显示小数点后4位的数据
  5. %读入hand的landmark数值
  6. fid=fopen( 'shapes.txt');
  7. hand=fscanf(fid, '%g %g',[ 40,inf]); % X(1,1)X(2,1)...X(56,1);X(1,2)X(2,2)...X(56,2)
  8. % choose 40 shapes as a row column
  9. Shape= 600*hand;
  10. %-----------------------------------------------------
  11. % shape 矩阵每行112列,对应一个手的数据,
  12. % 前56列对应X坐标 后56列对应Y坐标
  13. % Odata中所有形状的质点已经平移到原点
  14. temp=Shape;
  15. [temp,X,Y]=show2D(temp);
  16. % %--------Show unaligned shape
  17. % plot(X,Y,'r*');
  18. % title('unaligned hands');
  19. %------------------Compute the shape metric---------------------------
  20. %-------------------------计算each Shape Size-------------------------
  21. T=temp*temp'; % Diag的对角元素为∑(x^2+y^2)
  22. V=diag(T); % compute 对角线
  23. size=sqrt(V); % Size 为40×1矩阵
  24. %------------------------将Size归一化--------------------------------
  25. %%% 根据形状大小的函数满足S(ax)=aS(x),每个坐标都除以对应Size的值
  26. for i= 1: 40
  27. preHand(i,:)=temp(i,:)/size(i); % preHand 为已经对准质点和大小
  28. end
  29. % -------------------------将各个形状以hand1为mean旋转------------------------
  30. x1=preHand( 1,:); % vector 1*40
  31. x1=reshape(x1, 56, 2);
  32. x2=preHand( 2,:);
  33. for i= 2: 40
  34. x3=preHand(i,:);
  35. x2=reshape(x3, 56, 2);
  36. XD=x1'*x2;
  37. [U,S,V]=svd(XD);
  38. I=x2*V*U';
  39. preHand(i,:)=reshape(I, 1, 112);
  40. end
  41. aligned=preHand;
  42. for i= 1: 40
  43. for j= 1: 56
  44. XX(i,j)=aligned(i,j); % the mean x-axis coordinate of every landmark
  45. YY(i,j)=aligned(i,j+ 56); % the mean y-axis coordinate of every landmark
  46. end
  47. end
  48. plot(XX,YY, 'ro')
  49. %-----------------compute the mean shape coordinates
  50. % every column of colm is the mean cooridnate of all the 40 hands'
  51. % coordinate respectively
  52. colm=mean(aligned); % mean(X) 求每一列元素的均值
  53. for i= 1: 56
  54. XX(i)=colm(i); % the mean x-axis coordinate of every landmark
  55. YY(i)=colm(i+ 56); % the mean y-axis coordinate of every landmark
  56. end
  57. % subplot(1,2,1);
  58. % figure;
  59. % plot(XX,YY,'g-',XX,YY,'rx'); % show the mean shape of 40 hands
  60. % title('the Mean Shape of Aligned');
  61. % title('b1=0');
  62. %---------------------------------------------------------------
  63. % tangent space projection
  64. absx=colm*colm';absx=absx*absx;
  65. for i= 1: 40
  66. xo=dot(colm,aligned(i,:)); % 矩阵点乘
  67. xt(i,:)=absx*aligned(i,:)/xo;
  68. end
  69. %---------------------------------------------------------------
  70. % PCA
  71. [signals,PC,V] = pca1(xt');
  72. % eAB=xt*xt'; % 应该减去均值球协方差矩阵
  73. % eAb=xt*xt'/39;
  74. % % eBA=xt'*xt;
  75. % [PC,V]=eig(eAB);
  76. % [PC1,V1]=eig(eAb);
  77. % V=diag(V);
  78. % V1=diag(V1);
  79. % sumV=40*mean(V);
  80. % compute the eigenvector of eBA
  81. % PC1=xt'*PC;
  82. % figure(2)
  83. % bar(V);
  84. % title('Shape eigenvalue');
  85. % xlabel('Eigenvalue');
  86. % ylabel('variance expansion factor(percent)');
  87. % now the shape model can be x=xmean+PC1*B,
  88. % where b {-3*sqrt(λ),3*sqrt(λ)}
  89. % Pb=PC(:,1)*3*sqrt(V1(1));
  90. Pb1=signals(:, 1)* 3*sqrt(V( 1));
  91. %
  92. % Xz=colm+Pb1';
  93. % Xz=colm-Pb1';
  94. Pb2=signals(:, 2)* 3*sqrt(V( 2));
  95. Xz=colm-Pb2';
  96. % Xz=colm-Pb2';
  97. % for i=1:56
  98. % Xp(i)=Xz(i); % the mean x-axis coordinate of every landmark
  99. % Yp(i)=Xz(i+56); % the mean y-axis coordinate of every landmark
  100. % end
  101. function edgedemo(action, varargin)
  102. %EDGEDEMO Edge detection demo.
  103. % This demo uses the EDGE function to apply different edge detection
  104. % methods to a variety of images. Use the pop-up menus to select an
  105. % image and an edge detection method. You can control the parameters
  106. % for the different methods by setting the values in the middle frame
  107. % at the bottom of the figure. (The set of parameters differs
  108. % depending on the method you choose.) Press the "Apply" button to
  109. % calculate the edge map using the specified method and parameters.
  110. %
  111. % For the Sobel, Prewitt, and Roberts methods, the EDGE function
  112. % finds edges by thresholding the gradient. For the Laplacian of
  113. % Gaussian method, EDGE thresholds the slope of the zero crossings
  114. % after filtering the image with a LoG filter. For the Canny method,
  115. % EDGE thresholds the gradient using the derivative of a Gaussian
  116. % filter.
  117. %
  118. % By default, the EDGE function automatically computes the threshold
  119. % to use. To specify a different threshold manually (in order to
  120. % detect more or fewer edges), click the radio button next to the
  121. % edit box in the middle frame and enter the value in the text field.
  122. % If you are using the Canny method, two thresholds are used: the
  123. % high threshold is the value you specify, and the low threshold is
  124. % 0.4 times the high threshold.
  125. %
  126. % For the Sobel and Prewitt methods, you can choose to detect
  127. % horizontal edges, vertical edges, or both.
  128. %
  129. % For the Laplacian of Gaussian and Canny methods, you can specify
  130. % sigma, the parameter that controls the spread of the Gaussian
  131. % function. The size of the filter is set automatically by EDGE,
  132. % based on the value of sigma.
  133. %
  134. % The Saturn and Lifting Body images are courtesy of NASA.
  135. %
  136. % See also EDGE.
  137. % Copyright 1993-2004 The MathWorks, Inc.
  138. % $Revision: 1.19.4.7 $ $Date: 2004/04/01 16:12:06 $
  139. % Function subroutines:
  140. %
  141. % InitializeEDGEDEMO - Initialization of controls, axes, and
  142. % Images.
  143. %
  144. % ComputeEdgeMap - Computes the Edge map of the original
  145. % image using edge.m
  146. %
  147. % SelectMethod - Selects Edge Detection method and enable/disable
  148. % the appropriate controls
  149. %
  150. % LoadNewImage - Loads the selected Image
  151. %
  152. % UpdateThreshCtrl - Grabs the threshold from the Edit box and
  153. % enables the Apply button
  154. %
  155. % UpdateDirectionality - Sets the directionality string based on the
  156. % popup menu.
  157. %
  158. % Radio - Sets values for Radio Buttons and enables/disables
  159. % the threshold edit box.
  160. %
  161. % UpdateLOGSize - Grabs the LOG filter size from edit box
  162. %
  163. % UpdateLOGSigma - Grabs LOG filter Sigma from edit box
  164. %
  165. % ActivateSPRControls - Turns on controls for Sobel, Prewitt, Roberts
  166. %
  167. % ActivateLOGControls - Turns on controls for LOG.
  168. if nargin< 1,
  169. action= 'InitializeEDGEDEMO';
  170. end;
  171. feval(action,varargin{:});
  172. return;
  173. %%%
  174. %%% Sub-function - InitializeEDGEDEMO
  175. %%%
  176. function InitializeEDGEDEMO()
  177. % If dctdemo is already running, bring it to the foreground.
  178. h = findobj(allchild( 0), 'tag', 'Edge Detection Demo');
  179. if ~isempty(h)
  180. figure(h( 1))
  181. return
  182. end
  183. screenD = get( 0, 'ScreenDepth');
  184. if screenD> 8
  185. grayres= 256;
  186. else
  187. grayres= 128;
  188. end
  189. EdgeDemoFig = figure( ...
  190. 'Name', 'Edge Detection Demo', ...
  191. 'NumberTitle', 'off', 'HandleVisibility', 'on', ...
  192. 'tag', 'Edge Detection Demo', ...
  193. 'Visible', 'off', 'Resize', 'off',...
  194. 'BusyAction', 'Queue', 'Interruptible', 'off', ...
  195. 'Color', [. 8 . 8 . 8], ...
  196. 'IntegerHandle', 'off', ...
  197. 'DoubleBuffer', 'on', ...
  198. 'Colormap', gray(grayres));
  199. figpos = get(EdgeDemoFig, 'position');
  200. % Adjust the size of the figure window
  201. figpos( 3: 4) = [ 560 420];
  202. horizDecorations = 10; % resize controls, etc.
  203. vertDecorations = 45; % title bar, etc.
  204. screenSize = get( 0, 'ScreenSize');
  205. if (screenSize( 3) <= 1)
  206. % No display connected (apparently)
  207. screenSize( 3: 4) = [ 100000 100000]; % don't use Inf because of vms
  208. end
  209. if (((figpos( 3) + horizDecorations) > screenSize( 3)) | ...
  210. ((figpos( 4) + vertDecorations) > screenSize( 4)))
  211. % Screen size is too small for this demo!
  212. delete(EdgeDemoFig);
  213. error([ 'Screen resolution is too low ', ...
  214. '(or text fonts are too big) to run this demo']);
  215. end
  216. dx = screenSize( 3) - figpos( 1) - figpos( 3) - horizDecorations;
  217. dy = screenSize( 4) - figpos( 2) - figpos( 4) - vertDecorations;
  218. if (dx < 0)
  219. figpos( 1) = max( 5,figpos( 1) + dx);
  220. end
  221. if (dy < 0)
  222. figpos( 2) = max( 5,figpos( 2) + dy);
  223. end
  224. set(EdgeDemoFig, 'position', figpos);
  225. rows = figpos( 4); cols = figpos( 3);
  226. hs = (cols- 512) / 3; % Horizantal Spacing
  227. bot = rows- 2*hs- 256; % Bottom of the images
  228. %====================================
  229. % Parameters for all buttons and menus
  230. ifs = hs/ 2; % Intraframe Spacing
  231. Std.Interruptible = 'off';
  232. Std.BusyAction = 'queue';
  233. %================================
  234. % Original Image Axes
  235. hdl.ImageAxes = axes(Std, ...
  236. 'Units', 'Pixels', ...
  237. 'Parent',EdgeDemoFig,...
  238. 'ydir', 'reverse', ...
  239. 'XLim', [. 5 256.5], ...
  240. 'YLim', [. 5 256.5],...
  241. 'CLim', [ 0 255], ...
  242. 'Position',[hs bot 256 256], ...
  243. 'XTick',[], 'YTick',[]);
  244. set(get(hdl.ImageAxes, 'title'), 'string', 'Original Image');
  245. %================================
  246. % Edge Map Axes
  247. hdl.EdgeAxes = axes(Std, ...
  248. 'Units', 'Pixels', ...
  249. 'Parent',EdgeDemoFig,...
  250. 'ydir', 'reverse', ...
  251. 'XLim', [. 5 256.5], ...
  252. 'YLim', [. 5 256.5],...
  253. 'CLim', [ 0 1], ...
  254. 'Position',[cols-hs- 256 bot 256 256], ...
  255. 'XTick',[], 'YTick',[]);
  256. set(get(hdl.EdgeAxes, 'title'), 'string', 'Edge Map');
  257. %================================
  258. % Original Image
  259. hdl.Image = image(Std, ...
  260. 'CData', [], ...
  261. 'CDataMapping', 'scaled', ...
  262. 'Parent',hdl.ImageAxes,...
  263. 'Xdata', [ 1 256],...
  264. 'Ydata', [ 1 256],...
  265. 'EraseMode', 'none');
  266. %================================
  267. % Edge Map Image
  268. hdl.Edge = image(Std, ...
  269. 'CData', [], ...
  270. 'CDataMapping', 'scaled', ...
  271. 'Parent',hdl.EdgeAxes,...
  272. 'Xdata', [ 1 256],...
  273. 'Ydata', [ 1 256],...
  274. 'EraseMode', 'none');
  275. % Background color for frames
  276. bgcolor = [ 0.45 0.45 0.45];
  277. fgcolor = [ 1 1 1]; % For text
  278. %================================
  279. % The Menu frame - image and method popups go here
  280. mfleft=hs;
  281. mfbot=hs;
  282. mfwid=( 3*cols/ 8)- 1.5*hs; % 2*cols/7
  283. mfht=bot- 2*hs;
  284. hdl.MenuFrame = uicontrol(Std, ...
  285. 'Parent', EdgeDemoFig, ...
  286. 'Style', 'frame', ...
  287. 'Units', 'pixels', ...
  288. 'Position', [mfleft mfbot mfwid mfht], ...
  289. 'BackgroundColor', bgcolor);
  290. %====================================
  291. % The LoadNewImage menu : ip-> Image Popup
  292. ipwid = mfwid- 2*ifs;
  293. ipht = 21; % (mfht-5*ifs)/3;
  294. ipleft = mfleft+ifs;
  295. ipbot = mfbot+ 1.7*ifs + 2*ipht;
  296. hdl.ImgPop=uicontrol(Std, ...
  297. 'Parent', EdgeDemoFig, ...
  298. 'Style', 'popupmenu', ...
  299. 'Units', 'pixels', ...
  300. 'Position',[ipleft ipbot ipwid ipht], ...
  301. 'Enable', 'on', ...
  302. 'String', 'Coins|Circuit|Vertigo|Lifting Body|Rice|Saturn|Eight Bit|Glass', ...
  303. 'Tag', 'ImagesPop',...
  304. 'Callback', 'edgedemo(' 'LoadNewImage' ')');
  305. % Text label for Image Menu Popup
  306. uicontrol( Std, ...
  307. 'Parent', EdgeDemoFig, ...
  308. 'Style', 'text', ...
  309. 'Units', 'pixels', ...
  310. 'Position',[ipleft ipbot+ipht ipwid 18], ...
  311. 'Horiz', 'left', ...
  312. 'Background',bgcolor, ...
  313. 'Foreground',fgcolor, ...
  314. 'String', 'Select an Image:');
  315. %====================================
  316. % The Method menu : mp-> Method Popup
  317. hdl.Method = 'Sobel';
  318. mpwid = ipwid;
  319. mpht = ipht;
  320. mpleft = ipleft;
  321. mpbot = mfbot+ 1.2*ifs;
  322. hdl.MethodPop=uicontrol(Std, ...
  323. 'Parent', EdgeDemoFig, ...
  324. 'Style', 'popupmenu', ...
  325. 'Units', 'pixels', ...
  326. 'Position',[mpleft mpbot mpwid mpht], ...
  327. 'Enable', 'on', ...
  328. 'String', 'Sobel|Prewitt|Roberts|Laplacian of Gaussian|Canny', ...
  329. 'Tag', 'MethodPop',...
  330. 'Callback', 'edgedemo(' 'SelectMethod' ')');
  331. % Text label for Method Popup
  332. uicontrol( Std, ...
  333. 'Parent', EdgeDemoFig, ...
  334. 'Style', 'text', ...
  335. 'Units', 'pixels', ...
  336. 'Position',[mpleft mpbot+mpht mpwid 18], ...
  337. 'Horiz', 'left', ...
  338. 'Background',bgcolor, ...
  339. 'Foreground',fgcolor, ...
  340. 'String', 'Edge Detection Method:');
  341. %================================
  342. % The Parameter frame - method specific parameters go here
  343. pfleft =( 3*cols/ 8)+ 0.5*hs; % 2*cols/7
  344. pfbot = 1.5*hs;
  345. pfwid =( 3*cols/ 8)-hs; % 3*cols/7
  346. pfht = bot- 2.5*hs;
  347. hdl.ParamFrame = uicontrol(Std, ...
  348. 'Parent', EdgeDemoFig, ...
  349. 'Style', 'frame', ...
  350. 'Units', 'pixels', ...
  351. 'Position', [ pfleft pfbot pfwid pfht ], ...
  352. 'BackgroundColor', bgcolor);
  353. %====================================
  354. % Controls for Sobel/Prewitt/Roberts edge detectors:
  355. % Text label for Threshold Controls
  356. labelleft = pfleft+ifs;
  357. labelwid = pfwid/ 2-hs;
  358. labelbot = pfbot+ 2*pfht/ 3;
  359. hdl.sprThLbl = uicontrol(Std,...
  360. 'Parent', EdgeDemoFig, ...
  361. 'Style', 'text', ...
  362. 'Units', 'pixels', ...
  363. 'Position',[labelleft labelbot labelwid 18], ...
  364. 'Horiz', 'left', ...
  365. 'String', 'Threshold:', ...
  366. 'BackgroundColor',bgcolor, ...
  367. 'ForegroundColor',fgcolor);
  368. hdl.Threshold = 0; % Initial value
  369. raleft = pfleft + pfwid/ 2 - hs/ 2;
  370. rabot = pfbot+ 2*pfht/ 3+hs/ 6;
  371. rawid = pfwid/ 2;
  372. raht = ipht;
  373. hdl.RadioAutomatic=uicontrol(Std, ...
  374. 'Parent', EdgeDemoFig, ...
  375. 'Style', 'radiobutton', ...
  376. 'Units', 'pixels', ...
  377. 'Position',[raleft rabot rawid raht], ...
  378. 'String', 'Automatic', ...
  379. 'value', 1, 'Userdata', 1, ...
  380. 'Callback', 'edgedemo(' 'Radio' ',' 'auto' ')');
  381. rmleft = pfleft + pfwid/ 2 - hs/ 2;
  382. rmbot = pfbot+pfht/ 3+hs/ 3;
  383. rmwid = hs* 1.5;
  384. rmht = ipht;
  385. hdl.RadioManual=uicontrol(Std, ...
  386. 'Parent', EdgeDemoFig, ...
  387. 'Style', 'radiobutton', ...
  388. 'Units', 'pixels', ...
  389. 'Position',[rmleft rmbot rmwid rmht], ...
  390. 'String', '', ...
  391. 'value', 0, 'Userdata', 0, ...
  392. 'Callback', 'edgedemo(' 'Radio' ',' 'manual' ')');
  393. thleft = rmleft+rmwid;
  394. thwid = rawid-rmwid;
  395. thbot = rmbot;
  396. thht = rmht;
  397. hdl.ThreshCtrl = uicontrol(Std, ...
  398. 'Parent', EdgeDemoFig, ...
  399. 'Enable', 'off', ...
  400. 'Style', 'edit', ...
  401. 'Units', 'pixels', ...
  402. 'Position',[thleft thbot thwid thht], ...
  403. 'Horiz', 'right', ...
  404. 'Background', 'white', ...
  405. 'Foreground', 'black', ...
  406. 'String', '0',...
  407. 'callback', 'edgedemo(' 'UpdateSprThresh' ')');
  408. % The Directionality Popup menu : dp-> Direction Popup
  409. dpwid = pfwid/ 2;
  410. dpht = ipht;
  411. dpleft = pfleft + pfwid/ 2 - hs/ 2;
  412. dpbot = pfbot+. 4*hs;
  413. hdl.sprDirPop=uicontrol(Std, ...
  414. 'Parent', EdgeDemoFig, ...
  415. 'Style', 'popupmenu', ...
  416. 'Units', 'pixels', ...
  417. 'Position',[dpleft dpbot dpwid dpht], ...
  418. 'Enable', 'on', ...
  419. 'String', 'Both|Horizontal|Vertical', ...
  420. 'Tag', 'DirectionPop',...
  421. 'Callback', 'edgedemo(' 'UpdateDirectionality' ')');
  422. % Text label for Directionality Popup
  423. labelleft = pfleft+ifs;
  424. labelwid = pfwid/ 2-hs; %5*hs/4
  425. labelbot = dpbot;
  426. hdl.sprDirLbl = uicontrol( Std, ...
  427. 'Parent', EdgeDemoFig, ...
  428. 'Style', 'text', ...
  429. 'Units', 'pixels', ...
  430. 'Position',[labelleft labelbot labelwid 18], ...
  431. 'Horiz', 'left', ...
  432. 'Background',bgcolor, ...
  433. 'Foreground',fgcolor, ...
  434. 'String', 'Direction:');
  435. hdl.Directionality = 'both';
  436. hdl.logSigmaCtrl=uicontrol(Std, ...
  437. 'Parent', EdgeDemoFig, ...
  438. 'Style', 'edit', ...
  439. 'Units', 'pixels', ...
  440. 'Position',[dpleft dpbot dpwid dpht], ...
  441. 'Horiz', 'right', ...
  442. 'Background', 'white', ...
  443. 'Foreground', 'black', ...
  444. 'String', '2', ...
  445. 'Tag', 'DirectionPop',...
  446. 'Visible', 'off', ...
  447. 'Callback', 'edgedemo(' 'UpdateLOGSigma' ')');
  448. % Text label for Sigma edit box
  449. hdl.logSigmaLbl = uicontrol( Std, ...
  450. 'Parent', EdgeDemoFig, ...
  451. 'Style', 'text', ...
  452. 'Units', 'pixels', ...
  453. 'Position',[labelleft labelbot labelwid 18], ...
  454. 'Horiz', 'left', ...
  455. 'Background',bgcolor, ...
  456. 'Foreground',fgcolor, ...
  457. 'Visible', 'off', ...
  458. 'String', 'Sigma:');
  459. hdl.LogSigma = 2;
  460. %====================================
  461. % Status bar
  462. colr = get(EdgeDemoFig, 'Color');
  463. hdl.Status = uicontrol( Std, ...
  464. 'Parent', EdgeDemoFig, ...
  465. 'Style', 'text', ...
  466. 'Units', 'pixels', ...
  467. 'Background', colr, ...
  468. 'Foreground', [. 8 0 0], ...
  469. 'Position',[pfleft 2 pfwid 18], ...
  470. 'Horiz', 'center', ...
  471. 'Tag', 'Status', ...
  472. 'String', 'Initializing Edge Detection Demo...');
  473. %================================
  474. % The Button frame - Apply, Info, and Close buttons go here
  475. bfleft = ( 3*cols/ 4)+. 5*hs; % 5*cols/7
  476. bfbot = hs;
  477. bfwid = (cols/ 4)- 1.5*hs; % 2*cols/7
  478. bfht = bot- 2*hs;
  479. hdl.ButtonFrame = uicontrol(Std, ...
  480. 'Parent', EdgeDemoFig, ...
  481. 'Style', 'frame', ...
  482. 'Units', 'pixels', ...
  483. 'Position', [ bfleft bfbot bfwid bfht ], ...
  484. 'BackgroundColor', bgcolor);
  485. %====================================
  486. % The APPLY button
  487. btnwid = bfwid - 2*ifs;
  488. btnht = (bfht- 4*ifs)/ 3; % 21
  489. btnleft = bfleft + ifs;
  490. btnbot = bfbot + bfht - ifs - btnht;
  491. hdl.Apply=uicontrol(Std, ...
  492. 'Parent', EdgeDemoFig, ...
  493. 'Style', 'pushbutton', ...
  494. 'Units', 'pixels', ...
  495. 'Position',[btnleft btnbot btnwid btnht], ...
  496. 'Enable', 'off', ...
  497. 'String', 'Apply', ...
  498. 'Callback', 'edgedemo(' 'ComputeEdgeMap' ')');
  499. %====================================
  500. % The INFO button
  501. btnbot = bfbot + bfht - 2*ifs - 2*btnht;
  502. hdl.Help=uicontrol(Std, ...
  503. 'Parent', EdgeDemoFig, ...
  504. 'Style', 'pushbutton', ...
  505. 'Units', 'pixels', ...
  506. 'Position',[btnleft btnbot btnwid btnht], ...
  507. 'Enable', 'off', ...
  508. 'String', 'Info', ...
  509. 'Callback', 'helpwin edgedemo');
  510. %====================================
  511. % The CLOSE button
  512. btnbot = bfbot + ifs;
  513. hdl.Close=uicontrol(Std, ...
  514. 'Parent', EdgeDemoFig, ...
  515. 'Style', 'pushbutton', ...
  516. 'Units', 'pixels', ...
  517. 'Position',[btnleft btnbot btnwid btnht], ...
  518. 'Enable', 'off', ...
  519. 'String', 'Close', ...
  520. 'Callback', 'close(gcbf)');
  521. set(EdgeDemoFig, 'Userdata', hdl, 'Visible', 'on');
  522. drawnow
  523. LoadNewImage(EdgeDemoFig);
  524. drawnow
  525. set(EdgeDemoFig, 'HandleVisibility', 'Callback');
  526. set([hdl.Apply hdl.Help hdl.Close] , 'Enable', 'on');
  527. return
  528. %%%
  529. %%% Sub-Function - ComputeEdgeMap
  530. %%%
  531. function ComputeEdgeMap(DemoFig)
  532. if nargin< 1
  533. callb = 1; % We're in a callback
  534. DemoFig = gcbf;
  535. else
  536. callb = 0; % We're in the initialization
  537. end

三、运行结果




四、备注

完整代码或者仿真咨询添加QQ1575304183


转载:https://blog.csdn.net/weixin_50197058/article/details/117089878
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场