def update_chromosome_orientation(self):
     rotate_image_object = rotate_image.RotateImage()
     compute_projection_vector_object = compute_projection_vector.ComputeProjectionVector(
     )
     rotate_image_object.rotate_image(self.img_path, self.current_angle)
     self.best_image_path = rotate_image_object.get_output_image_path()
     self.best_horizontal_projection_vector = \
         compute_projection_vector_object.get_horizontal_projection_vector(self.img_path)
     self.best_vertical_projection_vector = \
         compute_projection_vector_object.get_vertical_projection_vector(self.img_path)
     self.best_score = \
         self.get_orientation_score(self.best_horizontal_projection_vector, self.best_vertical_projection_vector)
     for self.current_angle in range(10, 180, 5):
         rotate_image_object.rotate_image(self.img_path, self.current_angle)
         rotated_image_path = rotate_image_object.get_output_image_path()
         horizontal_projection_vector = \
             compute_projection_vector_object.get_horizontal_projection_vector(rotated_image_path)
         vertical_projection_vector = \
             compute_projection_vector_object.get_vertical_projection_vector(rotated_image_path)
         score = self.get_orientation_score(horizontal_projection_vector,
                                            vertical_projection_vector)
         if score < self.best_score:
             self.best_horizontal_projection_vector = horizontal_projection_vector
             self.best_vertical_projection_vector = vertical_projection_vector
             self.best_score = score
             self.best_image_path = rotated_image_path
             self.best_angle = self.current_angle
Beispiel #2
0
 def handle_one_image(self, image_path, straighten=True):
     self.ready_dir = self.get_or_create_ready_dir(image_path)
     if self.check_if_curved.is_curved(image_path):
         for self.current_angle in range(0, 180, 5):
             rotate_image_obj = rotate_image.RotateImage()
             rotate_image_obj.rotate_image(image_path, self.current_angle)
             rotated_image_path = rotate_image_obj.get_output_image_path()
             compute_projection_vector_obj = compute_projection_vector.ComputeProjectionVector(
             )
             h_vector = compute_projection_vector_obj.get_horizontal_projection_vector(
                 rotated_image_path)
             score, min_position = self.__compute_horizontal_vector_score(
                 h_vector)
             if score < self.best_score:
                 self.best_score = score
                 self.best_angle = self.current_angle
                 self.best_min_position = min_position
                 self.best_image_path = rotated_image_path
         if straighten:
             self.straighten_curved_chromosome.straight_curved_chromosome(
                 self.best_image_path, self.best_min_position,
                 self.ready_dir)
         else:
             shutil.copy2(self.best_image_path, self.ready_dir)
         return True
     else:
         shutil.copy2(image_path, self.ready_dir)
         return False
Beispiel #3
0
 def straight_half_chromosome(self, img_path):
     rotate_image_object = rotate_image.RotateImage()
     compute_projection_vector_object = compute_projection_vector.ComputeProjectionVector(
     )
     best_angle = 0
     rotate_image_object.rotate_image(img_path, best_angle)
     best_image_path = rotate_image_object.get_output_image_path()
     best_horizontal_projection_vector = compute_projection_vector_object.get_horizontal_projection_vector(
         img_path)
     best_vertical_projection_vector = compute_projection_vector_object.get_vertical_projection_vector(
         img_path)
     best_score = self.get_orientation_score(
         best_horizontal_projection_vector, best_vertical_projection_vector)
     for current_angle in range(0, 180, 5):
         rotate_image_object.rotate_image(img_path, current_angle)
         rotated_image_path = rotate_image_object.get_output_image_path()
         horizontal_projection_vector = \
             compute_projection_vector_object.get_horizontal_projection_vector(rotated_image_path)
         vertical_projection_vector = \
             compute_projection_vector_object.get_vertical_projection_vector(rotated_image_path)
         score = self.get_orientation_score(horizontal_projection_vector,
                                            vertical_projection_vector)
         if score < best_score:
             best_score = score
             best_image_path = rotated_image_path
             best_angle = current_angle
     print("Best angle = %d" % best_angle)
     if best_score < math.inf:
         print("Best score = %d" % best_score)
     print("Best image path = %s" % best_image_path)
     return best_image_path, best_angle
Beispiel #4
0
 def __extract_short_chromatid_ratio_feature_old(self):
     for file in self.get_all_images():
         compute_projection_vector_obj = compute_projection_vector.ComputeProjectionVector(
         )
         h_vector = compute_projection_vector_obj.get_horizontal_projection_vector(
             file)
         min_position = self.__compute_horizontal_vector_score(h_vector)
         chromosome_len = self.features[file][CHROMOSOME_LEN_KEY]
         short_chromatid_len = min(min_position,
                                   chromosome_len - min_position)
         self.features[file][
             SHORT_CHROMATID_RATIO_KEY] = short_chromatid_len / chromosome_len
         self.features[file][CENTROMERE_POSITION_KEY] = min_position
Beispiel #5
0
 def is_curved(self, image_to_check_path):
     self.image_path = image_to_check_path
     image = common_operations.read_image(self.image_path)
     compute_projection_vector_obj = compute_projection_vector.ComputeProjectionVector(
     )
     h_vector = compute_projection_vector_obj.get_horizontal_projection_vector(
         self.image_path)
     ch_area = sum(h_vector)
     total_area = image.shape[0] * image.shape[1]
     proc = ch_area / total_area
     if proc < 0.6:
         return True
     return False
 def __compute_centromere_position(self):
     for self.current_angle in range(0, 180, 5):
         rotate_image_obj = rotate_image.RotateImage()
         rotate_image_obj.rotate_image(self.image_path, self.current_angle)
         rotated_image_path = rotate_image_obj.get_output_image_path()
         compute_projection_vector_obj = compute_projection_vector.ComputeProjectionVector(
         )
         h_vector = compute_projection_vector_obj.get_horizontal_projection_vector(
             rotated_image_path)
         score, min_position = self.__compute_horizontal_vector_score(
             h_vector)
         if score < self.best_score:
             self.best_score = score
             self.best_angle = self.current_angle
             self.best_min_position = min_position
             self.best_image_path = rotated_image_path
Beispiel #7
0
 def __init__(self):
     self.compute_projection_vector_obj = compute_projection_vector.ComputeProjectionVector(
     )