Skip to content

Commit

Permalink
Working on training GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
sharsnik committed May 3, 2016
1 parent 831390a commit 728218f
Show file tree
Hide file tree
Showing 7 changed files with 648 additions and 219 deletions.
Binary file modified batch/trainingGui.fig
Binary file not shown.
259 changes: 249 additions & 10 deletions batch/trainingGui.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@

% Edit the above text to modify the response to help trainingGui

% Last Modified by GUIDE v2.5 29-Apr-2016 16:38:45
% Last Modified by GUIDE v2.5 03-May-2016 16:08:54

% Begin initialization code - DO NOT EDIT

global settings;


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
Expand All @@ -50,11 +54,26 @@ function trainingGui_OpeningFcn(hObject, eventdata, handles, varargin)
% 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 trainingGui (see VARARGIN)
global settings;

handles.output = hObject;
set(handles.figure1, 'units', 'normalized', 'position', [0.1 0.1 0.8 0.8])
guidata(hObject, handles);

handles.directory.String = pwd;

settings.axisFlag = 0;
settings.frameNumber = 1;
settings.loadFiles = [];
settings.loadDirectory = [];
settings.currentData = [];
settings.handles = handles;
settings.oldData = [];
settings.oldFrame = [];
settings.maxData = 10;

updateUI(handles);

% UIWAIT makes trainingGui wait for user response (see UIRESUME)
% uiwait(handles.figure1);

Expand Down Expand Up @@ -101,47 +120,136 @@ function try_const_Callback(hObject, eventdata, handles)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

dirname = fixDir(handles.directory.String);
images = dir([dirname,'*c1*.tif']);

if isempty(images) && ~isempty(dir([dirname,'/raw_im/*c1*.tif']))
dirname = [dirname, '/raw_im/'];
end

tryDifferentConstants(handles.directory.String, []);
tryDifferentConstants(dirname, []);





% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% --- Executes on button press in next.
function previous_Callback(hObject, eventdata, handles)
% hObject handle to next (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global settings;

settings.frameNumber = settings.frameNumber - 1;
settings.frameNumber = max(settings.frameNumber, 1);

settings.currentData = load([settings.loadDirectory,settings.loadFiles(settings.frameNumber).name]);

updateUI(handles);

% --- Executes on button press in pushbutton6.

% --- Executes on button press in previous.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% hObject handle to previous (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% --- Executes on button press in undo.
function undo_Callback(hObject, eventdata, handles)
% hObject handle to undo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global settings;

if numel(settings.oldData) > 0
settings.currentData = settings.oldData(1);
settings.frameNumber = settings.oldFrame(1);

if numel(settings.oldData) > 1
settings.oldData = settings.oldData(2:end);
settings.oldFrame = settings.oldFrame(2:end);
else
settings.oldData = [];
settings.oldFrame = [];
end

updateUI(handles);

try
data = settings.currentData;

save([settings.loadDirectory, settings.loadFiles(settings.frameNumber).name],'-STRUCT','data');
catch ME
warning(['Could not save undo changes: ', ME.message]);
end
else
errordlg(['Reached undo limit']);
end




% --- Executes on button press in toggle_segs.
function toggle_segs_Callback(hObject, eventdata, handles)
% hObject handle to toggle_segs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global settings;

settings.axisFlag = 1;
settings.frameNumber = 1;

%Make backup folder
try
backupFolder = [settings.loadDirectory(1:end-1), '_old/'];
if ~exist(backupFolder, 'dir')
mkdir(backupFolder);
end

copyfile(settings.loadDirectory, backupFolder)
catch ME
warning(['Could not back up files: ', ME.message]);
end

segTrainingDir = handles.directory.String;
settings.loadDirectory = [segTrainingDir,filesep,'xy1',filesep,'seg',filesep];
settings.loadFiles = dir([settings.loadDirectory,'*seg.mat']);
settings.currentData = load([settings.loadDirectory,settings.loadFiles(settings.frameNumber).name]);



updateUI(handles);


% --- Executes on button press in del_areas.
function del_areas_Callback(hObject, eventdata, handles)
% hObject handle to del_areas (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global settings;

if exist([settings.loadDirectory, 'CONST.mat'], 'file')
CONST = load([settings.loadDirectory, 'CONST.mat']);

for i = 1 : numel(settings.loadFiles)
data = load([settings.loadDirectory,settings.loadFiles(i).name]);



data = killRegions(data, CONST)

try
save([settings.loadDirectory, settings.loadFiles(i).name],'-STRUCT','data');
catch ME
warning(['Could not save changes: ', ME.message]);
end
end

disp('Bad regions removed');
else
warning(['Plese segment files first']);
end

% --- Executes on button press in train_segs.
function train_segs_Callback(hObject, eventdata, handles)
Expand Down Expand Up @@ -238,3 +346,134 @@ function image_folder_ClickedCallback(hObject, eventdata, handles)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.directory.String = uigetdir;


% --- Executes on button press in next.
function next_Callback(hObject, eventdata, handles)
% hObject handle to next (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global settings;

settings.frameNumber = settings.frameNumber + 1;
settings.frameNumber = min(settings.frameNumber, numel(settings.loadFiles));

settings.currentData = load([settings.loadDirectory,settings.loadFiles(settings.frameNumber).name]);

updateUI(handles);


function updateUI(handles)
global settings;

if settings.axisFlag > 0
FLAGS.im_flag = settings.axisFlag;
FLAGS.S_flag = 0;
FLAGS.t_flag = 0;

showTrainingData (settings.currentData, FLAGS, handles.viewport);

if numel(handles.viewport.Children) > 0
set(handles.viewport.Children(1),'ButtonDownFcn',@imageButtonDownFcn);
end
end

if settings.axisFlag == 1
handles.tooltip.String = ['Editing segments. Max frame: ', num2str(numel(settings.loadFiles))];
handles.frameNumber.Visible = 'on';
handles.frameNumber.String = num2str(settings.frameNumber);
elseif settings.axisFlag == 0
handles.tooltip.String = ['Editing regions. Max frame: ', num2str(numel(settings.loadFiles))];
handles.frameNumber.Visible = 'on';
handles.frameNumber.String = num2str(settings.frameNumber);
else
handles.tooltip.String = '';
handles.frameNumber.Visible = 'off';

if numel(handles.viewport.Children) > 0
set(handles.viewport.Children(1),'Visible', 'off');
end
end


% numChildren = numel(viewport.Children);
% for i = 1:numChildren
% viewport.Children(i).HitTest = 'off';
% end


function saveData()
global settings

try
data = settings.currentData;

save([settings.loadDirectory, settings.loadFiles(settings.frameNumber).name],'-STRUCT','data');
catch ME
warning(['Could not save changes: ', ME.message]);
end


function addUndo()
global settings

settings.oldData = [settings.currentData, settings.oldData];
if numel(settings.oldData) > settings.maxData
settings.oldData = settings.oldData(1:settings.maxData)
end

settings.oldFrame = [settings.frameNumber, settings.oldFrame];
if numel(settings.oldFrame) > settings.maxData
settings.oldFrame = settings.oldFrame(1:settings.maxData)
end


% --- Executes on mouse press over axes background.
function imageButtonDownFcn(hObject, eventdata, handles)
% hObject handle to viewport (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global settings;

if settings.axisFlag > 0
FLAGS.im_flag = settings.axisFlag;
FLAGS.S_flag = 0;
FLAGS.t_flag = 0;

addUndo();
[settings.currentData, list] = updateTrainingImage(settings.currentData, FLAGS, eventdata.IntersectionPoint(1:2));
saveData();

updateUI(settings.handles);
end



function frameNumber_Callback(hObject, eventdata, handles)
% hObject handle to frameNumber (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of frameNumber as text
% str2double(get(hObject,'String')) returns contents of frameNumber as a double
global settings;

settings.frameNumber = str2num(handles.frameNumber.String);
settings.frameNumber = max(1, min(settings.frameNumber, numel(settings.loadFiles)));

settings.currentData = load([settings.loadDirectory,settings.loadFiles(settings.frameNumber).name]);

updateUI(handles);


% --- Executes during object creation, after setting all properties.
function frameNumber_CreateFcn(hObject, eventdata, handles)
% hObject handle to frameNumber (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% 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
Binary file removed batch/trainingGui2.fig
Binary file not shown.
Loading

0 comments on commit 728218f

Please sign in to comment.