ParametersRun500;

dataset_positions = [{2,0}; {2,1}; {2,2}; {2,3}; {2,4}; {2,5}; {4,0}; {4,1}; {4,2}; {4,3}; {4,4}; {4,5}; {5,0}; {5,1}; {5,2}; {5,3}; {6,0}; {6,1}; {6,2}; {6,3}; {6,4}; {6,5}; {7,0}; {7,1}; {7,2}; {7,3}; {7,4}; {7,5}; {10,0}; {10,1}; {10,2}; {10,3}; {10,4}; {10,5}];

results_cb = zeros(size(dataset_positions,1),4);
num_points_cb = zeros(size(dataset_positions,1),3);

for i = 1:size(dataset_positions,1)
%     for i = 29:29
    dataset = dataset_positions{i,1};
    position = dataset_positions{i,2};
%     first_stack = calculated_stacks{dataset,position+1}(1);
    last_stack = stacks{dataset,position+1}(2);
    % this might need to be replaced with calculated stacks although very
    % unlikely, if some calculation goes down to first stack.  (calculated
    % stacks are the time point bounds held in calculated_params).
    
    if (dataset~= 2)&&(dataset~=4)
        moving_dataset_directory =  ['L:\seg2 5-31\Set ' num2str(dataset) '\Stacks\Position ' num2str(position) '\resized images'];
        ilastik_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(last_stack) '_Probabilities.h5'];
    else
        moving_dataset_directory =  ['K:\Laptop F drive copy\new reg 4-8 classifier 6-13-15\' num2str(dataset) '-' num2str(position)];
        ilastik_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(last_stack) '_Probabilities.h5'];
    end
    
    
    cd(moving_dataset_directory)
    image_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(last_stack)];
    
    input_stack = TiffStackImport(image_filename);
    
    input_stack_stretched = imwarp(input_stack,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
    
    cell_bodies_simple_cutoff = input_stack_stretched > 500;
    points_cell_bodies_simple = GeneratePoints(cell_bodies_simple_cutoff,optreg);
        
    h5input = h5read(ilastik_filename,'/exported_data');
    cell_bodies_ilastk = squeeze(h5input(4,:,:,:))>.5;
    cell_bodies_ilastik2 = imwarp(cell_bodies_ilastk,affine3d([0 1 0 0; 1 0 0 0; 0 0 1 0; 0 0 0 1]),'OutputView',imref3d([optreg.img_height optreg.img_width optreg.num_slices]));
    cell_bodies_ilastik_final = imwarp(cell_bodies_ilastik2,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
%     cell_bodies_ilastik_smoothed = smooth3(cell_bodies_ilastik_transformed,'gaussian',5,4)>0; 
        
    points_cell_bodies_ilastik = GeneratePoints(cell_bodies_ilastik_final,optreg);
    results_cb(i,1) = TestScoreCalculator(points_cell_bodies_simple,points_cell_bodies_ilastik);
    results_cb(i,2) = TestScoreCalculator(points_cell_bodies_ilastik,points_cell_bodies_simple);
    num_points_cb(i,1) = size(points_cell_bodies_simple,1);
    num_points_cb(i,2) = size(points_cell_bodies_ilastik,1);
    
end

    % total number of time points should be calculated by this procedure is
    % 31 (with the reference included).
    