-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_spike.m
66 lines (50 loc) · 1.37 KB
/
mod_spike.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% input
% img:
% center: 0-360
% height:
% width:
% GUI_use: true: boundary -> boundary
% false: image -> image
function out = mod_spike(input, center, height, width, GUI_use)
if GUI_use
bd_index = input;
else
img = input;
if size(img,3)~=1
img=rgb2gray(img);
end
if ~isa(img,'logical')
mask = imbinarize(img); % binary area image
else
mask = img;
end
% extract binary boundary
contour = bwperim(mask);
% extract boundary indexes
bd_index =find_close_indeces(contour);
end
x = bd_index(:,1);
y = bd_index(:,2);
% get cenrtoid
centerX = round(mean(x));
centerY = round(mean(y));
% convert to polar coordinate
[theta,rho] = cart2pol(x-centerX,y-centerY);
theta = theta + pi; % [-pi pi]->[0 2pi]
%-----------theta in [0 2pi]---- begin
location = (center/360)*(2*pi); % 360->2pi
out_rho = hat_rho(rho,theta,location,height,width);
%------------------------------- end
% convert back to Cartesian coordinate
[newx, newy] = pol2cart(theta-pi,out_rho); % [0 2pi]->[-pi pi]
Xint = round(newx) + centerX;
Yint = round(newy) + centerY;
bd = [Xint,Yint];
if GUI_use
out = bd;
else
% convert boundary to mask
out = poly2mask(bd(:,2), bd(:,1),size(mask,1),size(mask,2));
out = imfill(out,'holes');
end
end