-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_shapes.m
22 lines (21 loc) · 967 Bytes
/
load_shapes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function [props, labels] = load_shapes(directory)
% training_shapes directory contains all 20 tetris pieces extracted by
% segmentation from training images
file_list = dir(directory);
props = [];
labels = [];
for i = 3:length(file_list)
if(not(strcmp(file_list(i).name, ".")) && not(strcmp(file_list(i).name,"..")))
path = directory + file_list(i).name;
% Associate a label in relation to filename
lettera = char(file_list(i).name);
lettera = lettera(1);
image = logical(imread(path));
% Create descriptor (# corners, eccentricity and ratio area/perimeter^2)
im_props = regionprops(image, "Eccentricity", "Area", "Perimeter");
corners = get_corners(image);
labels = [labels; lettera];
props = [props; corners.Count/8 im_props.Eccentricity im_props.Area/im_props.Perimeter^2];
end
end
end