ParametersRun500

counter =0 ;

stretch_matrix = [1 0 0 0; 0 1 0 0; 0 0 3.077 0; 0 0 0 1];

target_dataset_directory = 'L:\seg2 5-31\2-4 (cp from E drive 5-30)\Position 4\resized images';
target_run_number = 500;
target_start_time = '15-Nov-2015 12.12.47';
target_position = 4;
target_dataset = 2;
first_target_stack = 20;
last_target_stack = 89;

moving_run_number = 500;


neur_seg_var = optreg.neurite_segmentation_variable;
cb_seg_var = optreg.cell_body_segmentation_variable;
nuclei_seg_var = optreg.nuclei_segmentation_variable;

new_num_slices = optreg.new_frame(3);

moving_run_number = 500;
for i = 1:size(dataset_positions,1)
    
    i
    
    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);
    
    
    moving_start_time = moving_start_times{dataset,position+1};
    moving_moments_time = moments_times{dataset,position+1};
    
    time_offset = time_offsets{dataset,position+1};
    
    
    first_target_stack = 20;
    if max(first_target_stack,last_stack+time_offset) > last_target_stack
        correct_target_stack = last_target_stack;
    else
        correct_target_stack = max(first_target_stack,last_stack+time_offset);
    end
    
    if (dataset == 4)&&(position == 5)
        last_stack = 92;
    elseif (dataset ==5)&&(position== 3)
        last_stack = 98;
    elseif (dataset == 6)&&(position == 3)
        last_stack = 80;
    elseif (dataset == 7)&&(position == 2)
        last_stack = 85;
    elseif (dataset == 10)&&(position == 1)
        last_stack = 104;
    elseif (dataset == 10)&&(position == 3)
        last_stack = 102;
    end
    
        
for this_stack = first_stack:last_stack
        counter =counter +1;
    
    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(this_stack) '_Probabilities.h5'];
    elseif (dataset ==2) && (position ==4)
        moving_dataset_directory = 'L:\seg2 5-31\2-4 (cp from E drive 5-30)\Position 4\resized images';
        ilastik_filename = ['Btc_Ds' num2str(dataset) '_Pos' num2str(position) '_Co0_St' num2str(this_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(this_stack) '_Probabilities.h5'];
    end
    
    cd([moving_dataset_directory '/Run 500'])
    
    if dataset==2 && position ==4
        load(['target transform matrix_' num2str(target_dataset) '_' num2str(target_position) '_r' num2str(target_run_number) '. ' target_start_time '.mat']);
    else
        load(['moving transform matrix_' num2str(dataset) '_' num2str(position) '_r' num2str(moving_run_number) '. ' moving_moments_time '.mat'])
        load(['reg params ' num2str(dataset) '_' num2str(position) '_r500 tar 2_4_r500. ' moving_start_time '.mat']);
        load(['calculated params ' num2str(dataset) '_' num2str(position) '_r500 tar 2_4_r500. ' moving_start_time '.mat']);
    end

    
    if dataset==2 && position==4
        is_moving = false;
    else
        is_moving = true;
    end
    
    num_nuclei(counter) = GetNucleiObjectscutcyl3CountsOnly(optreg,calculated_params, this_stack, is_moving,transform_matrix,false,false);
    end
end