skimage.util.img_as_ubyte的源代码是什么
时间: 2023-11-28 18:47:15 浏览: 131
Jama.rar_Jama.util Maths.java_jama_jama包
skimage.util.img_as_ubyte的源代码如下:
```python
def img_as_ubyte(image, force_copy=False):
"""Convert an image to 8-bit uint format.
This function is similar to img_as_uint, but does not guarantee the
same output dtype for identical input data. This function is useful
for generating an 8-bit uint image *without* rescaling so that
identical input data will not be guaranteed to have identical output
data.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional (default=False)
Force a copy of the data.
Returns
-------
out : ndarray
Output image.
Examples
--------
>>> from skimage import data, img_as_ubyte
>>> image = data.astronaut()
>>> image.max() <= 1.0
True
>>> image_ubyte = img_as_ubyte(image)
>>> 0 <= image_ubyte.max() <= 255
True
"""
if not _is_low_contrast(image):
warn("Possible precision loss converting image to uint8")
return convert(image, np.uint8, force_copy=force_copy)
```
该函数将输入图像转换为8位无符号整数格式。它类似于img_as_uint,但不保证相同输入数据的相同输出dtype。这个函数非常有用,因为它可以生成一个8位无符号整数图像,而不需要重新缩放,因此不能保证相同的输入数据具有相同的输出数据。函数还包括一个可选参数force_copy,用于强制复制输入数据。
阅读全文