예제 #1
0
 def OnLoadImage(self, im_file):
     self.path = im_file
     print('self.path=', self.path)
     # read 3d image
     h, self.vol = edf_read(im_file, header_size=0, verbose=True, \
                            autoparse_filename=True, return_header=True)
     print('min in image= %d, max in image=%d' %
           (np.min(self.vol), np.max(self.vol)))
     self.maxim_sc.SetRange(0, np.shape(self.vol)[2] - 1)
     print(np.shape(self.vol))
     self.imPanel.SetImage(self.vol[:, :, 0])
예제 #2
0
 def load_image(self, image_path):
     print('loading image from %s' % image_path)
     # read image depending on file extension
     if image_path.endswith('.edf'):
         image = edf_read(image_path).transpose()
     elif image_path.endswith('.png'):
         image = mpimg.imread(image_path)
     elif image_path.endswith('.tif'):
         image = TiffFile(image_path).asarray()  # should we transpose here?
     else:
         print('Only png, tif and edf images are supported for the moment')
         image = np.zeros((5, 5), dtype=np.uint8)  # dummy image
     return image
예제 #3
0
 def OnLoadImage(self, im_file):
     self.path = im_file
     print 'self.path=', self.path
     # read image depending on file extension (only .png .tif and .edf supported)
     if self.path.endswith('.edf'):
         self.im = edf_read(im_file).transpose()
     elif self.path.endswith('.png'):
         self.im = mpimg.imread(im_file)
     elif self.path.endswith('.tif'):
         self.im = TiffFile(im_file).asarray()
     else:
         print('Only png, tif and edf images are supported for the moment')
         sys.exit(1)
     print 'min in image= %d, max in image=%d' % (np.min(
         self.im), np.max(self.im))
     print np.shape(self.im)
     self.cur_image_name.SetLabel(im_file)
     self.imPanel.SetImage(self.im)
예제 #4
0
def tt_stack(scan_name,
             data_dir='.',
             save_edf=False,
             TOPO_N=-1,
             dark_factor=1.):
    """Build a topotomography stack from raw detector images.

    The number of image to sum for a topograph can be determined automatically from the total number of images present
    in `data_dir` or directly specified using the variable `TOPO_N`.

    :param str scan_name: the name of the scan to process.
    :param str data_dir: the path to the data folder.
    :param bool save_edf: flag to save the tt stack as an EDF file.
    :param int TOPO_N: the number of images to sum for a topograph.
    :param float dark_factor: a multiplicative factor for the dark image.
    """
    from pymicro.file.file_utils import edf_read, edf_write
    if TOPO_N < 0:
        import glob
        # figure out the number of frames per topograph TOPO_N
        n_frames = len(
            glob.glob(os.path.join(data_dir, scan_name,
                                   '%s*.edf' % scan_name)))
        TOPO_N = int(n_frames / 90)
    print('number of frames to sum for a topograph = %d' % TOPO_N)

    # parse the info file
    f = open(os.path.join(data_dir, scan_name, '%s.info' % scan_name))
    infos = dict()
    for line in f.readlines():
        tokens = line.split('=')
        # convert the value into int/float/str depending on the case
        try:
            value = int(tokens[1].strip())
        except ValueError:
            try:
                value = float(tokens[1].strip())
            except ValueError:
                value = tokens[1].strip()
        infos[tokens[0]] = value
    print(infos)

    # load dark image
    dark = dark_factor * edf_read(
        os.path.join(data_dir, scan_name, 'darkend0000.edf'))

    # build the stack by combining individual images
    tt_stack = np.empty((infos['TOMO_N'], infos['Dim_1'], infos['Dim_2']))
    print(tt_stack[0].shape)
    for n in range(int(infos['TOMO_N'])):
        print('building topograph %d' % (n + 1))
        topograph = np.zeros((infos['Dim_1'], infos['Dim_2']))
        offset = TOPO_N * n
        for i in range(TOPO_N):
            index = offset + i + 1
            frame_path = os.path.join(data_dir, scan_name,
                                      '%s%04d.edf' % (scan_name, index))
            im = edf_read(frame_path) - dark
            topograph += im
        tt_stack[n] = topograph
    tt_stack = tt_stack.transpose((1, 2, 0))
    print('done')

    # save the data as edf if needed
    if save_edf:
        edf_write(tt_stack, os.path.join(data_dir, '%sstack.edf' % scan_name))
    return tt_stack