Skip to content
Snippets Groups Projects
Commit bfd60019 authored by vand's avatar vand
Browse files

initial commit

parent 764c9841
No related branches found
No related tags found
No related merge requests found
**/.DS_Store
**/*.m~
File added
File added
File added
File added
File added
clear
close all
addpath functions
data_folder = '../data_folder';
annotate_gui(data_folder)
%annotate_gui(data_folder,'annotations',YXZ)
function annotate_gui(data_folder,varargin)
%ANNOTATE_TRACKING_GUI GUI for annotating foci in a set of B-scans.
% TODO descrube suggested workflow.
% ANNOTATE_GUI(DATA)
% ANNOTATE_GUI(DATA,Name,Value) sets one or more properties using
% name-value pair arguments. Keyboard shortcuts: arrows for
% changing B-scan, home and end for first and last, s for save.
% DATA_FOLDER, a folder containing tif images.
% Name-Value pairs:
% 'annotations', annotations previously saved from the GUI.
% Author: vand@dtu.dk, 2020
% PARSING INPUTS
if any(strcmpi(varargin,'ANNOTATIONS'))
YXZ = varargin{find(strcmpi(varargin,'ANNOTATIONS'))+1};
else
YXZ = [];
end
% SETTING UP
image_list = dir([data_folder,'/*.tif']);
Y_max = length(image_list);
readimage = @(y) imread([data_folder,'/',image_list(y).name]);
Y = 1; % starting with the first image
current_image = readimage(Y);
Z_max = size(current_image,1);
X_max = size(current_image,2);
% for drawing circles
N = 12; % number of points in the circle
t = 0:2*pi/N:2*pi*(1-1/N); % radial parameter
unit_circle = [sin(t); cos(t)]';
% SETTING UP THE FIGURES
fig_main = figure('Units', 'Normalized', 'Position', [0.0 0.5 1 0.5],...
'KeyPressFcn', @key_press, 'WindowButtonUpFcn', @button_up_add_point,...
'Name', 'Annotation window');
fig_3D = figure('Units', 'Normalized', 'Position', [0.3 0.0 0.4 0.3],...
'Name','3D visulization window');
R = 5; % initial radius
circle = R*unit_circle;
update_drawing, hold on, axis image ij, colormap gray
update_drawing % twice for case when YXZ given
update_surf
figure(fig_3D), hold on, axis vis3d, figure(fig_main)
%%%%%%%%%% CALLBACK FUNCTIONS %%%%%%%%%%
function key_press(~,object)
% keyboard commands
key = object.Key;
switch key
case 'rightarrow'
Y = min(Y+1,Y_max);
update_drawing
case 'leftarrow'
Y = max(Y-1,1);
update_drawing
case 'home'
Y = 1;
update_drawing
case 'end'
Y = Y_max;
update_drawing
% case 'd'
% if strcmp(object.Modifier,'shift') % only capital letters
% delete_point % TODO
% update_surf
% update_drawing
% end
case 's'
xlabel('Saving.')
drawnow
fid = fopen('annotations.txt','w');
fprintf(fid,'%d %d %d \n',round(YXZ)');
fclose(fid);
save('ANNOTIONS_YXZ.mat','YXZ')
disp('Ok, saved!')
xlabel('Saved.')
drawnow
end
end
%%%%%%%%%% HELPING FUNCTIONS %%%%%%%%%%
function update_drawing
figure(fig_main)
current_image = readimage(Y);
cla
imagesc(current_image)
if ~isempty(YXZ)
this_image = YXZ(:,1) == Y;
if ~isempty(this_image)
plot(YXZ(this_image,2)'+circle([1:end,1],1), ...
YXZ(this_image,3)'+circle([1:end,1],2),'r','LineWidth',2)
end
end
title(['Image ', num2str(Y)])
xlabel('')
drawnow
end
function update_surf
figure(fig_3D), cla
plot3(...
[0,1; 0,1; 0,1; 0,1; 0,0; 1,1; 0,0; 1,1; 0,0; 1,1; 0,0; 1,1]'*(X_max-1)+1,...
[0,0; 1,1; 0,0; 1,1; 0,1; 0,1; 0,1; 0,1; 0,0; 0,0; 1,1; 1,1]'*(Y_max-1)+1,...
[0,0; 0,0; 1,1; 1,1; 0,0; 0,0; 1,1; 1,1; 0,1; 0,1; 0,1; 0,1]'*(Z_max-1)+1,'k-');
if ~isempty(YXZ)
plot3(YXZ(:,2),YXZ(:,1),1+Z_max-YXZ(:,3),'ro')
end
drawnow
figure(fig_main)
end
function button_up_add_point(~,~)
cp = get(gca,'CurrentPoint');
YXZ(end+1,:) = [Y, cp(1,1:2)];
update_drawing
update_surf
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment