Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
classdef CellCounter < handle
properties
widget_MouseFigure
widget_ManualCellCounter
widget_PiaSelector
widget_ImageBrowser
widget_FolderBrowser
fig
currentFileName
distances
end
methods
function obj = CellCounter()
addpath(genpath('./submodules/'));
obj.fig = figure('Position', [0,0, 400, 800]);
cellCounterPanel = uipanel('Parent', obj.fig,...
'Position',[0 .1 1 .1]);
piaPanel = uipanel('Parent', obj.fig,...
'Position',[0 .2 1 .1]);
imagePanel = uipanel('Parent', obj.fig,...
'Position',[0 .3 1 .45]);
folderPanel = uipanel('Parent', obj.fig,...
'Position',[0 .75 1 .25]);
obj.widget_MouseFigure = MouseFigure();
imageAxes = obj.widget_MouseFigure.handle_axes;
set(imageAxes, 'nextPlot', 'add');
obj.widget_ImageBrowser = WidgetImageBrowser('Parent', imagePanel, 'Axes', imageAxes);
obj.widget_PiaSelector = WidgetPiaSelector('Parent', piaPanel, 'Axes', imageAxes);
obj.widget_ManualCellCounter = WidgetManualCellCounter('Parent', cellCounterPanel, 'Axes', imageAxes);
obj.widget_FolderBrowser = WidgetFolderBrowser('parent', folderPanel);
addlistener(obj.widget_FolderBrowser, 'event_newFile', @obj.on_newFile);
addlistener(obj.widget_MouseFigure, 'event_clickUp', @obj.on_event_clickUp);
addlistener(obj.widget_MouseFigure, 'event_pressDel', @obj.on_pressDel);
uicontrol('Style', 'pushbutton',...
'Parent', obj.fig,...
'String', 'Export',...
'Units', 'normalized',...
'Position', [0,0,1,.1],...
'Callback', @obj.on_export);
end
function obj = on_newFile(obj, ~, event)
obj.currentFileName = event.userdata;
obj.widget_ImageBrowser.read(event.userdata);
obj.widget_ManualCellCounter.reset();
end
function obj = on_event_clickUp(obj, ~, event) %Event forwarding
if ~obj.widget_PiaSelector.isCurrentlySelecting
obj.widget_ManualCellCounter.on_event_clickUp(obj, event);
end
end
function obj = on_pressDel(obj, ~, event) %Event forwarding
obj.widget_ManualCellCounter.on_pressDel(obj, event);
end
function obj = on_export(obj, ~, ~)
obj.calculateDistances();
exportMat = [obj.widget_ManualCellCounter.countIndices, obj.widget_ManualCellCounter.locations, obj.distances];
[pathstr, name, ~] = fileparts(obj.currentFileName);
exportFileName = [pathstr, filesep, name, '_counts.csv'];
fid = fopen(exportFileName,'w');
fprintf(fid, 'counter, x, y, distance from pia [px]\n');
fclose(fid);
dlmwrite (exportFileName, exportMat, '-append');
msgbox(['Wrote: ', exportFileName]);
end
function obj = calculateDistances(obj)
locations = obj.widget_ManualCellCounter.locations;
piaPos = obj.widget_PiaSelector.piaPos';
obj.distances = nan(size(locations,1),1);
for i = 1:size(locations,1)
minDist = Inf;
for j = 1:size(piaPos,1)
dist = pdist([locations(i,:) ; piaPos(j,:)]);
if dist < minDist
minDist = dist;
end
end
obj.distances(i) = minDist;
end
end
function delete(~)
if exist('obj', 'var')
if exist(obj.fig, 'figure')
close(obj.fig);
end
delete(obj.widget_MouseFigure);
delete(obj.widget_ManualCellCounter);
delete(obj.widget_PiaSelector);
delete(obj.widget_ImageBrowser);
delete(obj.widget_FolderBrowser);
end
end
end
end