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)
相关推荐
solicitous1 天前
人工智能发展的关键阶段概览
学习
FPGAI1 天前
Java学习之基础概念
java·学习
专注于大数据技术栈1 天前
java学习--Date
java·学习
94620164zwb51 天前
学习提醒模块 Cordova 与 OpenHarmony 混合开发实战
学习
北岛寒沫1 天前
北京大学国家发展研究院 经济学辅修 经济学原理课程笔记(第十五章 劳动力市场)
经验分享·笔记·学习
丝斯20111 天前
AI学习笔记整理(37)——自然语言处理的基本任务
人工智能·笔记·学习
BreezeJuvenile1 天前
通用定时器_测量PWM方波的周期和占空比案例
stm32·单片机·学习·通用定时器·pwm输入·测量占空比
周末不下雨1 天前
发明专利学习记录
学习
亚里随笔1 天前
偏离主路径:RLVR在参数空间中的非主方向学习机制
人工智能·深度学习·学习
我命由我123451 天前
Photoshop - Photoshop 工具栏(46)渐变工具
经验分享·笔记·学习·ui·职场和发展·学习方法·photoshop