def update_image_queue(self, img_dict):  #hardware_mode do this
     # QApplication.processEvents()
     plot_win = self.img_queue.plot_wins.get()
     plot_win.img_plot(img_dict)
     img_name2 = (plot_win.img_label)[0:24].replace(' ', '_').replace(
         ':', '').replace('-', '').replace('.', '_')
     self.img_queue.plot_wins.put(plot_win)
     print("update image queue")
     if settings.widget_params["Analyse Data Setting"][
             "autoStatus"] == True:
         QApplication.processEvents()
         fpath = IOHelper.get_config_setting('DATA_PATH')
         fpath = Path(fpath)
         dir_path = fpath
         # dir_path = fpath.joinpath(str(datetime.datetime.now())[2:].split('.')[0].replace(' ', '').replace(':', '_'))
         if settings.m_path != []:
             dir_path = settings.m_path
         if not dir_path.exists():
             dir_path.mkdir()
         img_data = np.array(img_dict['img_data'])
         # load image name by path
         # img_name2 = (self.img_label)[0:20].replace(' ', '~').replace(':', '').replace('-', '')
         img_name = str(img_name2)
         img_data = img_data[::-1]
         from numpy import savetxt
         savetxt(r"{}\{}.data".format(dir_path, img_name),
                 img_data,
                 fmt='%.2e',
                 delimiter=' ',
                 newline='\n',
                 header='',
                 footer='',
                 comments=' ',
                 encoding=None)
         print("save images to {}".format(dir_path))
 def Mainwindowfile_save_imgs(self):
     # try:
     if self.plot_main_window.img.image is None:
         print("have no image in Mainwindow")
         return
     fpath = IOHelper.get_config_setting('DATA_PATH')
     fpath = Path(fpath)
     dir_path = fpath
     # dir_path = fpath.joinpath(str(datetime.datetime.now())[2:].split('.')[0].replace(' ', '-').replace(':', '_'))
     # print("save images to {}".format(dir_path))
     if settings.m_path != []:
         dir_path = settings.m_path
     if not dir_path.exists():
         dir_path.mkdir()
     img_data = np.array(self.plot_main_window.img.image)
     # load image name by path
     img_name2 = (self.plot_main_window.img_label.text())[0:24].replace(
         ' ', '_').replace(':', '').replace('-', '').replace('.', '_')
     img_name = str(img_name2)
     img_data = img_data[::-1]
     # img_data = Image.fromarray(img_data)
     # img_data.save(r"{}\{}.png".format(dir_path, img_name))
     import numpy
     numpy.savetxt(r"{}\{}.data".format(dir_path, img_name),
                   img_data,
                   fmt='%.2e',
                   delimiter=' ',
                   newline='\n',
                   header='',
                   footer='',
                   comments=' ',
                   encoding=None)
     print("save images to {}".format(dir_path))
 def save_image(self):
     try:
         if self.video.image is None:
             print("have no image in window")
             return
         fpath = IOHelper.get_config_setting('DATA_PATH')
         fpath = Path(fpath)
         dir_path = fpath.joinpath(
             str(datetime.datetime.now()).split('.')[0].replace(
                 ' ', '-').replace(':', '_'))
         # print("save images to {}".format(dir_path))
         if not dir_path.exists():
             dir_path.mkdir()
             img_data = np.array(self.video.image)
             # load image name by path
             img_name1 = settings.widget_params["Analyse Data Setting"][
                 "Prefix"]
             img_name2 = (self.img_label.text())[0:20].replace(
                 ' ', '~').replace(':', '').replace('-', '')
             img_name = str(img_name1) + str(img_name2)
             img_data = img_data[::-1]
             img_data = Image.fromarray(img_data)
             img_data.save(r"{}\{}.png".format(dir_path, img_name))
         print("save images to {}".format(dir_path))
         # print("images have saved.")
     except OSError:
         print('Only new version files can be saved.')
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            try:
                fpath = IOHelper.get_config_setting('DATA_PATH')

                img_fpath = QFileDialog.getOpenFileName(
                    self, "Open File", fpath)  # name path
                strimg_fpath = str(img_fpath)
                img_file = strimg_fpath[2:len(strimg_fpath) - 19]
                img_path = Path(img_file)

                file = open(img_path)
                linescontent = file.readlines(
                )  # Read the file as a behavior unit
                rows = len(linescontent)  # get the numbers fo line
                lines = len(linescontent[0].strip().split(' '))
                img_data = np.zeros((rows, lines))  # Initialization matrix
                row = 0
                for line in linescontent:
                    line = line.strip().split(' ')
                    img_data[row, :] = line[:]
                    row += 1
                file.close()

                img_data = img_data[::-1]
                img_name = img_path.stem
                img = {'img_name': img_name, 'img_data': img_data}
                settings.absimgDatas[self.myserial] = img_data

                self.img_plot(img)
            except TypeError:
                return
            except PermissionError:
                return
 def push2_state(self):
     fpath = IOHelper.get_config_setting('DATA_PATH')
     fpath = Path(fpath)
     dir_path = fpath.joinpath(
         str(datetime.datetime.now())[2:].split('.')[0].replace(
             ' ', '-').replace(':', '_'))
     # print("save images to {}".format(dir_path))
     if settings.m_path != []:
         dir_path = settings.m_path
     if not dir_path.exists():
         dir_path.mkdir()
     img_data = np.array(self.img.image)
     # load image name by path
     img_name = (self.img_labelt1.text())[0:20].replace(' ', '~').replace(
         ':', '_').replace('-', '')
     img_data = img_data[::-1]
     import numpy
     numpy.savetxt(r"{}\{}.ndata".format(dir_path, img_name),
                   img_data,
                   fmt='%.2e',
                   delimiter=' ',
                   newline='\n',
                   header='',
                   footer='',
                   comments=' ',
                   encoding=None)
     print("save images to {}".format(dir_path))
Exemple #6
0
 def load_img2stack(self):
     """
     load images to image queue, with image name and data
     """
     settings.widget_params["Image Display Setting"]["imgSource"] = "disk"
     fpath = IOHelper.get_config_setting('DATA_PATH')
     img_fpath = QFileDialog.getExistingDirectory(self, "Open File", fpath)
     img_file = Path(img_fpath)
     img_paths = list(img_file.glob('*.png'))
     for win_index in range(settings.widget_params["Image Display Setting"]["img_stack_num"]):
         if win_index == len(img_paths):
             break
         plot_win = self.img_queue.plot_wins.get()
         plot_win.img_plot(self.load_img_dict(img_paths[win_index]))
         self.img_queue.plot_wins.put(plot_win)
Exemple #7
0
 def save_image(self):
     if self.video.image is None:
         print("have no image in window")
         return
     fpath = IOHelper.get_config_setting('DATA_PATH')
     fpath = Path(fpath)
     dir_path = fpath.joinpath(
         str(datetime.datetime.now()).split('.')[0].replace(' ',
                                                            '-').replace(
                                                                ':', '_'))
     print("save images to {}".format(dir_path))
     if not dir_path.exists():
         dir_path.mkdir()
         img_data = np.array(self.video.image)
         # load image name by path
         img_name = (self.img_label.text()).split('.')[0].replace(
             ' ', '-').replace(':', '_')
         img_data = Image.fromarray(img_data)
         img_data.save(r"{}\{}.png".format(dir_path, img_name))
     print("images have saved.")
Exemple #8
0
 def file_save_imgs(self):
     """
     save image stack's images to disk
     :return:
     """
     fpath = IOHelper.get_config_setting('DATA_PATH')
     fpath = Path(fpath)
     dir_path = fpath.joinpath(str(datetime.datetime.now()).split('.')[0].replace(' ', '-').replace(':', '_'))
     print("save images to {}".format(dir_path))
     if not dir_path.exists():
         dir_path.mkdir()
     for i in range(settings.widget_params["Image Display Setting"]["img_stack_num"]):
         plot_win = self.img_queue.plot_wins.get()
         if plot_win.video.image is not None:
             img_data = np.array(plot_win.video.image)
             # load image name by path
             img_name = (plot_win.img_label.text()).split('.')[0].replace(' ', '-').replace(':', '_')
             img_data = Image.fromarray(img_data)
             img_data.save(r"{}\{}.png".format(dir_path, img_name))
         self.img_queue.plot_wins.put(plot_win)
     print("images have saved.")
 def file_save_imgs(self):
     """
     save image stack's images to disk
     :return:
     """
     # try:
     fpath = IOHelper.get_config_setting('DATA_PATH')
     fpath = Path(fpath)
     dir_path = fpath
     # dir_path = fpath.joinpath(str(datetime.datetime.now()).split('.')[0].replace(' ', '-').replace(':', '_'))
     # print("save images to {}".format(dir_path))
     if settings.m_path != []:
         dir_path = settings.m_path
     if not dir_path.exists():
         dir_path.mkdir()
     for i in range(settings.widget_params["Image Display Setting"]
                    ["img_stack_num"]):
         plot_win = self.img_queue.plot_wins.get()
         if plot_win.video.image is not None:
             img_data = np.array(plot_win.video.image)
             # load image name by path
             img_name2 = (plot_win.img_label)[0:24].replace(
                 ' ', '_').replace(':', '').replace('-',
                                                    '').replace('.', '_')
             img_name = str(img_name2)
             img_data = img_data[::-1]
             # img_data = Image.fromarray(img_data)
             # img_data.save(r"{}\{}.png".format(dir_path, img_name))
             import numpy
             numpy.savetxt(r"{}\{}.data".format(dir_path, img_name),
                           img_data,
                           fmt='%.2e',
                           delimiter=' ',
                           newline='\n',
                           header='',
                           footer='',
                           comments=' ',
                           encoding=None)
         self.img_queue.plot_wins.put(plot_win)
     print("save images to {}".format(dir_path))
    def file_load_imgs(self):
        """
        Load previous image to stack.
        :return:
        """
        settings.widget_params["Image Display Setting"]["imgSource"] = "disk"
        fpath = IOHelper.get_config_setting('DATA_PATH')

        img_fpath = QFileDialog.getOpenFileName(self, "Open File",
                                                fpath)  # name path
        strimg_fpath = str(img_fpath)
        img_file = strimg_fpath[2:len(strimg_fpath) - 19]
        img_file = Path(img_file)
        img_paths = img_file

        if img_fpath[0] != '':
            plot_win = self.img_queue.plot_wins.get()
            try:
                plot_win.img_plot(self.load_img_dict(img_paths))
                self.img_queue.plot_wins.put(plot_win)
            except TypeError:
                return
            except PermissionError:
                return