dataset = 11;
read_prefix = '';
write_prefix = 'Btc_';
strain_name = 'NG_';
start_position = 0;
end_position = 5;

for position = start_position:end_position
    cd(['Position ' num2str(position) '/resized images'])

for i = 1:120
    green_filename = [read_prefix strain_name 'Ds' num2str(dataset) '_Pos' num2str(position) '_Co' num2str(0) '_St' num2str(i)];
    green_stack = TiffStackImport(green_filename);
    red_filename = [read_prefix strain_name 'Ds' num2str(dataset) '_Pos' num2str(position) '_Co' num2str(1) '_St' num2str(i)];
    red_stack = TiffStackImport(red_filename);
    finished_stack = uint16(green_stack - (red_stack-100)/15);
    output_filename = [write_prefix strain_name 'Ds' num2str(dataset) '_Pos' num2str(position) '_Co' num2str(0) '_St' num2str(i)];
    TiffStackWrite(finished_stack,output_filename,16);
    TiffStackMaxProjectCallable(finished_stack,[output_filename 'max project']);
end
cd ../..
end