-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkitMovieProj.m
More file actions
83 lines (73 loc) · 1.97 KB
/
kitMovieProj.m
File metadata and controls
83 lines (73 loc) · 1.97 KB
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
function [figH,rgbImg,z]=kitMovieProj(movieFileName,zPlane,roi,progress)
% KITMOVIEPROJ Presents movie projection in Z and T
%
% SYNOPSIS kitShowMovieProj(movieFileName)
%
% INPUT movieFileName: Filename of movie to crop.
% zPlane: Show single z-plane (optional).
%
% Copyright (c) 2012 Jonathan W. Armond
if nargin<2
zPlane=[];
end
if nargin<3
roi=[];
end
if nargin<4
progress=0;
end
% Open movie.
if progress
h = waitbar(0,'Opening movie');
end
[metadata,reader] = kitOpenMovie(movieFileName);
% Load subset of frames and overlay.
nImages = 10;
frameList = unique(round(1:metadata.nFrames/nImages:metadata.nFrames));
% Loop to create max projections.
maxMergeChannels = 3;
imgSz = [metadata.frameSize(1:2), 3];
centreSz = 0.5; % Take central percentage for locating threshold.
border = (1-centreSz)/2;
cx(1) = round(imgSz(1)*border);
cx(2) = round(cx(1) + imgSz(1)*centreSz);
cy(1) = round(imgSz(2)*border);
cy(2) = round(cy(1) + imgSz(2)*centreSz);
rgbImg = zeros(imgSz);
mapChan = [2 1 3];
for c=1:min([maxMergeChannels, metadata.nChannels])
maxProj = zeros(metadata.frameSize(1:2));
for f=1:length(frameList)
if progress
waitbar(f/length(frameList),h);;
end
% Read stack.
if isempty(zPlane)
img = kitReadImageStack(reader, metadata, frameList(f), c);
else
img = kitReadImagePlane(reader, metadata, frameList(f), c, zPlane);
end
z = size(img,3);
% Average max projection of each frame.
maxProj = maxProj + max(img,[],3);
end
% Normalize.
maxProj = maxProj/length(frameList);
% Merge into RGB image.
centreImg = maxProj(cx(1):cx(2),cy(1):cy(2),:);
lb = splitModes(centreImg(centreImg>0));
if isempty(lb)
% Can't identify background. Use sensible default.
lb = 0.75;
end
slim = stretchlim(centreImg,[lb 1]);
rgbImg(:,:,mapChan(c)) = imadjust(maxProj,slim,[]);
end
if progress
close(h);
end
figH=figure;
imshow(rgbImg);
if ~isempty(roi)
rectangle('Position',roi,'LineWidth',2,'EdgeColor','y');
end