-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipGetCentroids.m
89 lines (75 loc) · 2.1 KB
/
ipGetCentroids.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
%% ipGetCentroids
%% Clean Workspace
clear All
%% Get image
directory='../../info/Embalse_images_measurements/matlab/img';
[pathstr,name,ext] = fileparts(directory);
inputImage=imread([directory,'/IMG_MEAN.tif']); % This image is generated by ipAverage.m script
inputImage(:,:,1)=0; % Delete the red channel. Thermal noise.
grayImage=rgb2gray(inputImage); % Grayscale conversion
[y_size, x_size]=size(grayImage);
export_images=true;
%% Physical parameters
pixelXSize=119;%minsky=122; %img=119;
pixelYSize=123;%minsky=129; %img=123;
septaXSize=28;%minsky=28; %img=28;
septaYSize=24;%minsky=22; %img=24
%% Centroids
x_c=zeros(1,10);
y_c=zeros(1,10);
centroids=zeros(1,200);
k=1;
for i=1:10
for j=1:10
if i==1
x_c(1)=floor(pixelXSize/2);
else
x_c(i)=x_c(i-1)+septaXSize+pixelXSize;
end
if j==1
y_c(1)=floor(pixelYSize/2);
else
y_c(j)=y_c(j-1)+septaYSize+pixelYSize;
end
centroids(k)=x_c(i);
centroids(k+1)=y_c(j);
k=k+2;
end
end
%% Get pixels values
pixelsValues=zeros(119,123,100);
pixelsMean=zeros(1,100);
[y_size_p, x_size_p, pixels_]=size(pixelsValues);
k=1;
for l=1:100
for i=-floor(pixelXSize/2)+1:1:floor(pixelXSize/2)+1
for j=-floor(pixelYSize/2)+1:1:floor(pixelYSize/2)+1
pixelsValues(i+floor(pixelXSize/2),j+floor(pixelYSize/2),l)=grayImage(centroids(k)+i,centroids(k+1)+j);
end
end
k=k+2;
end
for l=1:100
pixelsMean(l)=sum(sum(pixelsValues(:,:,l)))/(y_size_p*x_size_p);
end
pixelsMeanMatrix=vec2mat(pixelsMean,10);
%% Graphic
figure
h=bar3(pixelsMeanMatrix);
colormap jet;
colorbar;
shading interp;
for i = 1:length(h)
zdata = get(h(i),'ZData');
set(h(i),'CData',zdata)
set(h,'EdgeColor','k')
end
rotate3d
%% Export images
if (export_images)
if ~exist(['export/',name], 'dir');mkdir('export/',name);end
saveas(gcf,['export/',name,'/Luminancia_perspectiva3D'],'epsc');
h=view(0, 90);
saveas(gcf,['export/',name,'/Luminancia_perspectiva2D'],'epsc');
h=view(-45, 30);
end