本文整理汇总了Python中tifffile.imread方法的典型用法代码示例。如果您正苦于以下问题:Python tifffile.imread方法的具体用法?Python tifffile.imread怎么用?Python tifffile.imread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tifffile
的用法示例。
在下文中一共展示了tifffile.imread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: degrade_images_in_folder
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def degrade_images_in_folder(
folder,
dst_folder_suffix,
LIGHTDOWN=True,
UNBALANCECOLOR=True,):
import os
js = os.listdir(folder)
dst_folder = folder + '-' + dst_folder_suffix
try:
os.mkdir(dst_folder)
except:
print('dir exist!')
print('in ' + dst_folder)
num = 3
for j in js:
img = cv2.imread(folder + '/' + j) / 255.
if LIGHTDOWN:
for _ in range(num - 1):
out = pow(img, np.random.uniform(0.4, 0.6)) * np.random.uniform(
0.25, 0.5)
cv2.imwrite(dst_folder + '/' + ('L%d-' % _) + j, out * 255.)
out = img * img
out = out * (1.0 / out.max())
cv2.imwrite(dst_folder + '/' + ('L%d-' % num) + j, out * 255.)
if UNBALANCECOLOR:
filter = WB2()
outs = np.array([img] * num)
features = np.abs(np.random.rand(num, 3))
for _, out in enumerate(
filter.process(outs, filter.filter_param_regressor(features))):
# print out.max()
out /= out.max()
out *= np.random.uniform(0.7, 1)
cv2.imwrite(dst_folder + '/' + ('C%d-' % _) + j, out * 255.)
示例2: imread
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def imread(filename: str) -> np.ndarray:
"""Custom implementation of imread to avoid skimage dependency.
Parameters
----------
filename : string
The path from which to read the image.
Returns
-------
data : np.ndarray
The image data.
"""
filename = abspath_or_url(filename)
ext = os.path.splitext(filename)[1]
if ext in [".tif", ".tiff", ".lsm"]:
import tifffile
return tifffile.imread(filename)
else:
import imageio
return imageio.imread(filename)
示例3: load_zstack
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def load_zstack(self):
name = QtGui.QFileDialog.getOpenFileName(
self, "Open zstack", filter="*.tif"
)
self.fname = name[0]
try:
self.zstack = imread(self.fname)
self.zLy, self.zLx = self.zstack.shape[1:]
self.Zedit.setValidator(QtGui.QIntValidator(0, self.zstack.shape[0]))
self.zrange = [np.percentile(self.zstack,1), np.percentile(self.zstack,99)]
self.computeZ.setEnabled(True)
self.zloaded = True
self.zbox.setEnabled(True)
self.zbox.setChecked(True)
if 'zcorr' in self.ops[0]:
if self.zstack.shape[0]==self.ops[0]['zcorr'].shape[0]:
zcorr = self.ops[0]['zcorr']
self.zmax = np.argmax(gaussian_filter1d(zcorr.T.copy(), 2, axis=1), axis=1)
self.plot_zcorr()
except Exception as e:
print('ERROR: %s'%e)
示例4: read_image_file
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def read_image_file(path: str, gray_scale=False):
if not os.path.exists(path):
raise Exception(f'Image at path {path} does not exist')
if path.endswith('.tiff') and not gray_scale:
return tifffile.imread(path)
elif path.endswith('.npy'):
return np.load(path)
else:
if gray_scale:
img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
assert img is not None, \
f'Image at path {path} is empty'
return img.astype(np.uint8)
else:
img = cv2.imread(path)
assert img is not None, \
f'Image at path {path} is empty'
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
示例5: load_file
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def load_file(f, gray):
"""
Load a file f.
gray: whether the image
should be gray
"""
if f[-4:] == 'tiff' or f[-3:] == 'tif':
img = tifffile.imread(f)
else:
img = imageio.imread(f)
if len(img.shape) == 2:
img = np.expand_dims(img, 2)
img = np.asarray(img, dtype=np.float32)
if gray and img.shape[2] > 1:
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img = np.expand_dims(img, 2)
assert(img.shape[2] == 1 or img.shape[2] == 3) # Gray or RGB. Please convert RGBA to RGB.
img = np.asarray(img, dtype=np.float32)
img = img/255.
return img
示例6: read_tiff16
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def read_tiff16(fn):
import tifffile
import numpy as np
img = tifffile.imread(fn)
if img.dtype == np.uint8:
depth = 8
elif img.dtype == np.uint16:
depth = 16
else:
print("Warning: unsupported data type {}. Assuming 16-bit.", img.dtype)
depth = 16
return (img * (1.0 / (2**depth - 1))).astype(np.float32)
示例7: get_artist_batch
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def get_artist_batch(folder, size=128, num=64):
import os
js = os.listdir(folder)
np.random.shuffle(js)
imgs = np.zeros((num, size, size, 3))
for i, jpg in enumerate(js[:num]):
img = cv2.imread(folder + '/' + jpg)
img = get_image_center(img) / 255.
imgs[i] = cv2.resize(img, dsize=(size, size))
return imgs
示例8: read_tiff_16bit_img_into_XYZ
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def read_tiff_16bit_img_into_XYZ(tiff_fn, exposure=0):
pp_rgb = tiff.imread(tiff_fn)
pp_rgb = np.float64(pp_rgb) / (2**16 - 1.0)
if not pp_rgb.shape[2] == 3:
print('pp_rgb shape', pp_rgb.shape)
raise UtilImageError('image channel number is not 3')
pp_rgb = linearize_ProPhotoRGB(pp_rgb)
pp_rgb *= np.power(2, exposure)
xyz = ProPhotoRGB2XYZ(pp_rgb)
xyz = XYZ_chromatic_adapt(xyz, src_white='D50', dest_white='D65')
return xyz
示例9: read_tiff_image
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def read_tiff_image(filename):
""" Read data from TIFF file
:param filename: name of TIFF file to be read
:type filename: str
:return: data stored in TIFF file
"""
return tiff.imread(filename)
示例10: decode_image
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def decode_image(data, image_type):
""" Decodes the image provided in various formats, i.e. png, 16-bit float tiff, 32-bit float tiff, jp2
and returns it as an numpy array
:param data: image in its original format
:type data: any of possible image types
:param image_type: expected image format
:type image_type: constants.MimeType
:return: image as numpy array
:rtype: numpy array
:raises: ImageDecodingError
"""
bytes_data = BytesIO(data)
if image_type.is_tiff_format():
image = tiff.imread(bytes_data)
else:
image = np.array(Image.open(bytes_data))
if image_type is MimeType.JP2:
try:
bit_depth = get_jp2_bit_depth(bytes_data)
image = fix_jp2_image(image, bit_depth)
except ValueError:
pass
if image is None:
raise ImageDecodingError('Unable to decode image')
return image
示例11: imread
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def imread(self):
"""
Use tifffile.imread to read image.tiff.
"""
file_name = os.path.join(self.data_dir, "image.tiff")
tifffile.imread(file_name)
示例12: _run_benchmark
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def _run_benchmark(
resources_dir: Path,
extensions: List[str],
non_aicsimageio_reader: List[Callable],
iterations: int = 3,
):
# Collect files matching the extensions provided
files = []
for ext in extensions:
files += list(resources_dir.glob(ext))
# Run reads for each file and store details in results
results = []
for file in files:
info_read = aicsimageio.AICSImage(file)
yx_planes = np.prod(info_read.size("STCZ"))
for reader in [aicsimageio.imread, non_aicsimageio_reader]:
reader_path = f"{reader.__module__}.{reader.__name__}"
for i in tqdm(range(iterations), desc=f"{reader_path}: {file.name}"):
start = time.perf_counter()
reader(str(file))
results.append(
{
"file_name": file.name,
"file_size_gb": file.stat().st_size / 10e8,
"reader": (
"aicsimageio" if "aicsimageio" in reader_path else "other"
),
"yx_planes": int(yx_planes),
"read_duration": time.perf_counter() - start,
}
)
return results
示例13: _run_benchmark_suite
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def _run_benchmark_suite(resources_dir: Path):
# Default reader / imageio imread tests
default_reader_single_image_results = _run_benchmark(
resources_dir=resources_dir,
extensions=["*.png", "*.jpg", "*.bmp"],
non_aicsimageio_reader=imageio.imread,
)
# Default reader / imageio mimread tests
default_reader_many_image_results = _run_benchmark(
resources_dir=resources_dir,
extensions=["*.gif"],
non_aicsimageio_reader=imageio.mimread,
)
# Tiff reader / tifffile imread tests
tiff_reader_results = _run_benchmark(
resources_dir=resources_dir,
extensions=["*.tiff"],
non_aicsimageio_reader=tifffile.imread,
)
# CZI reader / czifile imread tests
czi_reader_results = _run_benchmark(
resources_dir=resources_dir,
extensions=["*.czi"],
non_aicsimageio_reader=czifile.imread,
)
return [
*default_reader_single_image_results,
*default_reader_many_image_results,
*tiff_reader_results,
*czi_reader_results,
]
示例14: convert_tiff_to_png_tst
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def convert_tiff_to_png_tst():
files = glob.glob(INPUT_TESTING_PATH + "/*_RGB.tif")
print(len(files))
for f in files:
id = os.path.basename(f)[:-8]
print(id)
dsm_path = os.path.dirname(f) + '/' + id + '_DSM.tif'
dtm_path = os.path.dirname(f) + '/' + id + '_DTM.tif'
rgb_path = f
dsm = tifffile.imread(dsm_path)
dtm = tifffile.imread(dtm_path)
rgb = tifffile.imread(rgb_path)
print('DSM:', dsm.min(), dsm.max())
print('DTM:', dtm.min(), dtm.max())
dsm[dsm > -30000] += 220
dsm[dsm <= -30000] = 0
dsm *= 160
# print('DSM:', dsm.min(), dsm.max())
dsm = dsm.astype(np.uint16)
dtm[dtm > -30000] += 100
dtm[dtm <= -30000] = 0
dtm *= 540
# print('DTM:', dtm.min(), dtm.max())
dtm = dtm.astype(np.uint16)
print('DSM:', dsm.min(), dsm.max())
print('DTM:', dtm.min(), dtm.max())
if dsm.shape[:2] != rgb.shape[:2]:
print('Shape error!', id, dsm.shape[:2], rgb.shape[:2])
od = OUTPUT_BUILDING_TEST
dsm_path = od + id + '_dsm.png'
dtm_path = od + id + '_dtm.png'
rgb_path = od + id + '_rgb.png'
cv2.imwrite(dsm_path, dsm)
cv2.imwrite(dtm_path, dtm)
cv2.imwrite(rgb_path, rgb)
示例15: read3dTiff
# 需要导入模块: import tifffile [as 别名]
# 或者: from tifffile import imread [as 别名]
def read3dTiff(fName):
return imread(fName)