Beispiel #1
0
 def test_get_block_image(self):
     chromosome1 = image_utils.read_image(
         data_dir + "/chromosome/1/xx_karyotype_001_0.bmp")
     chromosome2 = image_utils.read_image(
         data_dir + "/chromosome/1/xx_karyotype_001_1.bmp")
     image = image_utils.get_block_image([chromosome1, chromosome2], "1")
     image_utils.show_image(image)
Beispiel #2
0
def image_files_to_bounding_box_csv(image_files,
                                    labels,
                                    csv_dir,
                                    prefix="",
                                    verbose=False):
    general_utils.create_directory(csv_dir)

    boxes = list()
    for image_file in image_files:
        image = image_utils.read_image(image_file, cmap="rgb")
        box = image_utils.get_chromosome_bounding_box(image)
        boxes.append(box)

    train_data, val_data, test_data = data_utils.split_multiple_data_lists(
        [image_files, boxes, labels])

    annotations_train_file = csv_dir + "/" + prefix + "annotations_train.csv"
    image_and_bounding_boxes_to_csv(*train_data, annotations_train_file)

    annotations_val_file = csv_dir + "/" + prefix + "annotations_val.csv"
    image_and_bounding_boxes_to_csv(*val_data, annotations_val_file)

    annotations_test_file = csv_dir + "/" + prefix + "annotations_test.csv"
    image_and_bounding_boxes_to_csv(*test_data, annotations_test_file)

    class_mapping = [[str(i), i] for i in range(len(labels))]
    class_mapping_file = csv_dir + "/" + prefix + "class_mapping.csv"
    general_utils.write_list_to_csv(class_mapping, class_mapping_file)

    if verbose:
        print("Train: ", annotations_train_file)
        print("Validation: ", annotations_val_file)
        print("Test: ", annotations_test_file)
        print("Class mapping:", class_mapping_file)
Beispiel #3
0
def images_and_centers_to_csv(image_files,
                              points_list,
                              annotations_file,
                              class_mapping_file,
                              window_radius=1):
    temp_image = image_utils.read_image(image_files[0], 0)
    image_shape = temp_image.shape[0]

    center_points = [[
        int(points[0][0] * image_shape),
        int(points[0][1] * image_shape)
    ] for points in points_list]
    rect_center_points = [[
        x - window_radius, y - window_radius, x + window_radius,
        y + window_radius
    ] for x, y in center_points]

    annotations = [[
        image_files[idx], rect_center_points[idx][0],
        rect_center_points[idx][1], rect_center_points[idx][2],
        rect_center_points[idx][3], "center"
    ] for idx in range(len(image_files))]

    class_mapping = [["center", 0]]

    general_utils.write_list_to_csv(annotations, annotations_file)
    general_utils.write_list_to_csv(class_mapping, class_mapping_file)
Beispiel #4
0
 def test_rewrite_image(self):
     idx = 12
     image = image_utils.read_image(
         "/home/lntk/Desktop/Karyotype/data/pipeline/karyotype_" +
         str(idx) + ".bmp")
     cv2.imwrite(
         "/home/lntk/Desktop/Karyotype/data/pipeline/karyotype_" +
         str(idx) + "_clone.bmp", image)
Beispiel #5
0
    def _on_file_drop(self, window, file_path):
        print("Dropping file ...")
        if self.collide_point(*self.mouse_pos):
            filePath = file_path.decode("utf-8")
            if self.debug:
                print(file_path)
            self.image.source = filePath
            self.image.reload()

            self.source = filePath
            if self.data is not None:
                self.data["image"] = image_utils.read_image(filePath)
                print(self.data["image"].shape)
Beispiel #6
0
    def test_generate_chromosome_cluster(self):
        image_dir = data_dir + "/chromosome/1"
        image_files = general_utils.get_all_files(image_dir)
        num_chromosome = 15
        contours = list()

        chromosomes = list()
        chosen_files = list()

        # error_case = ['/home/lntk/Desktop/Karyotype/data/chromosome/1/xx_karyotype_225_0.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xy_karyotype_213_1.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xy_karyotype_190_1.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xx_karyotype_064_0.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xx_karyotype_017_0.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xy_karyotype_055_0.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xy_karyotype_208_0.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xy_karyotype_266_1.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xy_karyotype_132_0.bmp',
        #               '/home/lntk/Desktop/Karyotype/data/chromosome/1/xy_karyotype_233_1.bmp']

        for _ in range(num_chromosome):
            """ Randomly get chromosome image from directory """
            idx = np.random.randint(len(image_files))
            chromosome = image_utils.read_image(image_dir + "/" +
                                                image_files[idx])
            chosen_files.append(image_dir + "/" + image_files[idx])
            # for image_file in error_case:
            #     chromosome = image_utils.read_image(image_file)
            """ Resize """
            chromosome = cv2.resize(chromosome, (64, 64))
            """ Rotate """
            angle = np.random.randint(90)
            rotated_chromosome = image_utils.rotate_image(chromosome, angle)
            """ Extract contour """
            contour = image_utils.get_chromosome_contour(rotated_chromosome)
            contours.append(contour)

            chromosomes.append(rotated_chromosome)

        print(chosen_files)

        contours, boxes, initial_boxes = chromosome_utils.generate_chromosome_cluster(
            contours)

        for contour in contours:
            print(contour.shape)

        # silhouette_image = chromosome_utils.get_chromosome_silhouette(contours, boxes)
        cluster_image = chromosome_utils.get_chromosome_cluster_image(
            boxes, initial_boxes, chromosomes)
        image_utils.show_multiple_images([cluster_image])
Beispiel #7
0
def images_and_points_to_csv(image_files,
                             points_list,
                             annotations_file,
                             class_mapping_file,
                             window_radius=1):
    num_point = 6
    temp_image = image_utils.read_image(image_files[0], 0)
    image_shape = temp_image.shape[0]

    points = [list() for _ in range(num_point)]
    rect_points = [list() for _ in range(num_point)]
    for i in range(num_point):
        points[i] = [[
            int(points[i][0] * image_shape),
            int(points[i][1] * image_shape)
        ] for points in points_list]
        rect_points[i] = [[
            x - window_radius, y - window_radius, x + window_radius,
            y + window_radius
        ] for x, y in points[i]]

    annotations = list()
    for image_id in range(len(image_files)):
        for point_id in range(6):
            annotations.append([
                image_files[image_id], rect_points[point_id][image_id][0],
                rect_points[point_id][image_id][1],
                rect_points[point_id][image_id][2],
                rect_points[point_id][image_id][3],
                str(point_id)
            ])

    class_mapping = [[str(i), i] for i in range(num_point)]

    general_utils.write_list_to_csv(annotations, annotations_file)
    general_utils.write_list_to_csv(class_mapping, class_mapping_file)
Beispiel #8
0
 def read_image(image_file):
     return image_utils.read_image(image_file)
Beispiel #9
0
 def test_remove_chromosomes(self):
     image = image_utils.read_image(data_dir + "/test/karyotyping_1.bmp")
     image = data_utils.remove_chromosomes(image)
     cv2.imwrite(data_dir + "/test/karyotyping_frame.bmp", image)