function [nothing] = ComposeRegistrationsOther(optreg, stack_index, first_moving_stack,last_moving_stack,first_target_stack,last_target_stack)

color = 0;
prefix = optreg.input_prefix;
z_multiplier = optreg.z_multiplier;
new_frame = optreg.new_frame;

moving_strain_name = optreg.moving_strain_name;
target_strain_name = optreg.target_strain_name;

% compose_type = optreg.register_compose_type;

moving_dataset_directory = optreg.moving_dataset_directory;
moving_dataset = optreg.moving_dataset;
moving_position = optreg.moving_position;
moving_run_number = optreg.moving_run_number;
moving_moments_time = optreg.moving_moments_time;
moving_start_time = optreg.start_time;
register_moving_forward = optreg.register_moving_forward;


target_dataset_directory = optreg.target_dataset_directory;
target_dataset = optreg.target_dataset;
target_position = optreg.target_position;
target_run_number = optreg.target_run_number;
target_moments_time = optreg.target_moments_time;
target_start_time = optreg.target_start_time;
register_target_forward = optreg.register_target_forward;

cross_map_last_time_point = optreg.cross_map_last_time_point;

save_final_images = optreg.save_final_images;
save_final_images_head = optreg.save_final_images_head;

center_position = optreg.center_position;

first_target_filename = [prefix target_strain_name 'Ds' num2str(target_dataset) '_Pos' num2str(target_position) '_Co' num2str(color) '_St' num2str(first_target_stack)];
last_target_filename = [prefix target_strain_name 'Ds' num2str(target_dataset) '_Pos' num2str(target_position) '_Co' num2str(color) '_St' num2str(last_target_stack)];
first_moving_filename = [prefix moving_strain_name 'Ds' num2str(moving_dataset) '_Pos' num2str(moving_position) '_Co' num2str(color) '_St' num2str(first_moving_stack)];  
last_moving_filename = [prefix moving_strain_name 'Ds' num2str(moving_dataset) '_Pos' num2str(moving_position) '_Co' num2str(color) '_St' num2str(last_moving_stack)];

if register_moving_forward
    cd([moving_dataset_directory '/Run ' num2str(moving_run_number) '/SelfTransforms'])
    load(['composed cpd conjugate_' first_moving_filename ' al ' last_moving_filename '_r' num2str(moving_run_number) '. ' moving_start_time '.mat'],'composed_cpd_conjugate')
    reversing_transform_moving = inv(composed_cpd_conjugate);
end
    
moving_filename = [prefix moving_strain_name 'Ds' num2str(moving_dataset) '_Pos' num2str(moving_position) '_Co' num2str(color) '_St' num2str(stack_index)]

cd([moving_dataset_directory '/Run ' num2str(moving_run_number)])
load(['moving transform matrix_' moving_strain_name num2str(moving_dataset) '_' num2str(moving_position) '_r' num2str(moving_run_number) '. ' moving_moments_time '.mat'])
transform_matrix_moving = transform_matrix;



cd([moving_dataset_directory '/Run ' num2str(moving_run_number) '/SelfTransforms']);
if ~register_moving_forward
load(['composed cpd conjugate_' moving_filename ' al ' first_moving_filename '_r' num2str(moving_run_number) '. ' moving_start_time '.mat'],'composed_cpd_conjugate')
backward_transform = composed_cpd_conjugate;
else
load(['composed cpd conjugate_' moving_filename ' al ' last_moving_filename '_r' num2str(moving_run_number) '. ' moving_start_time '.mat'],'composed_cpd_conjugate')
backward_transform = composed_cpd_conjugate*reversing_transform_moving;
end


cd([moving_dataset_directory '/Run ' num2str(moving_run_number) '/CrossTransforms']);
load(['cpd transform conjugate_' first_moving_filename ' al ' first_target_filename '_r' num2str(moving_run_number) '. ' moving_start_time '.mat'],'cpd_transform_conjugate')
cross_transform = cpd_transform_conjugate;



cd([target_dataset_directory '/Run ' num2str(target_run_number) '/SelfTransforms']);
if register_target_forward
load(['composed cpd conjugate_' first_target_filename ' al ' last_target_filename '_r' num2str(target_run_number) '. ' target_start_time '.mat'],'composed_cpd_conjugate')
forward_transform = composed_cpd_conjugate;
else
load(['composed cpd conjugate_' last_target_filename ' al ' first_target_filename '_r' num2str(target_run_number) '. ' target_start_time '.mat'],'composed_cpd_conjugate')
forward_transform = inv(composed_cpd_conjugate);
end

% this should be changed so that the cross transform is not saved with the
% stretch matrix?

stretch_matrix = [1 0 0 0; 0 1 0 0 ; 0 0 z_multiplier 0; 0 0 0 1];
full_transform_first = stretch_matrix.'*transform_matrix_moving.'*backward_transform;
full_transform_second = cross_transform;

if cross_map_last_time_point
    full_transform_third = forward_transform;
else
    full_transform_third = eye(4);
end

complete_cross_transform = full_transform_first*full_transform_second*full_transform_third

% required because level of precision of matlab inverse operation not as high as
% level of precision with which affine3d demands last column be 0s and then
% 1
complete_cross_transform(1:3,4) = 0; complete_cross_transform(4,4) = 1;

if save_final_images
    cd(moving_dataset_directory)
    input_stack = TiffStackImport(moving_filename);
    cd([moving_dataset_directory '/Run ' num2str(moving_run_number) '/CrossRegIms'])
    output_stack = imwarp(input_stack,affine3d(complete_cross_transform),'OutputView',imref3d(new_frame));
    if cross_map_last_time_point
    TiffStackWrite(output_stack,['indirect cross ' moving_filename ' al ' last_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. main pos ' moving_start_time],16);
    max_project_filename = ['indirect cross ' moving_filename ' al ' last_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. main pos max project ' moving_start_time];
    TiffStackMaxProjectCallable(output_stack,max_project_filename);
    else
    TiffStackWrite(output_stack,['indirect cross ' moving_filename ' al ' first_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. main pos ' moving_start_time],16);
    max_project_filename = ['indirect cross ' moving_filename ' al ' first_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. main pos ' moving_start_time];
    TiffstackMaxProjectCallable(output_stack,max_project_filename);
    end
end


if save_final_images_head
    first_translation = -center_position;
    first_transform = [1 0 0 0; 0 1 0 0; 0 0 1 0; [first_translation 1]];
    on_head_matrix = [0 0 1 0; 0 1 0 0; -1 0 0 0; 0 0 0 1];
    on_side_matrix = [1 0 0 0; 0 0 -1 0; 0 1 0 0; 0 0 0 1];
    second_translation = center_position;
    second_transform = [1 0 0 0; 0 1 0 0; 0 0 1 0; [second_translation 1]];
    full_on_head_transform = complete_cross_transform*first_transform*on_head_matrix*second_transform;
    
    cd(moving_dataset_directory)
    input_stack = TiffStackImport(moving_filename);
    cd([moving_dataset_directory '/Run ' num2str(moving_run_number) '/CrossRegIms'])
    output_stack = imwarp(input_stack,affine3d(full_on_head_transform),'OutputView',imref3d(new_frame)); 
    if cross_map_last_time_point
        TiffStackWrite(output_stack,['indirect cross ' moving_filename ' al ' last_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. on head ' moving_start_time],16);
        max_project_filename = ['indirect cross ' moving_filename ' al ' last_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. on head max project ' moving_start_time];
        TiffStackMaxProjectCallable(output_stack,max_project_filename);
    else
        TiffStackWrite(output_stack,['indirect cross ' moving_filename ' al ' first_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. on head ' moving_start_time],16);
        max_project_filename = ['indirect cross ' moving_filename ' al ' first_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. on head max project ' moving_start_time];
        TiffStackMaxProjectCallable(output_stack,max_project_filename);
    end

    full_on_side_transform = complete_cross_transform*first_transform*on_side_matrix*second_transform;
    
    cd([moving_dataset_directory '/Run ' num2str(moving_run_number) '/CrossRegIms'])
    output_stack = imwarp(input_stack,affine3d(full_on_side_transform),'OutputView',imref3d(new_frame)); 
    if cross_map_last_time_point
        TiffStackWrite(output_stack,['indirect cross ' moving_filename ' al ' last_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. side rot ' moving_start_time],16);
        max_project_filename = ['indirect cross ' moving_filename ' al ' last_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. side rot max project ' moving_start_time];
        TiffStackMaxProjectCallable(output_stack,max_project_filename);
    else
        TiffStackWrite(output_stack,['indirect cross ' moving_filename ' al ' first_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. side rot ' moving_start_time],16);
        max_project_filename = ['indirect cross ' moving_filename ' al ' first_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. side rot max project ' moving_start_time];
        TiffStackMaxProjectCallable(output_stack,max_project_filename);
    end
    

end

nothing = 'lalala';
% requires output so the multicore stuff doesn't break

cd([moving_dataset_directory '/Run ' num2str(moving_run_number) '/CrossTransforms'])
save(['complete cross transform_' moving_filename ' al ' last_target_filename '_rm' num2str(moving_run_number) '_rt' num2str(target_run_number) '. ' moving_start_time '.mat'],'complete_cross_transform')
