clear all; close all; clc;

% Výber 20 obrazov každého z gélov

% logaritmus10 = 0; % surové dáta
logaritmus10 = 1; % dekadický logaritmus


data = cell(20,7);     % databaza obrazov  0,5% gelu 1. stlpec;
%                                          1,0% gelu 2. stlpec;
%                                          1,5% gelu 3. stlpec;
%                                          2,0% gelu 4. stlpec;
%                                          2,5% gelu 5. stlpec;
%                                          3,0% gelu 6. stlpec;
%                                          3,5% gelu 7. stlpec;

Adress1 = 'H:\dp\29.4.2015\gely\gel_0.5_1_3D_000.FRG';
Adress2 = 'H:\dp\29.4.2015\gely\gel_1.0_1_2_3D_000.FRG';
Adress3 = 'H:\dp\29.4.2015\gely\gel_1.5_2_3D_000.FRG';
Adress4 = 'H:\dp\29.4.2015\gely\gel_2.0_1_3D_000.FRG';
Adress5 = 'H:\dp\29.4.2015\gely\gel_2.5_1_3D_000.FRG';
Adress6 = 'H:\dp\29.4.2015\gely\gel_3.0_5_3D_000.FRG';
Adress7 = 'H:\dp\29.4.2015\gely\gel_3.5_2_3D_000.FRG';

%% 0,5% gel, 1. stlpec;
fid = fopen(Adress1);
header.FileIdent               = fread(fid, 16, 'schar');    
header.NumberOfImages          = fread(fid,  1, 'int32');
fclose(fid);

% vektor poradovych cisel obrazov v bin. subore
a_05 =   [19, 21, 23, 28, 29, 40, 41, 44, 45, 46, 47, 48, 50, 51, 55,...
         57, 58, 59, 60, 61];
%      , 62, 63, 64, 69, 70, 71, 75, 79, 90, 91, 92, ...
%          93, 94, 100, 101, 103, 104, 108, 109, 11, 112, 113];

l_05 = length(a_05);
p_05 = 1; % pocitadlo na urcenie pozicie zapisu v cell array

for i = a_05
% for i = 1:header.NumberOfImages
    ImageRaw = frgread_surove(Adress1, i);
    if logaritmus10 == 1
        ImageRaw = log10(ImageRaw);
    end
    data{p_05,1} = ImageRaw;
    p_05 = p_05+1;
%     imshow(ImageRaw, [])
%     pause(0.1) % pomale prehliadanie obrazov
%     pause
end

%% 1,0% gel, 2. stlpec;
fid = fopen(Adress1);
header.FileIdent               = fread(fid, 16, 'schar');    
header.NumberOfImages          = fread(fid,  1, 'int32');
fclose(fid);

% vektor poradovych cisel obrazov v bin. subore
a_10 =   [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];

l_10 = length(a_10);
p_10 = 1; % pocitadlo na urcenie pozicie zapisu v cell array

for i = a_10
% for i = 1:header.NumberOfImages
    ImageRaw = frgread_surove(Adress2, i);
    if logaritmus10 == 1
    ImageRaw = log10(ImageRaw);
    end
    data{p_10,2} = ImageRaw;
    p_10 = p_10+1;
%     imshow(ImageRaw, [])
%     pause(0.1) % pomale prehliadanie obrazov 
%     pause
end

%% 1,5% gel, 3. stlpec;

fid = fopen(Adress3);
header.FileIdent               = fread(fid, 16, 'schar');
header.NumberOfImages          = fread(fid,  1, 'int32');
fclose(fid);

% vektor poradovych cisel obrazov v bin. subore
a_15 = [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, 108, 109, 120, 121, 122, 123, 124,...
%        125, 129, 130, 131, 132, 133, 134, 135, 136, 137];
% zaloha_15 = [141, 142, 155, 156, 157, 158, 159, 160, 161, 162, 171, 172, 173, 174, 175, 268];
       
l_15 = length(a_15);
p_15 = 1; % pocitadlo na urcenie pozicie zapisu v cell array

for i = a_15
% for i = 1:header.NumberOfImages
    ImageRaw = frgread_surove(Adress3, i);
    if logaritmus10 == 1
        ImageRaw = log10(ImageRaw);
    end
    data{p_15,3} = ImageRaw;
    p_15 = p_15+1;
%     imshow(ImageRaw, [])
%     pause(0.1) % pomale prehliadanie obrazov 
%     pause
end
%
%% 2,0% gel, 4. stlpec;

fid = fopen(Adress4);
header.FileIdent               = fread(fid, 16, 'schar');
header.NumberOfImages          = fread(fid,  1, 'int32');
fclose(fid);

% vektor poradovych cisel obrazov v bin. subore
a_20 = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257,...
        258, 259, 260, 261, 262, 263, 264];
%     , 265, 266, 267, 268, 269, 270,...
%         271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 390, 391, 392,...
%         397, 398, 399];
% zaloha20 = [400, 401, 402, 403, 404, 405,...
%         406,407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418,...
%         419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430];
l_20 = length(a_20);
p_20 = 1; % pocitadlo na urcenie pozicie zapisu v cell array

for i = a_20
% for i = 1:header.NumberOfImages
    ImageRaw = frgread_surove(Adress4, i);
    if logaritmus10 == 1
        ImageRaw = log10(ImageRaw);
    end
    data{p_20,4} = ImageRaw;
    p_20 = p_20+1;
%     imshow(ImageRaw, [])
%     pause(0.1) % pomale prehliadanie obrazov 
%     pause
end

%% 2,5% gel, 5. stlpec;

% vektor poradovych cisel obrazov v bin. subore
fid = fopen(Adress5);
header.FileIdent               = fread(fid, 16, 'schar');
header.NumberOfImages          = fread(fid,  1, 'int32');
fclose(fid);

a_25 = [290, 291, 292, 293, 294, 295, 296, 297, 299, 300, 370, 371,...
        372, 373, 374, 375, 376, 377, 378, 379];
%     , 380, 381, 382, 383, 384,...
%         385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397,...
%         398, 399, 400, 401];
% zaloha25 = [402, 403, 404, 405, 406, 407];
l_25 = length(a_25);
p_25 = 1; % pocitadlo na urcenie pozicie zapisu v cell array

for i = a_25
% for i = 1:header.NumberOfImages
    ImageRaw = frgread_surove(Adress5, i);
    if logaritmus10 == 1
        ImageRaw = log10(ImageRaw);
    end
    data{p_25,5} = ImageRaw;
    p_25 = p_25+1;
%     imshow(ImageRaw, [])
%     pause(0.2) % pomale prehliadanie obrazov 
%     pause
end

%% 3,0% gel, 6. stlpec;

% vektor poradovych cisel obrazov v bin. subore
fid = fopen(Adress6);
header.FileIdent               = fread(fid, 16, 'schar');
header.NumberOfImages          = fread(fid,  1, 'int32');
fclose(fid);

a_30 = [295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307,...
        308, 309, 310, 311, 312, 313, 314];
%     , 315, 316, 317, 318, 319, 329,...
%         321, 322, 323, 324, 325, 326, 327, 328, 329 330, 331, 332, 333,...
%         334, 335, 336];
% zaloha30 =  [337, 338, 339, 340, 341, 342, 343, 344, 345, 346,...
%         347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359,...
%         360, 361, 362, 363, 364, 365, 366];

    
l_30 = length(a_30);
p_30 = 1; % pocitadlo na urcenie pozicie zapisu v cell array

for i = a_30
% for i = 1:header.NumberOfImages
    ImageRaw = frgread_surove(Adress6, i);
    if logaritmus10 == 1
        ImageRaw = log10(ImageRaw);
    end
    data{p_30,6} = ImageRaw;
    p_30 = p_30+1;
%     imshow(ImageRaw, [])
%     pause(0.05) % pomale prehliadanie obrazov 
%     pause
end

%% 3,5% gel, 7. stlpec;

% vektor poradovych cisel obrazov v bin. subore
fid = fopen(Adress7);
header.FileIdent               = fread(fid, 16, 'schar');
header.NumberOfImages          = fread(fid,  1, 'int32');
fclose(fid);

a_35 = [35, 36, 37, 38, 39, 40, 52, 53, 54, 55, 56, 62, 63, 64, 65, 66, 67,...
       68, 71, 72];
%    , 73, 74, 75, 76, 77, 78, 79, 80, 82, 100,...
%        107, 108, 109, 110, 117, 133, 134, 135, 136, 137, 138, 139];
% zaloha25 = [140, 141, 142, 147, 148, 149, 150, 151, 152, 158, 159, 160,...
%             161, 162, 248, 255, 256, 275, 277, 278, 293, 294, 295, 296, 297, 298];
l_35 = length(a_35);
p_35 = 1; % pocitadlo na urcenie pozicie zapisu v cell array

for i = a_35
% for i = 1:header.NumberOfImages
    ImageRaw = frgread_surove(Adress7, i);
    if logaritmus10 == 1
        ImageRaw = log10(ImageRaw);
    end
    data{p_35,7} = ImageRaw;
    p_35 = p_35+1;
%     imshow(ImageRaw, [])
%     pause(0.05) % pomale prehliadanie obrazov 
%     pause
end

%% uloženie databázy vybraných obrazov
if logaritmus10 == 1
    save('databaza_obr_oct_agaroza_gel_log_10.mat','data')
else
    save('databaza_obr_oct_agaroza_gel_surove.mat','data') 
end
