예제 #1
0
    def get_img(self):
        # Get frame size info
        height, width = self.dataset[0].shape[0], self.dataset[0].shape[1]

        # Make blank image to update
        avg_temp_img = np.zeros((height, width), dtype=np.float32)

        num_pixels = (height + 1) * (width + 1)

        if self.gui_instance is not None:
            self.gui_instance.create_progress_bar()

        cur_pix_num = 0
        for row_num, _ in enumerate(avg_temp_img):
            for col_num, _ in enumerate(avg_temp_img[row_num]):
                if self.gui_instance is not None:
                    self.gui_instance.update_progress_bar(
                        cur_pix_num, num_pixels)
                printProgressBar(cur_pix_num, num_pixels,
                                 'Generating avg temp composite...')
                avg_temp_img[row_num,
                             col_num] = np.mean(self.dataset[:, row_num,
                                                             col_num])
                cur_pix_num += 1

        if self.gui_instance is not None:
            self.gui_instance.remove_progress_bar()

        return avg_temp_img
예제 #2
0
    def save_video(self, framerate: int = 60):
        self.framerate = framerate
        # Generate the filename based on what frames are used
        filename = self.dataset.build_folder + 'video'
        if self.dataset.start_frame != 0 or self.dataset.end_frame != self.dataset.original_end_frame:
            filename += str(self.dataset.start_frame) + '-' + str(
                self.dataset.end_frame)

        filename += '.avi'

        # Generate a reference frame to get height and width
        ref_frame = self.generate_frame(self.dataset[0])
        height = ref_frame.shape[0]
        width = ref_frame.shape[1]
        video_writer = cv2.VideoWriter(
            filename, cv2.VideoWriter_fourcc('F', 'M', 'P', '4'), framerate,
            (width, height))

        for i, frame in enumerate(self.dataset):
            printProgressBar(i, self.dataset.shape[0] - 1, 'Saving Video...')
            generated_frame = self.generate_frame(frame)
            video_writer.write(generated_frame)

        video_writer.release()

        print('\nVideo saved as :', filename)
예제 #3
0
    def plotLine(self):

        pixelTempHistory = []
        frame = []

        for pixel in self.pixels:
            cur_pix_history = []
            cur_pix_frames = []
            for i, frame_data in enumerate(self.temp_data):
                printProgressBar(i + self.temp_data.start_frame,
                                 self.temp_data.end_frame,
                                 'Generating temp history plot.')
                cur_pix_frames.append(i + self.temp_data.start_frame)
                cur_pix_history.append(frame_data[pixel])
            pixelTempHistory.append(cur_pix_history)
            frame.append(cur_pix_frames)

        fig6, ax6 = plt.subplots()
        fig6.suptitle('Pixel {} Temperature History:\n'.format(self.pixels))
        ax6.set_xlabel('Frame')
        ax6.set_ylabel('Temperature')
        for history, frames, pixel in zip(pixelTempHistory, frame,
                                          self.pixels):
            ax6.plot(frames,
                     history,
                     label=str(pixel[1]) + ',' + str(pixel[0]))

        plt.legend()
예제 #4
0
    def get_img(self):
        # Get frame size info
        height, width = self.dataset[0].shape[0], self.dataset[0].shape[1]

        # Make blank image to update
        hotspot_img = np.zeros((height, width), dtype=np.float32)

        if self.gui_instance is not None:
            self.gui_instance.create_progress_bar()
        for i, frame in enumerate(self.dataset):
            if self.gui_instance is not None:
                self.gui_instance.update_progress_bar(
                    i, self.dataset.end_frame - 1)
            printProgressBar(i, self.dataset.end_frame - 1,
                             'Generating hotspot image...')
            max_temp = np.amax(frame)
            hotspot_img = np.where(frame == max_temp, max_temp, hotspot_img)

        if self.gui_instance is not None:
            self.gui_instance.remove_progress_bar()
        return hotspot_img
예제 #5
0
    def get_img(self):
        # Get frame size info
        height, width = self.dataset[0].shape[0], self.dataset[0].shape[1]

        # Make blank image to update
        max_temp_img = np.zeros((height, width), dtype=np.float32)

        if self.gui_instance is not None:
            self.gui_instance.create_progress_bar()

        for i, frame in enumerate(self.dataset):
            if self.gui_instance is not None:
                self.gui_instance.update_progress_bar(i,
                                                      self.dataset.end_frame)
            printProgressBar(i, self.dataset.end_frame,
                             'Creating max temp composite...')
            max_temp_img = np.maximum(max_temp_img, frame)

        if self.gui_instance is not None:
            self.gui_instance.remove_progress_bar()

        return max_temp_img
예제 #6
0
    def get_img(self):
        # Get frame size info
        height, width = self.dataset[0].shape[0], self.dataset[0].shape[1]

        # Make blank image to increment
        img = np.zeros((height, width), dtype=np.float32)

        if self.gui_instance is not None:
            self.gui_instance.create_progress_bar()

        for i, frame in enumerate(self.dataset):
            if self.gui_instance is not None:
                self.gui_instance.update_progress_bar(
                    i - self.dataset.start_frame,
                    self.dataset.end_frame - self.dataset.start_frame)
            printProgressBar(i - self.dataset.start_frame,
                             self.dataset.end_frame - self.dataset.start_frame,
                             "Generating threshold image...")
            img = np.where(frame > self.threshold, img + 1, img)

        if self.gui_instance is not None:
            self.gui_instance.remove_progress_bar()
        return img
예제 #7
0
    def get_img(self):
        # Get frame size info
        height, width = self.dataset[0].shape[0], self.dataset[0].shape[1]

        # Make blank image to update
        integration_img = np.zeros((height, width), dtype=np.float32)

        if self.gui_instance is not None:
            self.gui_instance.create_progress_bar()

        for i, frame in enumerate(self.dataset):
            if self.gui_instance is not None:
                self.gui_instance.update_progress_bar(
                    i, self.dataset.end_frame - 1)
            printProgressBar(i, self.dataset.end_frame - 1,
                             'Generating integration image...')
            integration_img = np.where(
                frame > self.threshold,
                integration_img + (frame - self.threshold), integration_img)

        if self.gui_instance is not None:
            self.gui_instance.remove_progress_bar()
        return integration_img
예제 #8
0
    def save_frame16(self, start: int, end=-1):
        # Save only one frame
        if end < 0:
            savename = self.dataset.build_folder + '/frame' + str(
                start) + '.png'
            plt.imsave(savename, self.dataset[start], cmap='inferno')
            print('Saved to: ' + savename)
        else:
            # Create folder to save frames in
            frame_range_folder = self.dataset.build_folder + '/frames' + str(
                start) + '-' + str(end - 1)

            if os.path.isdir(frame_range_folder):
                shutil.rmtree(frame_range_folder)
            os.mkdir(frame_range_folder)

            for i in range(start, end):
                printProgressBar(
                    i - start, end - start,
                    'Saving frame range ' + str(start) + '-' + str(end))
                savename = frame_range_folder + '/frame' + str(i) + '.png'
                plt.imsave(savename, self.dataset[i], cmap='inferno')
            print('Frame range saved in: ' + frame_range_folder)
예제 #9
0
    def gradientMath(self):

        if self.gui_instance is not None:
            self.gui_instance.create_progress_bar()

        for pixel in self.pixels:
            cur_pixel_x_mags = []
            cur_pixel_y_mags = []
            cur_pixel_mags = []
            cur_pixel_angles = []
            cur_pixel_temps = []
            cur_pixel_frames = []
            for i, frame in enumerate(self.temp_data):
                # Show progress bars
                printProgressBar(i, self.temp_data.end_frame)
                if self.gui_instance is not None:
                    self.gui_instance.update_progress_bar(
                        i, self.temp_data.end_frame)

                result_matrix = np.asmatrix(frame)

                # Retrieve image gradient data
                if frame[pixel] > self.threshold:
                    dy, dx = np.gradient(result_matrix)
                    x_dir = dx[pixel]
                    y_dir = dy[pixel]

                    # Magnitude Calculation
                    magnitude = math.sqrt((x_dir**2) + (y_dir**2))

                    # Angle Calculation
                    angle_rad = (np.arctan2(x_dir, y_dir) - (math.pi / 2)
                                 )  # shift -90 deg
                    angle_deg = (angle_rad * (180 / math.pi)
                                 )  # Convert to degrees

                    cur_pixel_x_mags.append(x_dir)
                    cur_pixel_y_mags.append(y_dir)
                    cur_pixel_mags.append(magnitude)
                    cur_pixel_angles.append(angle_deg)
                    cur_pixel_frames.append(i + self.temp_data.start_frame)
                    cur_pixel_temps.append(frame[pixel])

            if cur_pixel_frames:
                self.x_magnitude_array.append(cur_pixel_x_mags)
                self.y_magnitude_array.append(cur_pixel_y_mags)
                self.magnitude_array.append(cur_pixel_mags)
                self.angle_array.append(cur_pixel_angles)
                self.frames.append(cur_pixel_frames)
                self.temperatures_array.append(cur_pixel_temps)
                self.plotted_pixels.append(pixel)
        """
        for frame_index in range(self.frame_count):
            printProgressBar(frame_index, self.frame_count)
            if self.gui_instance is not None:
                self.gui_instance.update_progress_bar(frame_index,
                                                      self.frame_count)
            temp = self.data[frame_index + self.start_frame]
            result_matrix = np.asmatrix(temp)

            if temp[self.pixel] > self.threshold:
                dy, dx = np.gradient(
                    result_matrix)  # Retrieve image gradient data
                x_dir = dx[self.pixel]  # Pixel magnitude W.R.T. x-axis
                y_dir = dy[self.pixel]  # Pixel magnitude W.R.T. y-axis

                # Magnitude Calculation
                magnitude = math.sqrt((x_dir**2) + (y_dir**2))

                # Angle Calculation
                angle_rad = (np.arctan2(x_dir, y_dir) - (math.pi / 2)
                             )  # shift -90 deg
                angle_deg = (angle_rad * (180 / math.pi))  # Convert to degrees

                self.x_magnitude_array.append(
                    x_dir)  # store pixel x-direction for frame in array
                self.y_magnitude_array.append(
                    y_dir)  # store pixel y-direction for frame in array
                self.magnitude_array.append(
                    magnitude)  # store pixel magnitude for frame in array
                self.angle_array.append(
                    angle_deg)  # store pixel angle for frame in array
                self.temperatures_array.append(temp[self.pixel])
                self.frames.append(frame_index + self.start_frame)
        """

        if self.gui_instance is not None:
            self.gui_instance.remove_progress_bar()