This repository has been archived by the owner on May 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayerVoronoi2D.m
52 lines (39 loc) · 1.51 KB
/
layerVoronoi2D.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
function layerVoronoi2D( pathArchMat, photoPath, photoName)
close all;
load(pathArchMat);
photo_Path=[photoPath '\' photoName];
[H,W]=size(imread(photo_Path));
for numLayer=1:size(LayerCentroid,1)
if size(LayerCentroid{numLayer,1},1) >= 3
imagen=zeros(H,W);
for numCentroidLayer=1:size(LayerCentroid{numLayer,1},1)
x{numLayer,1}=LayerCentroid{numLayer,1}(:,2);
y{numLayer,1}=LayerCentroid{numLayer,1}(:,3);
imagen(round(x{numLayer,1}(numCentroidLayer,1)),round(y{numLayer,1}(numCentroidLayer,1)))=1;
end
f=figure('Visible', 'off');
k=boundary(x{numLayer,1},y{numLayer,1},0);
D = bwdist(imagen);
DL = watershed(D);
bgm = DL == 0;
invertedVoronoi=bgm;
Voronoi=1-invertedVoronoi;
imshow(Voronoi);
hold on;
[xq, yq]= find(Voronoi == 0);
[in,on] = inpolygon(xq,yq,round(x{numLayer,1}(k,1)),round(y{numLayer,1}(k,1)));
for index=1:size(in,1)
if in(index,1)==0
Voronoi(xq(index,1), yq(index,1))=1;
end
end
imshow(Voronoi);
plot(y{numLayer,1}(k),x{numLayer,1}(k),'-k', 'LineWidth',0.3);
% numLay=sprintf('Layer%d', numLayer);
% legend(numLay);
% Merge images to return
voronoiPhoto=[photoPath '\Layers\Voronoi\' 'voronoi_layers' sprintf('%d',numLayer)];
print(f, voronoiPhoto, '-dtiff', '-r300');
end
end
end