-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_rois.m
35 lines (28 loc) · 1.02 KB
/
get_rois.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
function [roi_mat,labels] = get_rois(gray,roi_file, inFile)
labels = [];
roi_mat = [];
if isempty(roi_file)
roi_file = split(inFile,'.');
roi_file = roi_file(1);
roi_file = strcat(roi_file,'.zip');
else
roi_file = roi_file(1);
end
img_size = size(gray);
sizex = img_size(1);
sizey = img_size(2);
rois = ReadImageJROI(roi_file);
for i = 1:length(rois)
roi = rois{i};
if strcmp(roi.strType,'Rectangle')
slice = zeros(sizex,sizey);
points = roi.vnRectBounds;
slice(points(1):points(3),points(2):points(4)) = ones(points(3)-(points(1)-1),points(4)-(points(2)-1));
else
slice = poly2mask(roi.mnCoordinates(:,1),roi.mnCoordinates(:,2), sizex,sizey);
end
roi_mat = cat(3,roi_mat,slice);
labels = cat(2,labels,[string(roi.strName)]);
end
% roi_mat = getSmallestInnerRectangle(roi_mat);
end