%fileIn = '/home/karela/data/StrokeRatBrain/batches/20190610_092401_190610_STROKE_RAT_BRAIN_AMCAO9_1_1__01/experiment1/conv/data.mat';
%data_reg = load('/home/karela/data/StrokeRatBrain/batches/20190610_092401_190610_STROKE_RAT_BRAIN_AMCAO9_1_1__01/experiment1/reg/data.mat');

%fileIn = '/home/karela/data/StrokeRatBrain/batches/20190614_094953_20190614_Stroke_RAT_BRAIN_AMCAO12_1_1_01/experiment1/conv/data.mat';
%data_reg = load('/home/karela/data/StrokeRatBrain/batches/20190614_094953_20190614_Stroke_RAT_BRAIN_AMCAO12_1_1_01/experiment1/reg/data.mat');

fileIn = '/home/karela/data/StrokeRatBrain/batches/20190821_092549_190821_STROKE_RAT_BRAIN_AMCAO14_1_1_01/experiment1/conv/data.mat';
data_reg = load('/home/karela/data/StrokeRatBrain/batches/20190821_092549_190821_STROKE_RAT_BRAIN_AMCAO14_1_1_01/experiment1/reg/data.mat');

% fileIn = '/home/karela/data/StrokeRatBrain/batches/20200610_101545_AMCAO_AC05_1_1_20200610_101545_AMCAO_AC05_1_1_01/experiment1/conv/data.mat'
% data_reg = load('/home/karela/data/StrokeRatBrain/batches/20200610_101545_AMCAO_AC05_1_1_20200610_101545_AMCAO_AC05_1_1_01/experiment1/reg/data.mat');

%load('SyntheticEchoes_cartesian_reco');
%load('SyntheticEchoes_cartesian_ReferenceMaps');

%load('TFsel');
load('TFsel14');
%load('TFsel_simul');

%fileIn = '/home/karela/data/StrokeRatBrain/batches/20200611_114511_AMCAO_AC08_1_1_20200611_114511_AMCAO_AC08_1_1_01/experiment1/conv/data.mat'
%fileIn = '/home/karela/data/StrokeRatBrain/batches/20200713_105447_AMCAO_AC10_1_1_20200713_105447_AMCAO_AC10_1_1_01/experiment1/conv/data.mat'
% fileIn='data.mat'
load(fileIn);
%%
data_reg = data_reg.data2;
nSlices=size(data_reg,1);
nSamples=size(data_reg,2);
[nRows,nCols]=size(data_reg{1,1});
data4D_reg=zeros(nRows,nCols,nSlices,nSamples);
for sl=1:nSlices
    for t=1:nSamples
        data4D_reg(:,:,sl,t)=imrotate(data_reg{sl,t},90);
    end
end

% convert cell data to 4D matrix (x,y,z,time)
nSlices=size(data2,1);
nSamples=size(data2,2);
[nRows,nCols]=size(data2{1,1});
data4D=zeros(nRows,nCols,nSlices,nSamples);
for sl=1:nSlices
    for t=1:nSamples
        data4D(:,:,sl,t)=imrotate(data2{sl,t},90);
    end
end

outputFolder=[];
nSamples=size(data4D,4);
timeAxis=(0:1:nSamples-1)*info.acq.Ts/60;

data2D=DataCells2Mat(data2);

data_reg = data4D_reg;
 
%% K-means vs angio

I1 = data_reg(:,:,5,60);
I1_1 = I1;
I1 = mat2gray(I1);
I1 = I1.*255;
I1 = uint8(I1);

a = TFsel(:,:,5);
a = uint8(~a);

I2 = I1.*a;
I3 = I1;
I3(a==0)=255;


I1(:,:,1) = I3;
I1(:,:,2) = I2;
I1(:,:,3) = I2;

figure;
subplot 121
imshow(I1);
subplot 122
imshow(I1_1,[])

% %% Simul visual
% 
% I1 = data2D(:,:,:,61);
% I1 = mat2gray(I1);
% I1 = I1.*255;
% I1 = uint8(I1);
% I1 = imresize(I1, [1024 1024]);
% 
% a = TFsel(:,:);
% a = imresize(a, [1024 1024]);
% a = uint8(~a);
% 
% I2 = I1.*a;
% I3 = I1;
% I3(a==0)=255;
% 
% 
% I1(:,:,1) = I3;
% I1(:,:,2) = I2;
% I1(:,:,3) = I2;
% 
% figure;
% subplot 121
% imshow(I1);
% subplot 122
% imshow(RoisMap,[])

%% K-means

load('kmeans_pass1')
figure;
subplot 311
plot(timeAxis,clusterSignalsNorm(1,:),'r')
hold on
plot(timeAxis,clusterSignalsNorm(2,:),'g')
hold on
plot(timeAxis,clusterSignalsNorm(3,:),'b')
xlabel('Časová osa [min]')
ylabel('AIF [a.u.]')
legend('Shluk 1','Shluk 2','Shluk 3')

load('kmeans_pass2')
subplot 312
plot(timeAxis,clusterSignalsNorm(1,:),'r')
hold on
plot(timeAxis,clusterSignalsNorm(2,:),'g')
hold on
plot(timeAxis,clusterSignalsNorm(3,:),'b')
xlabel('Časová osa [min]')
ylabel('AIF [a.u.]')
legend('Shluk 1','Shluk 2','Shluk 3')

load('kmeans_pass3')
subplot 313
plot(timeAxis,clusterSignalsNorm(1,:),'r')
hold on
plot(timeAxis,clusterSignalsNorm(2,:),'g')
hold on
plot(timeAxis,clusterSignalsNorm(3,:),'b')
xlabel('Časová osa [min]')
ylabel('AIF [a.u.]')
legend('Shluk 1','Shluk 2','Shluk 3')

load('kmeans_pass4')
figure;
plot(timeAxis,Lowest1StMomentSig,'r')
xlabel('Časová osa [min]')
ylabel('AIF [a.u.]')


