当前位置:   article > 正文

[GUI] 使用MATLAB从图片中提取曲线数据_matlab从图片中的曲线读取数据

matlab从图片中的曲线读取数据

 用MATLAB 2017b GUI写的一款小工具。

无论是课堂、会议上随手拍的照片,还是阅读文献的截图,很快可以提取到曲线的原始数据点作为学习研究的参考。


主要思路是:

1)预处理:裁剪选区、透视变换(交互式点击四个角点)

      % 得到以坐标轴为边界的矩形图像

2)坐标变换:输入X、Y轴起始坐标,选择坐标类型(可选择线性坐标系或者对数坐标系);

     % 将像素坐标转换为图片坐标

3)点击目标曲线上任一点自动识别颜色并分割,灰度图像直接阈值分割;

     % 除目标曲线外全部清空

4)输入希望得到的数据点数,自动等间距捕捉曲线上的点;

     % 等间距扫描取相应点数

5)导出所捕获点的EXCEL数据表。

     % 所有数据点存储在EXCEL中

涉及到一些线性代数和数字图像的知识,基本都是经典的图像算法,为了交互友好自己添加了一些 “算子” 做成了Slider。

 

直接上例子:

(1)随手画的一张,测试透视变换、图像分割、去噪效果。

(2)测试目标颜色过滤效果。

(3)复杂曲线数据点生成测试。

(4)复杂曲线颜色过滤测试

 

处理结果比对:

(1)

 

(2)

 

 点击选择蓝色曲线所得结果。

(3)

 

 

(4)

 

 

 以下是Matlab GUI代码。

  1. classdef Graph2Data < matlab.apps.AppBase
  2. % Properties that correspond to app components
  3. properties (Access = public)
  4. Graph2DataUIFigure matlab.ui.Figure
  5. TabGroup matlab.ui.container.TabGroup
  6. Tab matlab.ui.container.Tab
  7. CoordinateSystemPanel matlab.ui.container.Panel
  8. X_StartEditFieldLabel matlab.ui.control.Label
  9. X_StartEditField matlab.ui.control.NumericEditField
  10. X_EndEditFieldLabel matlab.ui.control.Label
  11. X_EndEditField matlab.ui.control.NumericEditField
  12. Y_EndEditFieldLabel matlab.ui.control.Label
  13. Y_EndEditField matlab.ui.control.NumericEditField
  14. Y_StartEditFieldLabel matlab.ui.control.Label
  15. Y_StartEditField matlab.ui.control.NumericEditField
  16. XscaleTypeButtonGroup matlab.ui.container.ButtonGroup
  17. LinearButton matlab.ui.control.RadioButton
  18. LogarithmicButton matlab.ui.control.RadioButton
  19. YscaleTypeButtonGroup matlab.ui.container.ButtonGroup
  20. LinearButton_2 matlab.ui.control.RadioButton
  21. LogarithmicButton_2 matlab.ui.control.RadioButton
  22. ClearAllButton matlab.ui.control.Button
  23. PrepareImagePanel matlab.ui.container.Panel
  24. CropButton matlab.ui.control.Button
  25. LoadButton matlab.ui.control.Button
  26. PerspectiveButton matlab.ui.control.Button
  27. Tab2 matlab.ui.container.Tab
  28. UndoButton matlab.ui.control.Button
  29. ColorSegmentationPanel matlab.ui.container.Panel
  30. TargetButton matlab.ui.control.Button
  31. H_FactorSliderLabel matlab.ui.control.Label
  32. H_FactorSlider matlab.ui.control.Slider
  33. S_FactorSliderLabel matlab.ui.control.Label
  34. S_FactorSlider matlab.ui.control.Slider
  35. V_FactorSliderLabel matlab.ui.control.Label
  36. V_FactorSlider matlab.ui.control.Slider
  37. GraySegmentationPanel matlab.ui.container.Panel
  38. ThresholdingButton matlab.ui.control.Button
  39. FactorSliderLabel matlab.ui.control.Label
  40. FactorSlider matlab.ui.control.Slider
  41. CleanButton matlab.ui.control.Button
  42. RefreshButton matlab.ui.control.Button
  43. Tab3 matlab.ui.container.Tab
  44. GetDataPanel matlab.ui.container.Panel
  45. SaveAsButton matlab.ui.control.Button
  46. PointNumberEditFieldLabel matlab.ui.control.Label
  47. PointNumberEditField matlab.ui.control.NumericEditField
  48. PlotButton matlab.ui.control.Button
  49. PleaseenteranINTEGERLabel matlab.ui.control.Label
  50. UIAxes matlab.ui.control.UIAxes
  51. Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel matlab.ui.control.Label
  52. end
  53. properties (Access = public)
  54. Image % Description
  55. Image_hsv
  56. Image_target
  57. Image_target_hsv
  58. row
  59. col
  60. x_target % Description
  61. y_target
  62. xOriginal
  63. yOriginal
  64. xFinal
  65. yFinal
  66. data
  67. end
  68. methods (Access = private)
  69. % Button pushed function: CleanButton
  70. function CleanButtonPushed(app, event)
  71. imshow(app.Image_target);
  72. mask = roipoly(app.Image_target);
  73. close;
  74. [r_mask c_mask] = find(mask==1);
  75. app.Image_target(r_mask,c_mask,1)=255;
  76. app.Image_target(r_mask,c_mask,2)=255;
  77. app.Image_target(r_mask,c_mask,3)=255;
  78. imshow(app.Image_target,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  79. end
  80. % Button pushed function: ClearAllButton
  81. function ClearAllButtonPushed(app, event)
  82. app.Image = []; % Clear Image
  83. imshow(app.Image,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  84. end
  85. % Button pushed function: CropButton
  86. function CropButtonPushed(app, event)
  87. app.Image = imcrop(app.Image);
  88. close;
  89. imshow(app.Image,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  90. end
  91. % Value changed function: FactorSlider
  92. function FactorSliderValueChanged(app, event)
  93. value = app.FactorSlider.Value;
  94. threshold = graythresh(app.Image)+app.FactorSlider.Value;
  95. app.Image_target = im2bw(app.Image,threshold);
  96. imshow(app.Image_target,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  97. end
  98. % Value changed function: H_FactorSlider
  99. function H_FactorSliderValueChanged(app, event)
  100. value = app.H_FactorSlider.Value;
  101. app.Image_hsv = rgb2hsv(app.Image);
  102. app.Image_target = 255*ones(size(app.Image));
  103. app.Image_target_hsv = rgb2hsv(app.Image_target);
  104. H = app.Image_hsv(:,:,1);
  105. S = app.Image_hsv(:,:,2);
  106. V = app.Image_hsv(:,:,3);
  107. [app.row, app.col] = ind2sub(size(app.Image_hsv),find(app.Image_hsv(:,:,1)>H(app.x_target,app.y_target)-app.H_FactorSlider.Value & app.Image_hsv(:,:,1)< H(app.x_target,app.y_target)+app.H_FactorSlider.Value & app.Image_hsv(:,:,2)>S(app.x_target,app.y_target)-app.S_FactorSlider.Value & app.Image_hsv(:,:,3)>V(app.x_target,app.y_target)-app.V_FactorSlider.Value));
  108. for i = 1 : length(app.row)
  109. app.Image_target_hsv(app.row(i),app.col(i),:) = app.Image_hsv(app.row(i),app.col(i),:);
  110. end
  111. app.Image_target = hsv2rgb(app.Image_target_hsv);
  112. imshow(app.Image_target,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  113. end
  114. % Button pushed function: LoadButton
  115. function LoadButtonPushed(app, event)
  116. [file,path] = uigetfile('*.jpg;*.jpeg;*.png');
  117. app.Image = imread(fullfile(path,file));
  118. imshow(app.Image,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  119. end
  120. % Button pushed function: PerspectiveButton
  121. function PerspectiveButtonPushed(app, event)
  122. imshow(app.Image);
  123. %set(gcf,'outerposition',get(0,'screensize'));
  124. dot = ginput(4);
  125. weight = round(sqrt((dot(1,1)-dot(2,1))^2+(dot(1,2)-dot(2,2))^2));
  126. height = round(sqrt((dot(1,1)-dot(3,1))^2+(dot(1,2)-dot(3,2))^2));
  127. X=[dot(1,2) dot(1,2)+weight dot(1,2) dot(1,2)+weight];
  128. Y=[dot(1,1) dot(1,1) dot(1,1)+height dot(1,1)+height];
  129. base = [X(1) Y(1);X(2) Y(2);X(3) Y(3);X(4) Y(4)];
  130. tform = cp2tform(dot,base,'projective');
  131. app.Image = imtransform(app.Image,tform,'XData',[X(1) X(2)],'YData',[Y(1) Y(4)]);
  132. close;
  133. imshow(app.Image,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  134. end
  135. % Button pushed function: PlotButton
  136. function PlotButtonPushed(app, event)
  137. % app.X_StartEditField.Value
  138. % app.X_EndEditField.Value
  139. % app.Y_StartEditField.Value
  140. % app.Y_EndEditField.Value
  141. % app.PointNumberEditField.Value
  142. weight = size(app.Image,2);
  143. height = size(app.Image,1);
  144. % number = round(app.PointNumberSlider.Value);
  145. interval = floor(weight/app.PointNumberEditField.Value);
  146. app.xOriginal = [];
  147. app.yOriginal = [];
  148. if interval == 0
  149. for i = 1:1:weight
  150. colum = app.Image(:,i);
  151. index = sort(find(colum == 0));
  152. if isempty(index) == 0
  153. app.xOriginal = [app.xOriginal i];
  154. app.yOriginal = [app.yOriginal index(1)+floor(length(index)/2)];
  155. end
  156. end
  157. else
  158. for i = 1:interval:weight
  159. colum = app.Image(:,i);
  160. index = sort(find(colum == 0));
  161. if isempty(index) == 0
  162. app.xOriginal = [app.xOriginal i];
  163. app.yOriginal = [app.yOriginal index(1)+floor(length(index)/2)];
  164. end
  165. end
  166. end
  167. app.yOriginal = height-app.yOriginal;
  168. app.xFinal = (app.xOriginal./weight).*(app.X_EndEditField.Value-app.X_StartEditField.Value)+app.X_StartEditField.Value;
  169. app.yFinal = (app.yOriginal./height).*(app.Y_EndEditField.Value-app.Y_StartEditField.Value)+app.Y_StartEditField.Value;
  170. plot(app.xFinal,app.yFinal,'.');
  171. end
  172. % Value changed function: PointNumberEditField
  173. function PointNumberEditFieldValueChanged(app, event)
  174. value = app.PointNumberEditField.Value;
  175. end
  176. % Button pushed function: RefreshButton
  177. function RefreshButtonPushed(app, event)
  178. app.Image = app.Image_target;
  179. end
  180. % Value changed function: S_FactorSlider
  181. function S_FactorSliderValueChanged(app, event)
  182. value = app.S_FactorSlider.Value;
  183. app.Image_hsv = rgb2hsv(app.Image);
  184. app.Image_target = 255*ones(size(app.Image));
  185. app.Image_target_hsv = rgb2hsv(app.Image_target);
  186. H = app.Image_hsv(:,:,1);
  187. S = app.Image_hsv(:,:,2);
  188. V = app.Image_hsv(:,:,3);
  189. [app.row, app.col] = ind2sub(size(app.Image_hsv),find(app.Image_hsv(:,:,1)>H(app.x_target,app.y_target)-app.H_FactorSlider.Value & app.Image_hsv(:,:,1)< H(app.x_target,app.y_target)+app.H_FactorSlider.Value & app.Image_hsv(:,:,2)>S(app.x_target,app.y_target)-app.S_FactorSlider.Value & app.Image_hsv(:,:,3)>V(app.x_target,app.y_target)-app.V_FactorSlider.Value));
  190. for i = 1 : length(app.row)
  191. app.Image_target_hsv(app.row(i),app.col(i),:) = app.Image_hsv(app.row(i),app.col(i),:);
  192. end
  193. app.Image_target = hsv2rgb(app.Image_target_hsv);
  194. imshow(app.Image_target,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  195. end
  196. % Button pushed function: SaveAsButton
  197. function SaveAsButtonPushed(app, event)
  198. app.data = [app.xFinal' app.yFinal'];
  199. xlswrite('C:\Users\BAR\Desktop\data_sheet_001.xlsx',app.data);
  200. winopen('C:\Users\BAR\Desktop\data_sheet_001.xlsx');
  201. end
  202. % Button pushed function: TargetButton
  203. function TargetButtonPushed(app, event)
  204. app.Image_hsv = rgb2hsv(app.Image);
  205. app.Image_target = 255*ones(size(app.Image));
  206. app.Image_target_hsv = rgb2hsv(app.Image_target);
  207. H = app.Image_hsv(:,:,1);
  208. S = app.Image_hsv(:,:,2);
  209. V = app.Image_hsv(:,:,3);
  210. imshow(app.Image);
  211. [app.y_target app.x_target] = ginput(1);
  212. app.x_target = round(app.x_target);
  213. app.y_target = round(app.y_target);
  214. close;
  215. [app.row, app.col] = ind2sub(size(app.Image_hsv),find(app.Image_hsv(:,:,1)>H(app.x_target,app.y_target)-app.H_FactorSlider.Value & app.Image_hsv(:,:,1)< H(app.x_target,app.y_target)+app.H_FactorSlider.Value & app.Image_hsv(:,:,2)>S(app.x_target,app.y_target)-app.S_FactorSlider.Value & app.Image_hsv(:,:,3)>V(app.x_target,app.y_target)-app.V_FactorSlider.Value));
  216. for i = 1 : length(app.row)
  217. app.Image_target_hsv(app.row(i),app.col(i),:) = app.Image_hsv(app.row(i),app.col(i),:);
  218. end
  219. app.Image_target = hsv2rgb(app.Image_target_hsv);
  220. imshow(app.Image_target,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  221. end
  222. % Button pushed function: ThresholdingButton
  223. function ThresholdingButtonPushed(app, event)
  224. threshold = graythresh(app.Image);
  225. app.Image_target = im2bw(app.Image,threshold);
  226. imshow(app.Image_target,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  227. end
  228. % Button pushed function: UndoButton
  229. function UndoButtonPushed(app, event)
  230. imshow(app.Image,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  231. end
  232. % Value changed function: V_FactorSlider
  233. function V_FactorSliderValueChanged(app, event)
  234. value = app.V_FactorSlider.Value;
  235. app.Image_hsv = rgb2hsv(app.Image);
  236. app.Image_target = 255*ones(size(app.Image));
  237. app.Image_target_hsv = rgb2hsv(app.Image_target);
  238. H = app.Image_hsv(:,:,1);
  239. S = app.Image_hsv(:,:,2);
  240. V = app.Image_hsv(:,:,3);
  241. [app.row, app.col] = ind2sub(size(app.Image_hsv),find(app.Image_hsv(:,:,1)>H(app.x_target,app.y_target)-app.H_FactorSlider.Value & app.Image_hsv(:,:,1)< H(app.x_target,app.y_target)+app.H_FactorSlider.Value & app.Image_hsv(:,:,2)>S(app.x_target,app.y_target)-app.S_FactorSlider.Value & app.Image_hsv(:,:,3)>V(app.x_target,app.y_target)-app.V_FactorSlider.Value));
  242. for i = 1 : length(app.row)
  243. app.Image_target_hsv(app.row(i),app.col(i),:) = app.Image_hsv(app.row(i),app.col(i),:);
  244. end
  245. app.Image_target = hsv2rgb(app.Image_target_hsv);
  246. imshow(app.Image_target,'Parent',app.UIAxes,'InitialMagnification','fit','border','tight');
  247. end
  248. % Value changed function: X_EndEditField
  249. function X_EndEditFieldValueChanged(app, event)
  250. value = app.X_EndEditField.Value;
  251. end
  252. % Value changed function: X_StartEditField
  253. function X_StartEditFieldValueChanged(app, event)
  254. value = app.X_StartEditField.Value;
  255. end
  256. % Selection changed function: XscaleTypeButtonGroup
  257. function XscaleTypeButtonGroupSelectionChanged(app, event)
  258. selectedButton = app.XscaleTypeButtonGroup.SelectedObject;
  259. end
  260. % Value changed function: Y_EndEditField
  261. function Y_EndEditFieldValueChanged(app, event)
  262. value = app.Y_EndEditField.Value;
  263. end
  264. % Value changed function: Y_StartEditField
  265. function Y_StartEditFieldValueChanged(app, event)
  266. value = app.Y_StartEditField.Value;
  267. end
  268. % Selection changed function: YscaleTypeButtonGroup
  269. function YscaleTypeButtonGroupSelectionChanged(app, event)
  270. selectedButton = app.YscaleTypeButtonGroup.SelectedObject;
  271. end
  272. end
  273. % App initialization and construction
  274. methods (Access = private)
  275. % Create UIFigure and components
  276. function createComponents(app)
  277. % Create Graph2DataUIFigure
  278. app.Graph2DataUIFigure = uifigure;
  279. app.Graph2DataUIFigure.Color = [0.9412 0.9412 0.9412];
  280. app.Graph2DataUIFigure.Position = [300 50 960 750];
  281. app.Graph2DataUIFigure.Name = 'Graph2Data';
  282. % Create TabGroup
  283. app.TabGroup = uitabgroup(app.Graph2DataUIFigure);
  284. app.TabGroup.Position = [1 631 960 120];
  285. % Create Tab
  286. app.Tab = uitab(app.TabGroup);
  287. app.Tab.Title = 'Tab';
  288. app.Tab.BackgroundColor = [0.9412 0.9412 0.9412];
  289. % Create CoordinateSystemPanel
  290. app.CoordinateSystemPanel = uipanel(app.Tab);
  291. app.CoordinateSystemPanel.TitlePosition = 'centertop';
  292. app.CoordinateSystemPanel.Title = 'Coordinate System';
  293. app.CoordinateSystemPanel.BackgroundColor = [0.9412 0.9412 0.9412];
  294. app.CoordinateSystemPanel.FontName = 'Microsoft YaHei UI';
  295. app.CoordinateSystemPanel.Position = [261 0 560 96];
  296. % Create X_StartEditFieldLabel
  297. app.X_StartEditFieldLabel = uilabel(app.CoordinateSystemPanel);
  298. app.X_StartEditFieldLabel.VerticalAlignment = 'center';
  299. app.X_StartEditFieldLabel.FontName = 'Microsoft YaHei UI';
  300. app.X_StartEditFieldLabel.Position = [21 48 46 15];
  301. app.X_StartEditFieldLabel.Text = 'X_Start';
  302. % Create X_StartEditField
  303. app.X_StartEditField = uieditfield(app.CoordinateSystemPanel, 'numeric');
  304. app.X_StartEditField.ValueChangedFcn = createCallbackFcn(app, @X_StartEditFieldValueChanged, true);
  305. app.X_StartEditField.Position = [81 44 58 22];
  306. % Create X_EndEditFieldLabel
  307. app.X_EndEditFieldLabel = uilabel(app.CoordinateSystemPanel);
  308. app.X_EndEditFieldLabel.VerticalAlignment = 'center';
  309. app.X_EndEditFieldLabel.FontName = 'Microsoft YaHei UI';
  310. app.X_EndEditFieldLabel.Position = [21 18 40 15];
  311. app.X_EndEditFieldLabel.Text = 'X_End';
  312. % Create X_EndEditField
  313. app.X_EndEditField = uieditfield(app.CoordinateSystemPanel, 'numeric');
  314. app.X_EndEditField.ValueChangedFcn = createCallbackFcn(app, @X_EndEditFieldValueChanged, true);
  315. app.X_EndEditField.Position = [81 14 58 22];
  316. % Create Y_EndEditFieldLabel
  317. app.Y_EndEditFieldLabel = uilabel(app.CoordinateSystemPanel);
  318. app.Y_EndEditFieldLabel.VerticalAlignment = 'center';
  319. app.Y_EndEditFieldLabel.FontName = 'Microsoft YaHei UI';
  320. app.Y_EndEditFieldLabel.Position = [301 18 40 15];
  321. app.Y_EndEditFieldLabel.Text = 'Y_End';
  322. % Create Y_EndEditField
  323. app.Y_EndEditField = uieditfield(app.CoordinateSystemPanel, 'numeric');
  324. app.Y_EndEditField.ValueChangedFcn = createCallbackFcn(app, @Y_EndEditFieldValueChanged, true);
  325. app.Y_EndEditField.Position = [361 14 58 22];
  326. % Create Y_StartEditFieldLabel
  327. app.Y_StartEditFieldLabel = uilabel(app.CoordinateSystemPanel);
  328. app.Y_StartEditFieldLabel.VerticalAlignment = 'center';
  329. app.Y_StartEditFieldLabel.FontName = 'Microsoft YaHei UI';
  330. app.Y_StartEditFieldLabel.Position = [301 48 45 15];
  331. app.Y_StartEditFieldLabel.Text = 'Y_Start';
  332. % Create Y_StartEditField
  333. app.Y_StartEditField = uieditfield(app.CoordinateSystemPanel, 'numeric');
  334. app.Y_StartEditField.ValueChangedFcn = createCallbackFcn(app, @Y_StartEditFieldValueChanged, true);
  335. app.Y_StartEditField.Position = [361 44 58 22];
  336. % Create XscaleTypeButtonGroup
  337. app.XscaleTypeButtonGroup = uibuttongroup(app.CoordinateSystemPanel);
  338. app.XscaleTypeButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @XscaleTypeButtonGroupSelectionChanged, true);
  339. app.XscaleTypeButtonGroup.BorderType = 'none';
  340. app.XscaleTypeButtonGroup.Title = 'XscaleType';
  341. app.XscaleTypeButtonGroup.FontName = 'Microsoft YaHei UI';
  342. app.XscaleTypeButtonGroup.Position = [151 2 123 74];
  343. % Create LinearButton
  344. app.LinearButton = uiradiobutton(app.XscaleTypeButtonGroup);
  345. app.LinearButton.Text = 'Linear';
  346. app.LinearButton.Position = [1 34 57 15];
  347. app.LinearButton.Value = true;
  348. % Create LogarithmicButton
  349. app.LogarithmicButton = uiradiobutton(app.XscaleTypeButtonGroup);
  350. app.LogarithmicButton.Text = 'Logarithmic';
  351. app.LogarithmicButton.Position = [1 13 86 15];
  352. % Create YscaleTypeButtonGroup
  353. app.YscaleTypeButtonGroup = uibuttongroup(app.CoordinateSystemPanel);
  354. app.YscaleTypeButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @YscaleTypeButtonGroupSelectionChanged, true);
  355. app.YscaleTypeButtonGroup.BorderType = 'none';
  356. app.YscaleTypeButtonGroup.Title = 'YscaleType';
  357. app.YscaleTypeButtonGroup.FontName = 'Microsoft YaHei UI';
  358. app.YscaleTypeButtonGroup.Position = [431 2 123 74];
  359. % Create LinearButton_2
  360. app.LinearButton_2 = uiradiobutton(app.YscaleTypeButtonGroup);
  361. app.LinearButton_2.Text = 'Linear';
  362. app.LinearButton_2.Position = [1 34 57 15];
  363. app.LinearButton_2.Value = true;
  364. % Create LogarithmicButton_2
  365. app.LogarithmicButton_2 = uiradiobutton(app.YscaleTypeButtonGroup);
  366. app.LogarithmicButton_2.Text = 'Logarithmic';
  367. app.LogarithmicButton_2.Position = [1 13 86 15];
  368. % Create ClearAllButton
  369. app.ClearAllButton = uibutton(app.Tab, 'push');
  370. app.ClearAllButton.ButtonPushedFcn = createCallbackFcn(app, @ClearAllButtonPushed, true);
  371. app.ClearAllButton.BackgroundColor = [1 1 1];
  372. app.ClearAllButton.FontName = 'Microsoft YaHei UI';
  373. app.ClearAllButton.Position = [901 12 52.625 54];
  374. app.ClearAllButton.Text = 'ClearAll';
  375. % Create PrepareImagePanel
  376. app.PrepareImagePanel = uipanel(app.Tab);
  377. app.PrepareImagePanel.TitlePosition = 'centertop';
  378. app.PrepareImagePanel.Title = 'Prepare Image';
  379. app.PrepareImagePanel.BackgroundColor = [0.9412 0.9412 0.9412];
  380. app.PrepareImagePanel.FontName = 'Microsoft YaHei UI';
  381. app.PrepareImagePanel.Position = [1 0 261 96];
  382. % Create CropButton
  383. app.CropButton = uibutton(app.PrepareImagePanel, 'push');
  384. app.CropButton.ButtonPushedFcn = createCallbackFcn(app, @CropButtonPushed, true);
  385. app.CropButton.BackgroundColor = [1 1 1];
  386. app.CropButton.FontName = 'Microsoft YaHei UI';
  387. app.CropButton.Position = [91 12 51 54];
  388. app.CropButton.Text = 'Crop';
  389. % Create LoadButton
  390. app.LoadButton = uibutton(app.PrepareImagePanel, 'push');
  391. app.LoadButton.ButtonPushedFcn = createCallbackFcn(app, @LoadButtonPushed, true);
  392. app.LoadButton.BackgroundColor = [1 1 1];
  393. app.LoadButton.FontName = 'Microsoft YaHei UI';
  394. app.LoadButton.Position = [21 12 50 54];
  395. app.LoadButton.Text = 'Load';
  396. % Create PerspectiveButton
  397. app.PerspectiveButton = uibutton(app.PrepareImagePanel, 'push');
  398. app.PerspectiveButton.ButtonPushedFcn = createCallbackFcn(app, @PerspectiveButtonPushed, true);
  399. app.PerspectiveButton.BackgroundColor = [1 1 1];
  400. app.PerspectiveButton.FontName = 'Microsoft YaHei UI';
  401. app.PerspectiveButton.Position = [157 12 88 54];
  402. app.PerspectiveButton.Text = 'Perspective';
  403. % Create Tab2
  404. app.Tab2 = uitab(app.TabGroup);
  405. app.Tab2.Title = 'Tab2';
  406. % Create UndoButton
  407. app.UndoButton = uibutton(app.Tab2, 'push');
  408. app.UndoButton.ButtonPushedFcn = createCallbackFcn(app, @UndoButtonPushed, true);
  409. app.UndoButton.BackgroundColor = [1 1 1];
  410. app.UndoButton.FontName = 'Microsoft YaHei UI';
  411. app.UndoButton.Position = [811 11 59.5 55];
  412. app.UndoButton.Text = 'Undo';
  413. % Create ColorSegmentationPanel
  414. app.ColorSegmentationPanel = uipanel(app.Tab2);
  415. app.ColorSegmentationPanel.TitlePosition = 'centertop';
  416. app.ColorSegmentationPanel.Title = 'Color Segmentation';
  417. app.ColorSegmentationPanel.FontName = 'Microsoft YaHei UI';
  418. app.ColorSegmentationPanel.Position = [341 0 341 96];
  419. % Create TargetButton
  420. app.TargetButton = uibutton(app.ColorSegmentationPanel, 'push');
  421. app.TargetButton.ButtonPushedFcn = createCallbackFcn(app, @TargetButtonPushed, true);
  422. app.TargetButton.BackgroundColor = [1 1 1];
  423. app.TargetButton.FontName = 'Microsoft YaHei UI';
  424. app.TargetButton.Position = [21 12 50 54];
  425. app.TargetButton.Text = 'Target';
  426. % Create H_FactorSliderLabel
  427. app.H_FactorSliderLabel = uilabel(app.ColorSegmentationPanel);
  428. app.H_FactorSliderLabel.HorizontalAlignment = 'right';
  429. app.H_FactorSliderLabel.FontName = 'Microsoft YaHei UI';
  430. app.H_FactorSliderLabel.Position = [95 51 56 15];
  431. app.H_FactorSliderLabel.Text = 'H_Factor';
  432. % Create H_FactorSlider
  433. app.H_FactorSlider = uislider(app.ColorSegmentationPanel);
  434. app.H_FactorSlider.Limits = [0 0.15];
  435. app.H_FactorSlider.MajorTicks = [];
  436. app.H_FactorSlider.MajorTickLabels = {};
  437. app.H_FactorSlider.ValueChangedFcn = createCallbackFcn(app, @H_FactorSliderValueChanged, true);
  438. app.H_FactorSlider.MinorTicks = [];
  439. app.H_FactorSlider.FontName = 'Microsoft YaHei UI';
  440. app.H_FactorSlider.Position = [165 57 157 3];
  441. app.H_FactorSlider.Value = 0.06;
  442. % Create S_FactorSliderLabel
  443. app.S_FactorSliderLabel = uilabel(app.ColorSegmentationPanel);
  444. app.S_FactorSliderLabel.HorizontalAlignment = 'right';
  445. app.S_FactorSliderLabel.FontName = 'Microsoft YaHei UI';
  446. app.S_FactorSliderLabel.Position = [95 31 54 15];
  447. app.S_FactorSliderLabel.Text = 'S_Factor';
  448. % Create S_FactorSlider
  449. app.S_FactorSlider = uislider(app.ColorSegmentationPanel);
  450. app.S_FactorSlider.Limits = [0.1 0.8];
  451. app.S_FactorSlider.MajorTicks = [];
  452. app.S_FactorSlider.MajorTickLabels = {};
  453. app.S_FactorSlider.ValueChangedFcn = createCallbackFcn(app, @S_FactorSliderValueChanged, true);
  454. app.S_FactorSlider.MinorTicks = [];
  455. app.S_FactorSlider.FontName = 'Microsoft YaHei UI';
  456. app.S_FactorSlider.Position = [165 37 155 3];
  457. app.S_FactorSlider.Value = 0.4;
  458. % Create V_FactorSliderLabel
  459. app.V_FactorSliderLabel = uilabel(app.ColorSegmentationPanel);
  460. app.V_FactorSliderLabel.HorizontalAlignment = 'right';
  461. app.V_FactorSliderLabel.FontName = 'Microsoft YaHei UI';
  462. app.V_FactorSliderLabel.Position = [95 11 55 15];
  463. app.V_FactorSliderLabel.Text = 'V_Factor';
  464. % Create V_FactorSlider
  465. app.V_FactorSlider = uislider(app.ColorSegmentationPanel);
  466. app.V_FactorSlider.Limits = [0 1];
  467. app.V_FactorSlider.MajorTicks = [];
  468. app.V_FactorSlider.MajorTickLabels = {};
  469. app.V_FactorSlider.ValueChangedFcn = createCallbackFcn(app, @V_FactorSliderValueChanged, true);
  470. app.V_FactorSlider.MinorTicks = [];
  471. app.V_FactorSlider.FontName = 'Microsoft YaHei UI';
  472. app.V_FactorSlider.Position = [165 17 156 3];
  473. app.V_FactorSlider.Value = 0.6;
  474. % Create GraySegmentationPanel
  475. app.GraySegmentationPanel = uipanel(app.Tab2);
  476. app.GraySegmentationPanel.TitlePosition = 'centertop';
  477. app.GraySegmentationPanel.Title = 'Gray Segmentation';
  478. app.GraySegmentationPanel.FontName = 'Microsoft YaHei UI';
  479. app.GraySegmentationPanel.Position = [1 0 341 96];
  480. % Create ThresholdingButton
  481. app.ThresholdingButton = uibutton(app.GraySegmentationPanel, 'push');
  482. app.ThresholdingButton.ButtonPushedFcn = createCallbackFcn(app, @ThresholdingButtonPushed, true);
  483. app.ThresholdingButton.BackgroundColor = [1 1 1];
  484. app.ThresholdingButton.FontName = 'Microsoft YaHei UI';
  485. app.ThresholdingButton.Position = [19.5 13 91 54];
  486. app.ThresholdingButton.Text = 'Thresholding';
  487. % Create FactorSliderLabel
  488. app.FactorSliderLabel = uilabel(app.GraySegmentationPanel);
  489. app.FactorSliderLabel.VerticalAlignment = 'center';
  490. app.FactorSliderLabel.Position = [130 31 39 15];
  491. app.FactorSliderLabel.Text = 'Factor';
  492. % Create FactorSlider
  493. app.FactorSlider = uislider(app.GraySegmentationPanel);
  494. app.FactorSlider.Limits = [-0.2 0.2];
  495. app.FactorSlider.MajorTickLabels = {'', '', '', '', '', ''};
  496. app.FactorSlider.ValueChangedFcn = createCallbackFcn(app, @FactorSliderValueChanged, true);
  497. app.FactorSlider.Position = [168 37 162 3];
  498. % Create CleanButton
  499. app.CleanButton = uibutton(app.Tab2, 'push');
  500. app.CleanButton.ButtonPushedFcn = createCallbackFcn(app, @CleanButtonPushed, true);
  501. app.CleanButton.BackgroundColor = [1 1 1];
  502. app.CleanButton.FontName = 'Microsoft YaHei UI';
  503. app.CleanButton.Position = [701 11 52 55];
  504. app.CleanButton.Text = 'Clean';
  505. % Create RefreshButton
  506. app.RefreshButton = uibutton(app.Tab2, 'push');
  507. app.RefreshButton.ButtonPushedFcn = createCallbackFcn(app, @RefreshButtonPushed, true);
  508. app.RefreshButton.BackgroundColor = [1 1 1];
  509. app.RefreshButton.FontName = 'Microsoft YaHei UI';
  510. app.RefreshButton.Position = [891 11 59.5 55];
  511. app.RefreshButton.Text = 'Refresh';
  512. % Create Tab3
  513. app.Tab3 = uitab(app.TabGroup);
  514. app.Tab3.Title = 'Tab3';
  515. % Create GetDataPanel
  516. app.GetDataPanel = uipanel(app.Tab3);
  517. app.GetDataPanel.TitlePosition = 'centertop';
  518. app.GetDataPanel.Title = 'Get Data';
  519. app.GetDataPanel.FontName = 'Microsoft YaHei UI';
  520. app.GetDataPanel.Position = [1 0 380 96];
  521. % Create SaveAsButton
  522. app.SaveAsButton = uibutton(app.GetDataPanel, 'push');
  523. app.SaveAsButton.ButtonPushedFcn = createCallbackFcn(app, @SaveAsButtonPushed, true);
  524. app.SaveAsButton.BackgroundColor = [1 1 1];
  525. app.SaveAsButton.FontName = 'Microsoft YaHei UI';
  526. app.SaveAsButton.Position = [301 12 60 54];
  527. app.SaveAsButton.Text = 'Save As';
  528. % Create PointNumberEditFieldLabel
  529. app.PointNumberEditFieldLabel = uilabel(app.GetDataPanel);
  530. app.PointNumberEditFieldLabel.VerticalAlignment = 'center';
  531. app.PointNumberEditFieldLabel.FontName = 'Microsoft YaHei UI';
  532. app.PointNumberEditFieldLabel.Position = [11 48 87 15];
  533. app.PointNumberEditFieldLabel.Text = 'Point Number';
  534. % Create PointNumberEditField
  535. app.PointNumberEditField = uieditfield(app.GetDataPanel, 'numeric');
  536. app.PointNumberEditField.ValueChangedFcn = createCallbackFcn(app, @PointNumberEditFieldValueChanged, true);
  537. app.PointNumberEditField.FontName = 'Microsoft YaHei UI';
  538. app.PointNumberEditField.Position = [111 44 90 22];
  539. % Create PlotButton
  540. app.PlotButton = uibutton(app.GetDataPanel, 'push');
  541. app.PlotButton.ButtonPushedFcn = createCallbackFcn(app, @PlotButtonPushed, true);
  542. app.PlotButton.BackgroundColor = [1 1 1];
  543. app.PlotButton.FontName = 'Microsoft YaHei UI';
  544. app.PlotButton.Position = [229 10 50 56];
  545. app.PlotButton.Text = 'Plot';
  546. % Create PleaseenteranINTEGERLabel
  547. app.PleaseenteranINTEGERLabel = uilabel(app.GetDataPanel);
  548. app.PleaseenteranINTEGERLabel.FontName = 'Microsoft YaHei UI';
  549. app.PleaseenteranINTEGERLabel.Position = [11 11 190 15];
  550. app.PleaseenteranINTEGERLabel.Text = 'Please enter an INTEGER. ';
  551. % Create UIAxes
  552. app.UIAxes = uiaxes(app.Graph2DataUIFigure);
  553. app.UIAxes.FontName = 'Consolas';
  554. app.UIAxes.MinorGridLineStyle = '-';
  555. app.UIAxes.GridColor = [0.8275 0.8275 0.8275];
  556. app.UIAxes.GridAlpha = 0.6;
  557. app.UIAxes.GridColorMode = 'manual';
  558. app.UIAxes.MinorGridAlpha = 0.2;
  559. app.UIAxes.Box = 'on';
  560. app.UIAxes.XColor = [0.8275 0.8275 0.8275];
  561. app.UIAxes.XColorMode = 'manual';
  562. app.UIAxes.YColor = [0.8275 0.8275 0.8275];
  563. app.UIAxes.YColorMode = 'manual';
  564. app.UIAxes.Color = [0.9412 0.9412 0.9412];
  565. app.UIAxes.XGrid = 'on';
  566. app.UIAxes.XMinorGrid = 'on';
  567. app.UIAxes.YGrid = 'on';
  568. app.UIAxes.YMinorGrid = 'on';
  569. app.UIAxes.Position = [2 2 960 630];
  570. % Create Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel
  571. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel = uilabel(app.Graph2DataUIFigure);
  572. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel.HorizontalAlignment = 'center';
  573. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel.VerticalAlignment = 'bottom';
  574. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel.FontName = 'Consolas';
  575. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel.FontSize = 11;
  576. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel.FontColor = [1 1 1];
  577. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel.Position = [511.5 736 449 15];
  578. app.Version1020200301CopyrightC2020Haotian_WAllrightsreservedLabel.Text = 'Version: 1.0 20200301; Copyright (C) 2020 Haotian_W All rights reserved.';
  579. end
  580. end
  581. methods (Access = public)
  582. % Construct app
  583. function app = Graph2Data
  584. % Create and configure components
  585. createComponents(app)
  586. % Register the app with App Designer
  587. registerApp(app, app.Graph2DataUIFigure)
  588. if nargout == 0
  589. clear app
  590. end
  591. end
  592. % Code that executes before app deletion
  593. function delete(app)
  594. % Delete UIFigure when app is deleted
  595. delete(app.Graph2DataUIFigure)
  596. end
  597. end
  598. end

(部分测试图片来自互联网,侵删)  

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/710101
推荐阅读
相关标签
  

闽ICP备14008679号