def from_file(path, scale):
''' Reads a file into a new RGBImage instance, must be 24bpp/8bpc
Args:
path (`string`): path to a file.
scale (`float`): pixel scale, in microns.
Returns:
`RGBImage`: a new image object.
Notes:
TODO: proper handling of images with more than 8bpp.
'''
# img is an mxnx3 array of unit8s
img = imread(path).astype(config.precision) / 255
img = np.flip(img, axis=0)
# crop the image if it has an odd dimension.
# TODO: change this an understand why it is an issue
# fftshift vs ifftshift?
if is_odd(img.shape[0]):
img = img[0:-1, :, :]
if is_odd(img.shape[1]):
img = img[:, 0:-1, :]
return RGBImage(r=img[:, :, 0], g=img[:, :, 1], b=img[:, :, 2],
sample_spacing=scale, synthetic=False)
评论列表
文章目录