Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AxonTracker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenSource
AxonTracker
Commits
20fd73e6
Commit
20fd73e6
authored
Aug 24, 2010
by
Mark Winter
Committed by
Mark Winter
Oct 14, 2014
Browse files
Options
Downloads
Patches
Plain Diff
MATLAB scripted tracking and plotConnect improvements
parent
d17175e2
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
matlab/GoSegmentIt.m
+218
-0
218 additions, 0 deletions
matlab/GoSegmentIt.m
matlab/GoTrack43.m
+63
-0
63 additions, 0 deletions
matlab/GoTrack43.m
matlab/Make43MovieList.m
+26
-0
26 additions, 0 deletions
matlab/Make43MovieList.m
matlab/plotConnect.m
+18
-3
18 additions, 3 deletions
matlab/plotConnect.m
with
325 additions
and
3 deletions
matlab/GoSegmentIt.m
0 → 100644
+
218
−
0
View file @
20fd73e6
function
[
rgDetect
,
rgMotionBlur
,
imKymo
,
LKymo
,
iPath
,
jPath
,
totalDetections
]
=
GoSegmentIt
(
movieroot
,
moviefilename
,
tracefilename
,
kymofilename
,
alpha
,
extMaxH
)
rgDetect
=
[];
rgMotionBlur
=
[];
LKymo
=
[];
iPath
=
[];
jPath
=
[];
bCheckMotionBlur
=
1
;
if
(
nargout
<
2
)
bCheckMotionBlur
=
0
;
end
Movie_Name
=
fullfile
(
movieroot
,
moviefilename
);
load
(
tracefilename
);
imKymo
=
imread
(
kymofilename
);
nKymo
=
0
*
imKymo
;
hold
off
;
imagesc
(
imKymo
);
hold
on
;
colormap
gray
RADIUS_DILATE
=
12
;
RADIUS
=
10
;
NFRAMES
=
120
;
sed
=
strel
(
'
disk
'
,
RADIUS_DILATE
);
se
=
strel
(
'
disk
'
,
RADIUS
);
stats
=
[
0
Inf
];
rcFG
=
{};
rcPKS
=
{};
for
t
=
1
:
NFRAMES
im
=
(
imread
(
Movie_Name
,
t
));
if
max
(
im
(
:
))
<
stats
(
2
)
stats
(
2
)
=
max
(
im
(
:
));
end
if
min
(
im
(
:
))
>
stats
(
1
)
stats
(
1
)
=
min
(
im
(
:
));
end
end
nbdsize
=
5
;
nbdoffset
=
floor
(
nbdsize
/
2
);
nbdsize
=
2
*
nbdoffset
+
1
;
rgDetect
=
[];
totalDetections
=
0
;
for
t
=
1
:
NFRAMES
im
=
(
imread
(
Movie_Name
,
t
));
im
(
im
>
stats
(
2
))
=
stats
(
2
);
im
=
mat2gray
(
im
);
%
bw
=
logical
(
0
*
im
);
idx
=
sub2ind
(
size
(
im
),
round
(
iPath
),
round
(
jPath
));
bw
(
idx
)
=
1
;
bwd
=
imdilate
(
bw
,
sed
);
bw
=
imdilate
(
bw
,
se
);
%
level
=
alpha
*
graythresh
(
im
(
bwd
));
bwi
=
im2bw
(
im
,
level
);
bwi
(
~
bw
)
=
0
;
bwMax
=
imextendedmax
(
im
,
extMaxH
,
4
)
&
bwi
;
bwMax
=
bwmorph
(
bwMax
,
'
shrink
'
,
Inf
);
[
rfg
cfg
]
=
find
(
bwi
);
rcFG
{
t
}
=
[
rfg
cfg
];
%
[
rpk
cpk
]
=
find
(
bwMax
&
bwi
);
%
rcPKS
{
t
}
=
[
rpk
cpk
];
[
L
num
]
=
bwlabel
(
bwi
,
4
);
%
%
%
bwp
=
bwboundaries
(
bwi
);
%
hold
off
;
imagesc
(
im
);
hold
on
%
if
1
==
t
brighten
(
0
.
33
),
end
%
for
i
=
1
:
length
(
bwp
)
%
plot
(
bwp
{
i
}(
:
,
2
),
bwp
{
i
}(
:
,
1
),
'
-
r
'
)
%
end
%
[
r
c
]
=
find
(
bwi
);
%
plot
(
c
,
r
,
'
.
g
'
)
%
%
%
plot
all
pts
%
for
n
=
1
:
num
%
[
r
c
]
=
find
(
L
==
n
);
%
for
i
=
1
:
length
(
r
)
%
pKymo
=
LKymo
(
r
(
i
),
c
(
i
));
%
if
0
==
pKymo
%
dd
=
(
jPath
-
c
(
i
)).
^
2
+
(
iPath
-
r
(
i
)).
^
2
;
%
[
m
pKymo
]
=
min
(
dd
);
%
end
%
plot
(
t
,
pKymo
,
'
.
b
'
)
%
end
%
end
%
plot
maxima
j
=
1
;
for
n
=
1
:
num
[
r
c
]
=
find
(
L
==
n
);
if
length
(
r
)
>
10
,
ccc
=
'
.
m
'
;
elseif
length
(
r
)
>
6
,
ccc
=
'
.
r
'
;
elseif
length
(
r
)
>
3
,
ccc
=
'
.
g
'
;
else
ccc
=
'
.
y
'
;
end
ccc
=
'
.
r
'
;
for
i
=
1
:
length
(
r
)
if
~
bwMax
(
r
(
i
),
c
(
i
)),
continue
,
end
pKymo
=
LKymo
(
r
(
i
),
c
(
i
));
if
0
==
pKymo
dd
=
(
jPath
-
c
(
i
)).
^
2
+
(
iPath
-
r
(
i
)).
^
2
;
[
m
pKymo
]
=
min
(
dd
);
end
plot
(
t
,
pKymo
,
ccc
)
yl
=
max
(
r
(
i
)
-
nbdoffset
,
1
);
xl
=
max
(
c
(
i
)
-
nbdoffset
,
1
);
yh
=
min
(
size
(
im
,
1
),
r
(
i
)
+
nbdoffset
);
xh
=
min
(
size
(
im
,
2
),
c
(
i
)
+
nbdoffset
);
yoffmin
=
yl
-
(
r
(
i
)
-
nbdoffset
);
yoffmax
=
yh
-
(
r
(
i
)
+
nbdoffset
);
xoffmin
=
xl
-
(
c
(
i
)
-
nbdoffset
);
xoffmax
=
xh
-
(
c
(
i
)
+
nbdoffset
);
peaknbd
=
-
ones
(
2
*
nbdoffset
+
1
,
2
*
nbdoffset
+
1
);
peaknbd
((
yoffmin
+
1
)
:
(
nbdsize
+
yoffmax
),(
xoffmin
+
1
)
:
(
nbdsize
+
xoffmax
))
=
im
(
yl
:
yh
,
xl
:
xh
);
rgDetect
{
t
}(
j
,
:
)
=
[
r
(
i
)
c
(
i
)
peaknbd
(
:
)
'
];
rcPKS
{
t
}(
j
,
:
)
=
[
r
(
i
)
c
(
i
)];
j
=
j
+
1
;
totalDetections
=
totalDetections
+
1
;
end
%
pix
=
find
(
L
==
n
);
%
if
~
any
(
bwMax
(
pix
))
%
rmean
=
round
(
mean
(
r
));
%
cmean
=
round
(
mean
(
c
));
%
bwMax
(
rmean
,
cmean
)
=
1
;
%
pKymo
=
LKymo
(
rmean
,
cmean
);
%
if
0
==
pKymo
%
dd
=
(
jPath
-
cmean
).
^
2
+
(
iPath
-
rmean
).
^
2
;
%
[
m
pKymo
]
=
min
(
dd
);
%
end
%
plot
(
t
,
pKymo
,
'
xg
'
)
%
end
end
drawnow
end
if
(
~
bCheckMotionBlur
)
rgMotionBlur
=
[];
return
;
end
lenpix
=
size
(
imKymo
,
1
);
if
(
(
totalDetections
/
(
lenpix
*
120
))
>
0
.
3
)
disp
([
'
Too
many
detections
'
moviefilename
]);
rgDetect
=
[];
rgMotionBlur
=
[];
return
;
end
VMAX
=
20
;
rgMotionBlur
=
cell
(
1
,
length
(
rgDetect
)
-
1
);
for
t
=
1
:
NFRAMES
-
1
bwtFG
=
logical
(
0
*
im
);
idx
=
sub2ind
(
size
(
im
),
rcFG
{
t
}(
:
,
1
),
rcFG
{
t
}(
:
,
2
));
bwtFG
(
idx
)
=
1
;
bwt1FG
=
logical
(
0
*
im
);
idx
=
sub2ind
(
size
(
im
),
rcFG
{
t
+
1
}(
:
,
1
),
rcFG
{
t
+
1
}(
:
,
2
));
bwt1FG
(
idx
)
=
1
;
[
L
num
]
=
bwlabel
(
bwtFG
,
8
);
[
L1
num1
]
=
bwlabel
(
bwt1FG
,
8
);
for
i
=
1
:
size
(
rcPKS
{
t
},
1
)
[
r
c
]
=
find
(
L
==
L
(
rcPKS
{
t
}(
i
,
1
),
rcPKS
{
t
}(
i
,
2
)));
rgMotionBlur
{
t
}{
i
}
=
[];
for
j
=
1
:
size
(
rcPKS
{
t
+
1
},
1
)
vij
=
norm
([
rcPKS
{
t
+
1
}
(
j
,
:
)
-
rcPKS
{
t
}(
i
,
:
)]);
if
vij
>
VMAX
,
continue
,
end
[
r1
c1
]
=
find
(
L1
==
L1
(
rcPKS
{
t
+
1
}(
j
,
1
),
rcPKS
{
t
+
1
}(
j
,
2
)));
dmin
=
Inf
;
for
k
=
1
:
length
(
r1
)
d
=
sqrt
(
(
r1
(
k
)
-
r
).
^
2
+
(
c1
(
k
)
-
c
).
^
2
);
dd
=
min
(
d
);
if
dd
<
dmin
dmin
=
dd
;
end
end
p1
=
LKymo
(
rcPKS
{
t
}(
i
,
1
),
rcPKS
{
t
}(
i
,
2
));
if
0
==
p1
dd
=
(
jPath
-
rcPKS
{
t
}(
i
,
2
)).
^
2
+
(
iPath
-
rcPKS
{
t
}(
i
,
1
)).
^
2
;
[
m
p1
]
=
min
(
dd
);
end
p2
=
LKymo
(
rcPKS
{
t
+
1
}(
j
,
1
),
rcPKS
{
t
+
1
}(
j
,
2
));
if
0
==
p2
dd
=
(
jPath
-
rcPKS
{
t
+
1
}(
j
,
2
)).
^
2
+
(
iPath
-
rcPKS
{
t
+
1
}(
j
,
1
)).
^
2
;
[
m
p2
]
=
min
(
dd
);
end
if
dmin
<
(
1
-
150
/
650
)
*
vij
+
2
plot
([
t
t
+
1
],[
p1
p2
],
'
-
y
'
)
%
rgMotionBlur
{
t
}{
i
}(
1
:
2
,
end
+
1
)
=
[
j
;
1
];
else
plot
([
t
t
+
1
],[
p1
p2
],
'
-
b
'
)
%
rgMotionBlur
{
t
}{
i
}(
1
:
2
,
end
+
1
)
=
[
j
;
0
];
end
rgMotionBlur
{
t
}{
i
}(
1
:
2
,
end
+
1
)
=
[
j
;
dmin
];
plot
(
t
,
p1
,
'
.
r
'
)
plot
(
t
+
1
,
p2
,
'
.
r
'
)
end
end
drawnow
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
matlab/GoTrack43.m
0 → 100644
+
63
−
0
View file @
20fd73e6
inputroot
=
'C:\Users\mwinter\Documents\MATLAB\KymoTrackingData\Movies'
;
if
(
~
exist
(
'mvlist'
,
'var'
)
)
mvlist
=
Make43MovieList
(
inputroot
);
end
if
(
~
exist
(
'alphalist'
,
'var'
)
)
alphalist
=
ones
(
size
(
mvlist
));
end
if
(
~
exist
(
'exthlist'
,
'var'
)
)
exthlist
=
0.025
*
ones
(
size
(
mvlist
));
end
if
(
~
exist
(
'startidx'
,
'var'
)
)
startidx
=
1
;
end
if
(
~
exist
(
'endidx'
,
'var'
)
)
endidx
=
length
(
mvlist
);
end
if
(
~
exist
(
'errlist'
,
'var'
)
)
errlist
=
[];
end
successlist
=
[];
results
=
struct
([]);
for
i
=
startidx
:
endidx
if
(
~
isempty
(
find
(
errlist
==
i
,
1
))
)
continue
;
end
results
(
i
)
.
movieroot
=
mvlist
(
i
)
.
movieroot
;
results
(
i
)
.
moviename
=
mvlist
(
i
)
.
moviename
;
results
(
i
)
.
alpha
=
alphalist
(
i
);
results
(
i
)
.
extH
=
exthlist
(
i
);
[
rgDetect
,
rgMotionBlur
,
imKymo
,
LKymo
,
iPath
,
jPath
]
=
GoSegmentIt
(
mvlist
(
i
)
.
movieroot
,
mvlist
(
i
)
.
moviename
,
mvlist
(
i
)
.
tracefilename
,
mvlist
(
i
)
.
kymofilename
,
alphalist
(
i
),
exthlist
(
i
));
%results(i) = GoSegmentIt(results(i), mvlist(i).tracefilename, mvlist(i).kymofilename);
% if ( isempty(rgDetect) )
% disp(['Error segmenting ' mvlist(i).root ': ' mvlist(i).cellname]);
% errlist(end+1) = i;
% continue;
% end
outdatname
=
[
mvlist
(
i
)
.
root
'_'
mvlist
(
i
)
.
cellname
];
save
([
outdatname
'.mat'
],
'rgDetect'
,
'rgMotionBlur'
,
'imKymo'
,
'LKymo'
,
'iPath'
,
'jPath'
);
successlist
(
end
+
1
)
=
i
;
segdatname
=
[
outdatname
'_seg.dat'
];
mbdatname
=
[
outdatname
'_mb.dat'
];
writeSegData
(
segdatname
,
rgDetect
);
%writeTraceData([outdatname '_trace.dat'], [jPath';iPath']);
writeMotionBlurData
(
mbdatname
,
rgMotionBlur
);
system
([
'C:\Users\mwinter\Documents\Projects\KymoTracker\trunk\Release\KymoTracker.exe "'
segdatname
'" "'
mbdatname
'" "'
outdatname
'" &'
]);
end
save
(
'finalstate.mat'
,
'mvlist'
,
'errlist'
,
'successlist'
,
'alphalist'
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
matlab/Make43MovieList.m
0 → 100644
+
26
−
0
View file @
20fd73e6
function
movielist
=
Make43MovieList
(
inputroot
)
movielist
=
[];
folders
=
{
'HD5 BDNF middle'
,
'HD6 BDNF MIDDLE'
,
'HD9 BDNF MIDDLE'
,
'HD10 BDNF MIDDLE'
};
maxmovies
=
20
;
for
i
=
1
:
length
(
folders
)
ROOT
=
folders
{
i
};
for
j
=
1
:
maxmovies
cellname
=
[
'cell '
num2str
(
j
)
' middle'
];
moviename
=
[
cellname
' BDNF.tif'
];
movieroot
=
fullfile
(
inputroot
,
ROOT
);
moviefilename
=
fullfile
(
movieroot
,
moviename
);
tracefilename
=
fullfile
(
inputroot
,
'OutputKymos'
,
[
ROOT
'_'
cellname
'_path.mat'
]);
kymofilename
=
fullfile
(
inputroot
,
'OutputKymos'
,
[
ROOT
'_'
cellname
'_kymo.tif'
]);
if
(
exist
(
moviefilename
,
'file'
)
&&
exist
(
tracefilename
,
'file'
)
&&
exist
(
kymofilename
,
'file'
)
)
movielist
(
end
+
1
)
.
root
=
ROOT
;
movielist
(
end
)
.
cellname
=
cellname
;
movielist
(
end
)
.
moviename
=
moviename
;
movielist
(
end
)
.
movieroot
=
movieroot
;
movielist
(
end
)
.
tracefilename
=
tracefilename
;
movielist
(
end
)
.
kymofilename
=
kymofilename
;
end
end
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
matlab/plotConnect.m
+
18
−
3
View file @
20fd73e6
...
...
@@ -25,10 +25,25 @@ function plotConnect(trackList, gConnect, gCellData, hashNodes, rgDetect, imKymo
plot
(
trkt
(
1
),
trkpts
(
1
),
'o'
,
'Color'
,
trackColors
(
i
,:));
h
=
plot
(
trkt
,
trkpts
,
'Color'
,
trackColors
(
i
,:),
'LineWidth'
,
1
,
'LineStyle'
,
'-'
);
set(h, 'ButtonDownFcn',@Plot
Button
ClickFunc, 'UserData', i);
set
(
h
,
'ButtonDownFcn'
,
@
Plot
Segment
ClickFunc
,
'UserData'
,
i
);
end
function PlotButtonClickFunc(src, evt)
% function PlotDetectionClickFunc(src, evt)
% clktype = get(gcf, 'SelectionType');
%
% if ( strcmpi(clktype,'normal') )
% elseif ( strcmpi(clktype,'alt') )
% if ( ~isempty(branchPaths) )
% for j=1:length(branchPaths)
% delete(branchPaths(j));
% end
% branchPaths = [];
% highlightedBranch = [];
% end
% end
% end
function
PlotSegmentClickFunc
(
src
,
evt
)
clktype
=
get
(
gcf
,
'SelectionType'
);
if
(
~
isempty
(
highlightedObj
)
)
set
(
highlightedObj
,
'LineWidth'
,
1
);
...
...
@@ -81,6 +96,6 @@ function plotConnect(trackList, gConnect, gCellData, hashNodes, rgDetect, imKymo
highlightedBranch
=
src
;
set
(
src
,
'LineWidth'
,
2
);
cidx
=
get
(
src
,
'UserData'
);
disp(['
Path
Cost: ' num2str(gCellData(cidx).cost)]);
disp
([
'
Segment ('
num2str
(
gCellData
(
cidx
)
.
path
(
1
))
','
num2str
(
gCellData
(
cidx
)
.
path
(
2
))
')
Cost: '
num2str
(
gCellData
(
cidx
)
.
cost
)]);
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment