Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-kretschmerf committed Feb 26, 2018
1 parent 2d81965 commit 345e830
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions CellCounter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
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

0 comments on commit 345e830

Please sign in to comment.