skimage rescale学习

example1

bash 复制代码
import numpy as np
from skimage import data
from skimage.transform import rescale
import matplotlib.pyplot as plt

# Load a sample image
image = data.chelsea()
 
# Notice that you shouldn't use the multichannel parameter
# Rescale the image to 50% of its original size
image_rescaled = rescale(image, 0.5, anti_aliasing=True, channel_axis=2)

# Display the original and rescaled images
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(10, 5))

ax1.imshow(image)
ax1.set_title('Original image')

ax2.imshow(image_rescaled)
ax2.set_title('Rescaled image (50%)')

plt.tight_layout()
plt.show()

example2

bash 复制代码
import numpy as np
from skimage import data, img_as_ubyte
from skimage.transform import rescale
import matplotlib.pyplot as plt

# Load a sample image
image = data.chelsea()

# Rescale the image to 50% of its original size
image_rescaled_float = rescale(image, 0.5, anti_aliasing=True, channel_axis=2)

# Convert the rescaled image to 8-bit unsigned integer
image_rescaled = img_as_ubyte(image_rescaled_float)

# Display the original and rescaled images
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(10, 5))

ax1.imshow(image)
ax1.set_title('Original image')

ax2.imshow(image_rescaled)
ax2.set_title('Rescaled image (50%)')

plt.tight_layout()
plt.show()

# Print the data types to verify
print("Original image dtype:", image.dtype)
print("Rescaled image dtype:", image_rescaled.dtype)
相关推荐
alfiy16 分钟前
ElasticSearch学习笔记(三)Ubuntu 2204 server elasticsearch集群配置
笔记·学习·elasticsearch
hengzhepa43 分钟前
ElasticSearch备考 -- 多字段查询
学习·elasticsearch·搜索引擎·全文检索·es
结衣结衣.3 小时前
Python基础语法1
开发语言·笔记·python·学习·编程·编程语法
Lbs_gemini06033 小时前
Java研发笔记6——C语言程序设计学习笔记5
c语言·笔记·学习
tiantian17)3 小时前
深入学习并发编程中的 synchronized
java·学习
朔北之忘 Clancy4 小时前
2021 年 12 月青少年软编等考 C 语言二级真题解析
c语言·开发语言·c++·学习·算法·青少年编程·题解
蜡笔小新星4 小时前
在Python中,使用Pillow(PIL的更新分支)库来合并两张图片成一张上下结构的图片
前端·经验分享·python·学习·pillow