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)
相关推荐
小Tomkk4 小时前
2025年PMP 学习十五 第10章 项目资源管理
学习·pmp·项目pmp
oceanweave4 小时前
【K8S学习之生命周期钩子】详细了解 postStart 和 preStop 生命周期钩子
学习·kubernetes
黄暄7 小时前
初识计算机网络。计算机网络基本概念,分类,性能指标
笔记·学习·计算机网络·考研
梅子酱~8 小时前
Vue 学习随笔系列二十三 -- el-date-picker 组件
前端·vue.js·学习
Alice-YUE8 小时前
【HTML5学习笔记1】html标签(上)
前端·笔记·学习·html·html5
jerry6098 小时前
LLM笔记(五)概率论
人工智能·笔记·学习·概率论
threelab11 小时前
12.three官方示例+编辑器+AI快速学习webgl_buffergeometry_indexed
学习·编辑器·webgl
jerry60911 小时前
LLM笔记(六)线性代数
笔记·学习·线性代数·自然语言处理
ghost14311 小时前
C#学习第23天:面向对象设计模式
开发语言·学习·设计模式·c#
Yan_ks12 小时前
计算机组成原理——数据的表示
学习