糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > 【Matlab学习手记】利用Matlab提取图片曲线数据

【Matlab学习手记】利用Matlab提取图片曲线数据

时间:2019-09-17 03:47:02

相关推荐

【Matlab学习手记】利用Matlab提取图片曲线数据

-6-25 新增 github 源码链接,所以,自行下载,enjoy

/AFei19911012/MatlabSamples/tree/master/AppDesigner/SimpleImageToData

目的:提取图片上的曲线数据点。比如,文献中的图表数据。

-4-24 更新,代码已修改为 AppDesigner 设计,增加了自动提取功能:/p/347520891

源代码

function varargout = DataExtract(varargin)% DATAEXTRACT MATLAB code for DataExtract.fig%DATAEXTRACT, by itself, creates a new DATAEXTRACT or raises the existing%singleton*.%%H = DATAEXTRACT returns the handle to a new DATAEXTRACT or the handle to%the existing singleton*.%%DATAEXTRACT('CALLBACK',hObject,eventData,handles,...) calls the local%function named CALLBACK in DATAEXTRACT.M with the given input arguments.%%DATAEXTRACT('Property','Value',...) creates a new DATAEXTRACT or raises the%existing singleton*. Starting from the left, property value pairs are%applied to the GUI before DataExtract_OpeningFcn gets called. An%unrecognized property name or invalid value makes property application%stop. All inputs are passed to DataExtract_OpeningFcn via varargin.%%*See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one%instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help DataExtract% Last Modified by GUIDE v2.5 30-Aug- 09:01:43% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @DataExtract_OpeningFcn, ...'gui_OutputFcn', @DataExtract_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before DataExtract is made visible.function DataExtract_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to DataExtract (see VARARGIN)% Choose default command line output for DataExtracthandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes DataExtract wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = DataExtract_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{1} = handles.output;function pushbutton1_Callback(hObject, eventdata, handles)axes(handles.axes1)cla resetaxis offset(handles.uitable1, 'data', []);set(handles.text5, 'string', 'Load a picture !!!');[FileName, PathName] = uigetfile({'*.bmp'}, 'Load a picture');if length(PathName) < 3msgbox('Failed to load a picture !!!');return;endFilePath = [PathName, FileName];Img = imread(FilePath);axes(handles.axes1);imshow(Img, 'Border', 'tight');set(handles.text5, 'string', 'Input the values in EditBoxs, press Enter to continue !!!');pause();set(handles.text5, 'string', 'Locate the start point !!!');currPt = ginput(1);x0 = currPt(1, 1);y0 = currPt(1, 2);line(x0, y0, 'marker', '.', 'color', 'r', 'markersize', 20);set(handles.text5, 'string', 'Locate the x-end point !!!');currPt = ginput(1);xend = currPt(1, 1);y = currPt(1, 2);line(xend, y, 'marker', '.', 'color', 'r', 'markersize', 20);line([x0, xend], [y0, y], 'color', 'r');set(handles.text5, 'string', 'Locate the y-end point !!!');currPt = ginput(1);x = currPt(1, 1);yend = currPt(1, 2);line(x, yend, 'marker', '.', 'color', 'r', 'markersize', 20);line([x0, x], [y0, yend], 'color', 'r');set(handles.text5, 'string', 'Now you can locate the point, press RightButton to locate the last point !!!');tableData = cell(0);con = 1;i = 1;xmin = str2double(get(handles.edit1, 'string'));xmax = str2double(get(handles.edit2, 'string'));ymin = str2double(get(handles.edit3, 'string'));ymax = str2double(get(handles.edit4, 'string'));scale1 = get(handles.radiobutton1, 'value');scale2 = get(handles.radiobutton3, 'value');while con == 1 [x, y, con] = ginput(1);line(x, y, 'marker', '.', 'color', 'r', 'markersize', 20);if scale1 == 1xx = (xmax - xmin)*(x - x0)/(xend - x0) + xmin;elsexx = 10^((log10(xmax) - log10(xmin))*(x - x0)/(xend - x0) + log10(xmin));endif scale2 == 1yy = (ymax - ymin)*(y - y0)/(yend - y0) + ymin;else%yy = 10^((log10(ymax) - log10(ymin))*(log10(y) - log10(y0))/(log10(yend) - log10(y0)) + log10(ymin));yy = 10^((log10(ymax) - log10(ymin))*(y - y0)/(yend - y0) + log10(ymin));endtableData{i, 1} = i;tableData{i, 2} = xx;tableData{i, 3} = yy;set(handles.uitable1, 'data', tableData);i = i + 1;endfunction pushbutton2_Callback(hObject, eventdata, handles)[FileName, PathName] = uiputfile('*.txt', 'save file name');tableData = get(handles.uitable1, 'data');tableData = cell2mat(tableData);if ~isempty(tableData)dlmwrite([PathName, FileName], tableData(:, 2:end), 'delimiter', '\t', 'precision', '%8.4f');endfunction pushbutton3_Callback(hObject, eventdata, handles)close(gcf);function edit1_Callback(hObject, eventdata, handles)function edit1_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit2_Callback(hObject, eventdata, handles)function edit2_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit3_Callback(hObject, eventdata, handles)function edit3_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit4_Callback(hObject, eventdata, handles)function edit4_CreateFcn(hObject, eventdata, handles)% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end

源代码链接

/download/u012366767/10593012

如果觉得《【Matlab学习手记】利用Matlab提取图片曲线数据》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。