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_neurites = zeros(size(dataset_positions,1),4);
num_points_neurites = zeros(size(dataset_positions,1),3);

target_dataset_directory = 'L:\seg2 5-31\2-4 (cp from E drive 5-30)\Position 4\resized images';

do_target = true;


for i = 1:size(dataset_positions,1)
    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);

    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)];
    trace_filename = [image_filename ' neurite trace'];
    do_smoothing = true;
    do_output = true;
    [neurites_combined,neurite_points,run_length] = TrakEM2_XML_extractor(trace_filename,do_smoothing,do_output);
    
    %CleanTrakem2Points;  this program is for calculating lengths of the
    %original thing and fitting to splines.
    
    
    neurites_combined2 = imwarp(neurites_combined,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
    neurites_combined2 = neurites_combined2>0;
    neurites_points_trace_final = GeneratePoints(neurites_combined2,optreg);
    
    
    h5input = h5read(ilastik_filename,'/exported_data');
    neurites_unspecial = squeeze(h5input(5,:,:,:))>.5;
    neurites_unspecial2 = imwarp(neurites_unspecial,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]));
    neurites_unspecial_stretched = imwarp(neurites_unspecial2,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
%     neurites_unspecial_smoothed = smooth3(neurites_unspecial_stretched,'gaussian',5,4)>0;
    neurites_unspecial_points_final = GeneratePoints(neurites_unspecial_stretched,optreg);
    
%     ilastik_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(last_stack) '_Probabilities_neuritesfinal.h5'];
%     h5input = h5read(ilastik_filename,'/exported_data');
%     neurites_special = squeeze(h5input(5,:,:,:))>.5;
%     neurites_special2 = imwarp(neurites_special,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]));
%     neurites_special_stretched = imwarp(neurites_special2,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
%     neurites_special_smoothed = smooth3(neurites_special_stretched,'gaussian',5,4)>0;
%     neurites_special_points_final = GeneratePoints(neurites_special_smoothed,optreg);
    
    results_neurites(i,1) = TestScoreCalculator(neurites_points_trace_final,neurites_unspecial_points_final);
    results_neurites(i,2) = TestScoreCalculator(neurites_unspecial_points_final,neurites_points_trace_final);
%     results_neurites(i,3) = TestScoreCalculator(neurites_points_trace_smoothed,neurites_special_points_final);
%     results_neurites(i,4) = TestScoreCalculator(neurites_special_points_final,neurites_points_trace_smoothed);
    num_points_neurites(i,1) = size(neurites_points_trace_final,1);
    num_points_neurites(i,2) = size(neurites_unspecial_points_final,1);
%     num_points_neurites(i,3) = size(neurites_points_trace_smoothed,1);
%     num_points_neurites(i,4) = size(neurites_special_points_final,1);
    
end

% if do_target
%     dataset= 2;
%     position = 4;
% %     first_stack = calculated_stacks{dataset,position+1}(1);
%     last_stack = 89;
%     % 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'];
% %     elseif dataset==2
% %         moving_dataset_directory =  ['K:\Laptop F drive copy\new reg 4-8 classifier 6-13-15\Set ' num2str(dataset) '\Stacks\Position ' num2str(position)];
% %     end
%     
%     cd(target_dataset_directory)
% 
%     image_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(last_stack)];
%     trace_filename = [image_filename ' neurite trace'];
%     do_smoothing = true;
%     do_output = true;
%     [neurites_combined,neurite_points,run_length] = TrakEM2_XML_extractor(trace_filename,do_smoothing,do_output);
%     
%     %CleanTrakem2Points;  this program is for calculating lengths of the
%     %original thing and fitting to splines.
%     
%     
%     neurites_combined2 = imwarp(neurites_combined,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
%     neurites_combined2 = neurites_combined2>0;
%     neurites_points_trace_final = GeneratePoints(neurites_combined2,optreg);
%     
%     
%     ilastik_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(last_stack) '_Probabilities.h5'];
%     h5input = h5read(ilastik_filename,'/exported_data');
%     neurites_unspecial = squeeze(h5input(5,:,:,:))>.5;
%     neurites_unspecial2 = imwarp(neurites_unspecial,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]));
%     neurites_unspecial_stretched = imwarp(neurites_unspecial2,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
% %     neurites_unspecial_smoothed = smooth3(neurites_unspecial_stretched,'gaussian',5,4)>0;
%     neurites_unspecial_points_final = GeneratePoints(neurites_unspecial_stretched,optreg);
%     
% %     ilastik_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(last_stack) '_Probabilities_neuritesfinal.h5'];
% %     h5input = h5read(ilastik_filename,'/exported_data');
% %     neurites_special = squeeze(h5input(5,:,:,:))>.5;
% %     neurites_special2 = imwarp(neurites_special,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]));
% %     neurites_special_stretched = imwarp(neurites_special2,affine3d([1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1]),'OutputView',imref3d(optreg.new_frame));
% %     neurites_special_smoothed = smooth3(neurites_special_stretched,'gaussian',5,4)>0;
% %     neurites_special_points_final = GeneratePoints(neurites_special_smoothed,optreg);
%     
%     results_neurites_target(1) = TestScoreCalculator(neurites_points_trace_final,neurites_unspecial_points_final);
%     results_neurites_target(2) = TestScoreCalculator(neurites_unspecial_points_final,neurites_points_trace_final);
% %     results_neurites(i,3) = TestScoreCalculator(neurites_points_trace_smoothed,neurites_special_points_final);
% %     results_neurites(i,4) = TestScoreCalculator(neurites_special_points_final,neurites_points_trace_smoothed);
%     num_points_neurites_target(1) = size(neurites_points_trace_final,1);
%     num_points_neurites_target(2) = size(neurites_unspecial_points_final,1);
% %     num_points_neurites(i,3) = size(neurites_points_trace_smoothed,1);
% %     num_points_neurites(i,4) = size(neurites_special_points_final,1);
% 
% end

moving_results = results_neurites(:,1:2)./num_points_neurites(:,1:2);
% target_results = results_neurites_target./num_points_neurites_target;
% total_results = [moving_results; target_results];

total_results = moving_results;

total_num = size(total_results,1);

% error_1 = std(total_results(:,1))/sqrt(total_num);
% error_2 = std(total_results(:,2))/sqrt(total_num);

error_1 = std(total_results(:,1));
error_2 = std(total_results(:,2));

mean_il_on_tr = mean(total_results(:,1));
mean_tr_on_il = mean(total_results(:,2));

figure
errorh = errorbar([1 2], [mean_tr_on_il mean_il_on_tr], [error_1 error_2],'o');
hold on;
scatterh = scatter([1 2], [mean_tr_on_il mean_il_on_tr],'ro');


errorh.Marker = 'none';
scatterh.SizeData = 16;
scatterh.MarkerFaceColor = 'red';

these_axes = gca;

axis([0 3 0 1]);

these_axes.XTick = [1 2];
these_axes.XTickLabel = {'% tr to il ov','% il to tr ov'};


these_axes.DataAspectRatio = [2.5 1 1]

MakeFont;

% these_axes.YTick = [0 100 200 300 400 500 600];
% these_axes.YTickLabel = {[0 100 200 300 400 500 600]};
