示例#1
0
    def select_best_frames(self):
        """
        For each quality area, rank all frames by their local image quality. For quality areas
        containing at least one alignment point, use their "local contrast" as the ranking
        criterion. For areas which do not contain any alignment point, copy the frame ranks from the
        nearest quality area with alignment points.

        The rationale for this differentiation is that areas without alignment points are either
        empty space or very smooth surface sections where the contrast measurement does not make
        much sense.

        :return: -
        """

        # Cycle through all frames. Use the monochrome image for frame ranking.
        for frame in self.frames.frames_mono:
            # Cycle through all quality areas:
            for index_y, quality_area_row in enumerate(self.quality_areas):
                for index_x, quality_area in enumerate(quality_area_row):
                    # If the alignment point list of the quality area is non-empty, compute the
                    # local contrast.
                    if quality_area['alignment_point_indices']:
                        [y_low, y_high, x_low, x_high] = quality_area['coordinates']
                        quality_area['frame_qualities'].append(
                            Miscellaneous.local_contrast(frame[y_low:y_high, x_low:x_high],
                                                         self.configuration.quality_area_pixel_stride))

        # For quality areas with alignment points, sort the computed quality ranks in descending
        # order.
        for index_y, quality_area_row in enumerate(self.quality_areas):
            for index_x, quality_area in enumerate(quality_area_row):
                if quality_area['alignment_point_indices']:
                    quality_area['best_frame_indices'] = [b[0] for b in sorted(
                        enumerate(quality_area['frame_qualities']), key=lambda i: i[1],
                        reverse=True)]

        # For quality areas without alignment points, use method "best_frame_indices_in_empty_areas"
        # to copy ranks from the nearest quality area with alignment points.
        for index_y, quality_area_row in enumerate(self.quality_areas):
            for index_x, quality_area in enumerate(quality_area_row):
                if not quality_area['alignment_point_indices']:
                    quality_area['best_frame_indices'] = self.best_frame_indices_in_empty_areas(
                        index_y, index_x)
示例#2
0
    def frame_score(self):
        """
        Compute the frame quality values and normalize them such that the best value is 1.

        :return: -
        """

        # For all frames compute the quality with method "local_contrast" in module "miscellaneous".
        for frame in self.frames_mono:
            self.frame_ranks.append(Miscellaneous.local_contrast(frame,
                self.configuration.frame_score_pixel_stride))
            # Ten times slower but twice as good:
            # self.frame_ranks.append(Miscellaneous.local_contrast_sobel(frame))


        # Sort the frame indices in descending order of quality.
        self.quality_sorted_indices = [b[0] for b in sorted(enumerate(self.frame_ranks),
                                                            key=lambda i: i[1], reverse=True)]

        # Set the index of the best frame, and normalize all quality values.
        self.frame_ranks_max_index = self.quality_sorted_indices[0]
        self.frame_ranks_max_value = self.frame_ranks[self.frame_ranks_max_index]
        self.frame_ranks /= self.frame_ranks_max_value