forked from woxxel/ROI-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_blobs.m
More file actions
62 lines (51 loc) · 1.65 KB
/
plot_blobs.m
File metadata and controls
62 lines (51 loc) · 1.65 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
function [hPlot] = plot_blobs(ax,A,offset,thr,ROI_line,ROI_color,hwait)
%% --- INPUTS ---
%% ax - axis to plot to
%% A - (nX x nY x nROI) array containing ROI footprints in order to plot
%% offset - coordinates (min_y, max_y, min_x, max_x) of imaging window to be displayed
%% thr - threshold for "energy"-cutoff of displayed ROI area (0 = full, 1=peak only)
%% ROI_line - linestyle of ROI contours: single value, or cell of length nROI to be plotted
%% ROI_color - color of ROI contours: single value, or cell of length nROI to be plotted
%% --- OUTPUTS ---
%% hPlot - handles to ROIs
nROI = size(A,3);
if ~iscell(ROI_line) || ~(length(ROI_line) == nROI)
linestyle_tmp = ROI_line;
ROI_line={};
[ROI_line{1:nROI}] = deal(linestyle_tmp);
end
if ~iscell(ROI_color) || ~(length(ROI_color) == nROI)
color_tmp = ROI_color;
ROI_color={};
[ROI_color{1:nROI}] = deal(color_tmp);
end
if nargin==7
waitbar(0,hwait,sprintf('Plotting %d ROIs...',nROI))
end
if isempty(offset)
offset = [0 0];
end
hold(ax,'on')
for n=1:size(A,3)
if nargin==7 && mod(n,100)==0
waitbar(n/nROI,hwait)
end
A_tmp = A(:,:,n);
if nanmax(A_tmp(:)) > 0
A_tmp(A_tmp<thr*max(A_tmp(:))) = 0;
BW = bwareafilt(A_tmp>0,1);
blob = bwboundaries(BW);
if ~isempty(blob)
for ii = 1:length(blob)
blob{ii} = fliplr(blob{ii}-offset);
hPlot(n) = plot(ax,blob{ii}(:,1),blob{ii}(:,2),ROI_line{n},'Color',ROI_color{n},'linewidth', 0.75,'Hittest','off');
end
end
end
end
hold(ax,'off')
drawnow
if nargin==7
waitbar(1,hwait)
end
end