-
Notifications
You must be signed in to change notification settings - Fork 1
/
aMap.m
executable file
·107 lines (94 loc) · 3.03 KB
/
aMap.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function [actMap1] = aMap(data,stat,endp,Fs,bg,cmap,filename)
%% aMap is the central function for creating conduction velocity maps
% [actMap1] = aMap(data,stat,endp,Fs,bg) calculates the activation map
% for a single action potential upstroke.
% INPUTS
% data = cmos data (voltage, calcium, etc.) from the micam ultima system.
%
% stat = start of analysis (in msec)
%
% endp = end of analysis (in msec)
%
% Fs = sampling frequency
%
% bg = black and white background image from the CMOS camera. This is a
% 100X100 pixel image from the micam ultima system. bg is stored in the
% handles structure handles.bg.
%
% cmap = a colormap input that facilites the potential inversion of the
% colormap. cmap is stored in the handles structure as handles.cmap.
%
%
% OUTPUT
% actMap1 = activation map
%
% METHOD
% An activation map is calculated by finding the time of the maximum derivative
% of each pixel in the specified time-windowed data.
%
% REFERENCES
%
% ADDITIONAL NOTES
%
% RELEASE VERSION 1.0.1
%
% AUTHOR: Qing Lou, Jacob Laughner ([email protected])
%
% MAINTAINED BY: Christopher Gloschat - ([email protected]) - [Jan. 2015 - Present]
%
% MODIFICATION LOG:
%
% Jan. 26, 2015 - The input cmap was added to input the colormap and code
% was added at the end of the function to set the colormap to the user
% determined values. In this case the most immediate purpose is to
% facilitate inversion of the default colormap.
%
%
%% Code
% Create initial variables
stat=round(stat*Fs);
endp=round(endp*Fs);
actMap = zeros(size(data,1),size(data,2));
mask2 = zeros(size(data,1),size(data,2));
temp = data(:,:,stat:endp); % windowed signal
% Re-normalize data in case of drift
temp = normalize_data(temp,Fs);
% identify channels that have been zero-ed out due to noise
mask = max(temp,[],3) > 0;
% Remove non-connected artifacts
CC = bwconncomp(mask,4);
numPixels = cellfun(@numel,CC.PixelIdxList);
[biggest,idx] = max(numPixels);
mask_id = CC.PixelIdxList{idx};
mask2(mask_id) = 1;
% Find First Derivative and time of maxium
temp2 = diff(temp,1,3); % first derivative
[max_der,max_i] = max(temp2,[],3); % find location of max derivative
% Activation Map Matrix
actMap1 = max_i.*mask;
actMap1(actMap1 == 0) = nan;
offset1 = min(min(actMap1));
actMap1 = actMap1 - offset1*ones(size(data,1),size(data,2));
actMap1 = actMap1/Fs*1000; %% time in ms
% Plot Map
zz = figure('Name','Activation Map');
contourf(flipud(actMap1),endp-stat,'LineColor','none')
title('Activation Map')
axis image
axis off
colormap(cmap);
colorbar;
% User prompt for input to create csv
prompt1 = {'Save activation map for CV analysis?'};
dlg_title1 = 'Save activation map';
num_lines1 = 1;
direc='/home/lab/Documents/Langendorff-MEHP/ActMaps/';
def1 = {strcat(direc,'ActMap-',filename,'.csv')};
answer = inputdlg(prompt1,dlg_title1,num_lines1,def1);
% process user inputs
if isempty(answer) % cancel save if user clicks "cancel"
return
end
filename = answer{1};
csvwrite(filename,actMap1);
end