-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_field_cardboard_arena.m
66 lines (50 loc) · 1.84 KB
/
open_field_cardboard_arena.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
clear;
myFolder = uigetdir;
cd(myFolder);
filePattern = fullfile(myFolder, '*.tif');
tiffiles = dir(filePattern);
count = length(tiffiles);
% nMovies = count;
% curMovie = 0;
%figure;
Y = str2num(cell2mat(inputdlg('please enter the top left y coordinate')))
value = str2num(cell2mat(inputdlg('please enter the contrast value')))
for curMovie = 1:count;
%if mod(y, 2) ==1;
curMovieName = tiffiles(curMovie, 1).name;
fileinfo = imfinfo(curMovieName);
frames = numel(fileinfo);
I = imreadtiffstack (curMovieName, frames);
% resize option would go here - change I to J in line above
% I = imresize(J, 0.5);
%diamKeeper = zeros(frames,1);
I2 = I(Y:Y+135, : , :);
for z = 1:frames;
contrastkeeper(:,:,z) = imadjust(I2(:,:,z), [0.0 value], []); %originally 0.06, also used at 0.04, for recent movies set to 0.1 to start
end
clear('I')
level = graythresh(contrastkeeper(:,:,1));
for b = 1:frames;
bwkeeper(:,:,b) = im2bw(contrastkeeper(:,:,b), level);
end
for currentFrame = 1:frames;
%gimg = min( I(:,:,currentFrame), [], 3 );
%BW = im2bw( gimg, .02 ); %imagesc(BW) % changed to 0.02, was 0.4
BW = bwkeeper(:,:,currentFrame);
% 3. Get area and centroid porperties of image regions
st = regionprops( ~BW, 'Area', 'Centroid', 'PixelIdxList' );
%now pick largest region and get centroid
[sel_val, sel_inx] = max([st(1:end, 1).Area]);
res = st(sel_inx, 1).Centroid;
if currentFrame == 1;
res_keeper = res;
else
res_keeper = vertcat(res_keeper, res);
end
name = curMovieName(1:end-4);
save(char(strcat(name, '.mat')), 'res_keeper');
end
end
save('files', 'tiffiles');
save('Y', 'Y');
save('value', 'value');