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)
相关推荐
近津薪荼23 分钟前
优选算法——双指针5(单调性)
c++·学习·算法
idontknow23325 分钟前
DPDK学习笔记(1):二层转发应用例代码解析
c语言·网络·笔记·学习
求真求知的糖葫芦1 小时前
耦合传输线分析学习笔记(八)对称耦合微带线S参数矩阵推导与应用(上)
笔记·学习·矩阵·射频工程
2501_942326441 小时前
掌握脑科学记忆法,助力孩子高效学习
学习
试试勇气1 小时前
Linux学习笔记(十三)--文件系统
linux·笔记·学习
FAFU_kyp1 小时前
RISC0_ZERO项目在macOs上生成链上证明避坑
开发语言·后端·学习·macos·rust
jrlong1 小时前
DataWhale大模型基础与量化微调task5学习笔记(第 3 章:大模型训练与量化_Deepspeed 框架介绍)
笔记·学习
程序员清洒1 小时前
Flutter for OpenHarmony:Icon 与 IconButton — 图标系统集成
前端·学习·flutter·华为
时光慢煮1 小时前
打造跨端驾照学习助手:Flutter × OpenHarmony 实战解析
学习·flutter·华为·开源·openharmony
A9better1 小时前
嵌入式开发学习日志52——二值与计数信号量
单片机·嵌入式硬件·学习