def perform_max_z_creation(img_path_list, file_num,  sub_save_location, split_training_test):
    os.chdir(sub_save_location)
    sub_folder = "sequences"
    sequence_path = os.path.join(sub_save_location, sub_folder)
    os.mkdir(sequence_path)
    os.chdir(sequence_path)
    t, z, y_dim,x_dim, img = load_img(img_path_list[file_num])

    # txt_name_log = open(destination + "/name_log.txt", "a")
    # txt_name_log.write("{}, {}\n".format(new_folder_name, img_path_list[file_num]), )
    # txt_name_log.close()

    for t_num in tqdm(range(0,t)):
    #create new directory-path
      file_folder = "%02d" % (t_num+1)
      t_folder = os.path.join(sequence_path, file_folder)
      os.mkdir(t_folder)  
      os.chdir(t_folder)

      for z_num in range(0,z-2):
        slice_folder = "%04d" % (z_num+1)
        three_z_folder = os.path.join(t_folder, slice_folder)
        os.mkdir(three_z_folder)  
        os.chdir(three_z_folder)
        #add new folder to txt-file
        decision_train_test = random.random()
        if decision_train_test < split_training_test:
          txt_file_train = open(sub_save_location + "/tri_trainlist.txt", "a")
          txt_file_train.write("{}/{}\n".format(file_folder,slice_folder))
          txt_file_train.close()
        else:
          txt_file_test = open(sub_save_location + "/tri_testlist.txt", "a")
          txt_file_test.write("{}/{}\n".format(file_folder,slice_folder))
          txt_file_test.close()
          
        #converting images in rgb and uint8 to save it like that
        img_save_1 = reshape_data(img, "TZXY","XY", T=t_num, Z=z_num)
        img_save_1 = create_3D_image(img_save_1, x_dim, y_dim)
        img_save_1 = convert(img_save_1, 0, 255, np.uint8)
        img_save_2 = reshape_data(img, "TZXY","XY", T=t_num, Z=z_num+1)
        img_save_2 = create_3D_image(img_save_2, x_dim, y_dim)
        img_save_2 = convert(img_save_2, 0, 255, np.uint8)
        img_save_3 = reshape_data(img, "TZXY","XY", T=t_num, Z=z_num+2)
        img_save_3 = create_3D_image(img_save_3, x_dim, y_dim)
        img_save_3 = convert(img_save_3, 0, 255, np.uint8)

        with png_writer.PngWriter("im1.png") as writer2:
          writer2.save(img_save_1)
        with png_writer.PngWriter("im2.png") as writer2:
          writer2.save(img_save_2)
        with png_writer.PngWriter("im3.png") as writer2:
          writer2.save(img_save_3)
        print("{}/{}\n".format(file_folder,slice_folder))
def perform_prep_predict_t_creation(img_path_list, file_num,  sub_save_location):
    os.chdir(sub_save_location)
    t, z, y_dim,x_dim, img = load_img(img_path_list[file_num])
    folder_gt = str(file_num) + "_gt"
    folder_gt = os.path.join(sub_save_location,folder_gt)
    os.mkdir(folder_gt)
    folder_steps = str(file_num) + "_steps"
    folder_steps = os.path.join(sub_save_location,folder_steps)
    os.mkdir(folder_steps)

    # txt_name_log = open(destination + "/name_log.txt", "a")
    # txt_name_log.write("{}, {}\n".format(new_folder_name, img_path_list[file_num]), )
    # txt_name_log.close()

    images_jump =2
   #create new directory-path
    for z_num in tqdm(range(0,z)):
        for t_num in range(math.ceil(t/images_jump)-1):
        #create new directory-path
          file_folder = ("f_%03d" %(file_num)+"-" +"z_%03d"%(z_num) + "-"+"t_%03d" %(t_num))
          os.chdir(folder_gt)
          os.mkdir(file_folder)
          os.chdir(folder_steps)
          os.mkdir(file_folder)
          GT_path_folder = os.path.join(folder_gt, file_folder)
          steps_path_folder = os.path.join(folder_steps, file_folder)
          os.chdir(steps_path_folder)

          #here put the image pngs into the folder (instead of creating the folder)
          #convert image to unit8 otherwise warning
          first = t_num* images_jump
          second = t_num*images_jump+images_jump
          img_save_1 = reshape_data(img, "TZXY","XY", T=first, Z=z_num)
          img_save_1 = create_3D_image(img_save_1, x_dim, y_dim)
          img_save_1 = convert(img_save_1, 0, 255, np.uint8)

          img_save_3 = reshape_data(img, "TZXY","XY", T=second, Z=z_num)
          img_save_3 = create_3D_image(img_save_3, x_dim, y_dim)
          img_save_3 = convert(img_save_3, 0, 255, np.uint8)

          img_save_2 = reshape_data(img, "TZXY","XY", T=first+1, Z=z_num)
          img_save_2 = create_3D_image(img_save_2, x_dim, y_dim)
          img_save_2 = convert(img_save_2, 0, 255, np.uint8)

          # saving images as PNG
          with png_writer.PngWriter("im1.png") as writer1:
            writer1.save(img_save_1)
          with png_writer.PngWriter("im3.png") as writer2:
            writer2.save(img_save_3)

          os.chdir(GT_path_folder)
          with png_writer.PngWriter("im2.png") as writer2:
            writer2.save(img_save_2)
Exemplo n.º 3
0
def run_code_sample(filepath_list, destination, i, t):
    # create virtual number of files
    images_jump = 1
    print(filepath_list[i])
    txt_name_log = open(destination + "/name_log.txt", "a")
    txt_name_log.write("{}, {}\n".format(("%03d" % (t) + "-" + "%03d" % (i)),
                                         filepath_list[i]))
    txt_name_log.close()

    img = AICSImage(filepath_list[i])
    z_dim = img.shape[2]

    #dim for later for generating the image_3d files
    x_dim = img.shape[-2]
    y_dim = img.shape[-1]

    for j in range(z_dim - 1):
        #create new directory-path
        file_folder = ("%03d" % (t) + "-" + "%03d" % (i) + "-" + "%03d" % (j))

        os.chdir(destination)
        os.mkdir(file_folder)
        new_folder_path_2 = os.path.join(destination, file_folder)
        os.chdir(new_folder_path_2)

        #here put the image pngs into the folder (instead of creating the folder)
        #convert image to unit8 otherwise warning
        first = j * images_jump
        second = j * images_jump + images_jump
        if second <= z_dim - 1:  #*images_jump-images_jump:
            img_1 = img.get_image_data("YX", S=0, T=0, Z=0, C=first)
            img_1 = create_3D_image(img_1, x_dim, y_dim)
            img_1 = convert(img_1, 0, 255, np.uint8)

            img_2 = img.get_image_data("YX", S=0, T=0, Z=0, C=second)
            img_2 = create_3D_image(img_2, x_dim, y_dim)
            img_2 = convert(img_2, 0, 255, np.uint8)

            # saving images as PNG
            with png_writer.PngWriter("im1.png") as writer1:
                writer1.save(img_1)
            with png_writer.PngWriter("im3.png") as writer2:
                writer2.save(img_2)

    os.chdir(destination)
def upsample_z_creation(img_path_list, file_num, sub_save_location):
    os.chdir(sub_save_location)
    t, z, y_dim,x_dim, img = load_img(img_path_list[file_num])
    folder_steps = str(file_num) + "_steps"
    folder_steps = os.path.join(sub_save_location,folder_steps)
    os.mkdir(folder_steps)

    # txt_name_log = open(destination + "/name_log.txt", "a")
    # txt_name_log.write("{}, {}\n".format(new_folder_name, img_path_list[file_num]), )
    # txt_name_log.close()

    #create new directory-path
    for t_num in tqdm(range(0,t)):
        for z_num in range(z-1):
          #create new directory-path
          file_folder = ("f_%03d" %(file_num) + "-"+"t_%03d" %(t_num) +"-" +"z_%03d"%(z_num))
          os.chdir(folder_steps)
          os.mkdir(file_folder)
          steps_path_folder = os.path.join(folder_steps, file_folder)
          os.chdir(steps_path_folder)

          # #here put the image pngs into the folder (instead of creating the folder)
          # #convert image to unit8 otherwise warning
          img_save_1 = reshape_data(img, "TZXY","XY", T=t_num, Z=z_num)
          img_save_1 = create_3D_image(img_save_1, x_dim, y_dim)
          img_save_1 = convert(img_save_1, 0, 255, np.uint8)

          img_save_2 = reshape_data(img, "TZXY","XY", T=t_num, Z=z_num+1)
          img_save_2 = create_3D_image(img_save_2, x_dim, y_dim)
          img_save_2 = convert(img_save_2, 0, 255, np.uint8)

          # # saving images as PNG
          with png_writer.PngWriter("im1.png") as writer1:
            writer1.save(img_save_1)
          with png_writer.PngWriter("im3.png") as writer2:
            writer2.save(img_save_2)
Exemplo n.º 5
0
def run_create_training_T(filepath, destination, k, sequence_path,
                          split_training_test):
    # get file-path-list
    filepath_list = get_file_list_T(filepath)

    # create virtual number of files
    for i in range(0, len(filepath_list)):
        print(filepath_list[i - 1])
        # list_number_of_files.append(i)
        new_folder_name = ("%02d" % (k) + "-" + "%05d" % (i + 1))
        os.mkdir(new_folder_name)
        txt_name_log = open(destination + "/name_log.txt", "a")
        txt_name_log.write(
            "{}, {}\n".format(new_folder_name, filepath_list[i - 1]), )
        txt_name_log.close()
        img = AICSImage(filepath_list[i])
        z_dim = img.shape[2]
        #dim for later for generating the image_3d files
        x_dim = img.shape[-2]
        y_dim = img.shape[-1]

        #because the naming of the folders in the original also starts with 1 and -1 because i take always 3 so need to stop 2 before the end
        for j in range(0, z_dim - 1):
            #create new directory-path
            new_folder_path_1 = os.path.join(sequence_path, new_folder_name)
            os.chdir(new_folder_path_1)
            file_folder = "%04d" % (j + 1)
            os.mkdir(file_folder)
            #add new folder to txt-file
            decision_train_test = random.random()
            if decision_train_test < split_training_test:
                txt_file_train = open(destination + "/tri_trainlist.txt", "a")
                txt_file_train.write("{}/{}\n".format(new_folder_name,
                                                      file_folder))
                txt_file_train.close()
            else:
                txt_file_test = open(destination + "/tri_testlist.txt", "a")
                txt_file_test.write("{}/{}\n".format(new_folder_name,
                                                     file_folder))
                txt_file_test.close()
            new_folder_path_2 = os.path.join(new_folder_path_1, file_folder)
            os.chdir(new_folder_path_2)
            #here put the image pngs into the folder (instead of creating the folder)
            #convert image to unit8 otherwise warning
            img_1 = img.get_image_data("YX", S=0, T=0, C=j - 1, Z=0)
            img_1 = create_3D_image(img_1, x_dim, y_dim)
            img_1 = convert(img_1, 0, 255, np.uint8)
            img_2 = img.get_image_data("YX", S=0, T=0, C=j, Z=0)
            img_2 = create_3D_image(img_2, x_dim, y_dim)
            img_2 = convert(img_2, 0, 255, np.uint8)
            img_3 = img.get_image_data("YX", S=0, T=0, C=j + 1, Z=0)
            img_3 = create_3D_image(img_3, x_dim, y_dim)
            img_3 = convert(img_3, 0, 255, np.uint8)

            # saving images as PNG
            with png_writer.PngWriter("im1.png") as writer2:
                writer2.save(img_1)
            with png_writer.PngWriter("im2.png") as writer2:
                writer2.save(img_2)
            with png_writer.PngWriter("im3.png") as writer2:
                writer2.save(img_3)
        os.chdir(sequence_path)