コード例 #1
0
def read_image_sequence(data_dir, prefix, num_images, start_index=0, image_format='png', zero_padding=0, crop=None, verbose=False):
    '''Read a series of images into a list of numpy arrays.
    
    :param str data_dir: directory where the image files are located.
    :param str prefix: a string to construct the image file names.
    :param int num_images: the number of images to read.
    :param int start_index: the index to start loading the images (0 by default).
    :param str image_format: can be tif or png (png by default).
    :param int zero_padding: number of zero to use in zero padding (0 by default).
    :param list crop: bounds to crop the images (None by default) 
    :param bool verbose: activate verbose mode (False by default).
    :return: the list of the images read from the disk.
    '''
    # build the numbering pattern
    pat = '0%dd' % zero_padding
    fmt = '{0:s}{1:' + pat + '}.{2:s}'
    image_stack = []
    if image_format == 'tif':
        from pymicro.external.tifffile import TiffFile
    elif image_format == 'png':
        from matplotlib import pyplot as plt
    for i in range(start_index, start_index + num_images):
        image_path = os.path.join(data_dir, fmt.format(prefix, i, image_format))
        if verbose:
            print('loading image %s' % image_path)
        if image_format == 'tif':
            im = TiffFile(image_path).asarray()
        elif image_format == 'png':
            im = (np.mean(plt.imread(image_path)[:, :, :3], axis=2) * 255).astype(np.uint8)
        if crop:
            im = im[crop[2]:crop[3], crop[0]:crop[1]]
        image_stack.append(im.T)
    return image_stack
コード例 #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 load_image(self, image_path):
     print('loading image %s' % image_path)
     self.image_path = image_path
     if image_path.endswith('.tif'):
         self.data = TiffFile(image_path).asarray().T.astype(np.float32)
     elif image_path.endswith('.raw'):
         self.data = HST_read(self.image_path, data_type=self.data_type,
                              dims=(self.get_size_px()[0], self.get_size_px()[1], 1))[:, :, 0].astype(np.float32)
     else:
         print('unrecognized file format: %s' % image_path)
         return None
     assert self.data.shape == self.size
     self.compute_corrected_image()
コード例 #4
0
tsr_points[5] = [209, 675]

from pymicro.view.vol_utils import compute_affine_transform

# compute the affine transform from the point set
translation, transformation = compute_affine_transform(ref_points, tsr_points)
invt = np.linalg.inv(transformation)
offset = -np.dot(invt, translation)
print(translation)
print(transformation)

invt
from pymicro.external.tifffile import TiffFile

sem = TiffFile(
    'Slice%d.tif' %
    slice).asarray()[:2048, :].T  # imaged with scaling already applied
print('SEM shape', sem.shape)
compositeScan = OimScan.zeros_like(sem.T, resolution=(pixel_size, pixel_size))
compositeScan.sampleId = '%s_%03d' % (prefix, slice)

plt.imshow(sem.T, cmap=cm.gray)
plt.show()

from scipy import ndimage
# register ebsd
iq_reg = ndimage.interpolation.affine_transform(iq.T,
                                                invt,
                                                output_shape=sem.shape,
                                                offset=offset).T
eu0_reg = ndimage.interpolation.affine_transform(scan.euler[:, 0].T,