function varargout = extraction(varargin)
% EXTRACTION MATLAB code for extraction.fig
% EXTRACTION, by itself, creates a new EXTRACTION or raises the existing
% singleton*.
%
% H = EXTRACTION returns the handle to a new EXTRACTION or the handle to
% the existing singleton*.
%
% EXTRACTION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EXTRACTION.M with the given input arguments.
%
% EXTRACTION('Property','Value',...) creates a new EXTRACTION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before extraction_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to extraction_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 extraction
% Last Modified by GUIDE v2.5 19-Aug-2015 16:29:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @extraction_OpeningFcn, ...
'gui_OutputFcn', @extraction_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before extraction is made visible.
function extraction_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 extraction (see VARARGIN)
% Choose default command line output for extraction
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes extraction wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = extraction_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 structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global img;
global fname;
global num;
global file_num;
global file_path;
global img_path_list;
global img_maxnum;
global image_name;
file_num = 1;
num=0;
[filename,pathname]=uigetfile({'*.*';'*.bmp';'*.jpg';'*.tif';'*.jpg'},'选择图像');
file_path = pathname;% 图像文件夹路径
img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像
img_maxnum = length(img_path_list);%获取图像总数量
image_name = filename;
if isequal(filename,0)||isequal(pathname,0)
errordlg('您还没有选取图片!!','温馨提示');%如果没有输入,则创建错误对话框
return;
else
try
image=[pathname,filename];%合成路径+文件名
img=imread(image);%读取图像
%axes(handles.axes3);
figure(1);
imageHandle=imshow(img);
exif = imfinfo(image);
d = exif.DigitalCamera;
fname=[num2str(1/d.ExposureTime),'-',num2str(d.FNumber),'_'];
title([fname,filename]);
set(imageHandle,'ButtonDownFcn',@ImageClickCallback);
catch
end
end
%鼠标截取红绿灯部分
function ImageClickCallback(objectHandle,eventdata,handles)
global img;
global num;
global fname;
global image_name;
global path;
num=num+1;
%k=waitforbuttonpress;
%point= get(gca,'CurrentPoint') ; %mouse pressed
%rectregion = rbbox ;
axesHandle = get(objectHandle,'Parent');
%获取坐标轴axesHandles
point = get(axesHandle,'CurrentPoint');
point= point(1,1:2);% extract col/row min and maxs
point_x=point(1);
point_y=point(2);
length = 20;
width = 20;
img_cut=img(point_y-length:point_y+length,point_x-width:point_x+width,:);
figure(2);
imshow(img_cut);
imm_name = '';
[pppp,qqqq] = size(image_name);
for qq=1:qqqq
if(image_name(qq)=='.')
break;
end
imm_name = strcat(imm_name,image_name(qq));
end
name = [path,fname,num2str(num),'_',imm_name,'.png'];
imwrite(img_cut,name);
% --- Executes on button press in btn_g.
function btn_g_Callback(hObject, eventdata, handles)
% hObject handle to btn_g (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global path;
path ='E:\肖永杰\MATLAB\MATLAB\extraction\png版本0907\g\g下午2\';
% --- Executes on button press in btn_r.
function btn_r_Callback(hObject, eventdata, handles)
% hObject handle to btn_r (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global path;
path ='E:\肖永杰\MATLAB\MATLAB\extraction\png版本0907\r\r傍晚\';
% --- Executes on button press in btn_y.
function btn_y_Callback(hObject, eventdata, handles)
% hObject handle to btn_y (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global path;
path ='E:\肖永杰\MATLAB\MATLAB\extraction\png版本0907\y\y下午\';
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_num;
global img;
global file_path;
global img_path_list;
global fname;
file_num = file_num+1;
global num;
num = 0;
global img_maxnum;
global image_name;
if(file_num == img_maxnum)
errordlg('最后一张图片!!','温馨提示');%如果没有输入,则创建错误对话框
end
image_name = img_path_list(file_num).name;% 图像名
image = strcat(file_path,image_name);
img = imread(image);
figure(1);
imageHandle=imshow(img);
exif = imfinfo(image);
d = exif.DigitalCamera;
fname=[num2str(1/d.ExposureTime),'-',num2str(d.FNumber),'_'];
title([fname,image_name]);
set(imageHandle,'ButtonDownFcn',@ImageClickCallback);
fprintf('%d/%d \n',file_num,length(img_path_list));