-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaskPolygon.m
More file actions
42 lines (35 loc) · 1.41 KB
/
MaskPolygon.m
File metadata and controls
42 lines (35 loc) · 1.41 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Masks the 2D polygon in a reference plane of size 2*Radius x 2*Radius.
% This will convert the vertices into a solid 2D polygon
% The polygon is meshed over the reference plane and is indicated by logic
% 1, while the empty area is indicated by logic 0
%
% Parameters:
% Inputs: Radius - The average radius of the ellipse inside which the
% polygon will be plotted.
% This is obtained from GenerateRegularPolygon.m
% x,y - Vertices of the 2D polygon.
%
% Output: binaryImage - Returns binaryImage (1 = area covered by polygon,
% 0 = uncovered area)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function binaryImage = MaskPolygon(x,y,Radius)
%% Testing purpose only
% clear all;
%
% Diameter = 1000;
% Radius = Diameter/2;
% Num_of_Vertices = 4;
% Aspect_ratio = 9;
%
% [x,y] = GenerateRegularPolygon (Radius, Num_of_Vertices, Aspect_ratio);
%% Masking the polygon to form a logical image matrix of size 2*Radius x 2*Radius
adjust_factor = round((Radius) - ((max(x) - min(x))/2));
x = x + adjust_factor;
% Poly2mask is used to make the logical image matrix (or mask matrix)
binaryImage = flip(poly2mask(x,y, 2*Radius, 2*Radius));
%% Testing purpose only
% figure(2)
% imshow(binaryImage);
%%%
end