-
Notifications
You must be signed in to change notification settings - Fork 0
/
chooseROIsAsBWConnCompStruct.m
46 lines (37 loc) · 1.4 KB
/
chooseROIsAsBWConnCompStruct.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
function roiStructs = chooseROIsAsBWConnCompStruct(image)
if isnumeric(image) && ismatrix(image)
h = imshow(image);
elseif ishandle(image)
switch get(image,'Type')
case {'figure' 'axes'}
hs = findobj(image,'Type','image');
if isempty(hs)
error('Figure or axes handle must contain at least one image');
end
h = hs(1);
case 'image'
h = image;
otherwise
error('First argument must be a 2D matrix or a handle to an image or to a figure or an axes containing at least one image');
end
image = get(h,'CData');
else
error('First argument must be a 2D matrix or a handle to an image or to a figure or an axes containing at least one image');
end
a = get(h,'Parent');
caxis(a,prctile(image(:),[1 99]));
imageSize = fliplr(size(image));
roi = imfreehand(a);
while ~isempty(roi)
if exist('rois','var')
rois(end+1) = roi; %#ok<AGROW>
else
rois = roi;
end
roi = imfreehand(a);
end
if ~exist('rois','var')
return
end
roiStructs = struct('Connectivity',8,'ImageSize',{imageSize},'NumObjects',numel(rois),'PixelIdxList',{arrayfun(@(r) find(createMask(r)),rois,'UniformOutput',false)});
end