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)
相关推荐
d111111111d1 天前
STM32外设学习--DMA直接存储器读取(AD扫描程序,DMA搬运)--学习笔记。
笔记·stm32·单片机·嵌入式硬件·学习
流川_疯1 天前
CANOE概念与应用
经验分享·笔记·学习·汽车
Elias不吃糖1 天前
NebulaChat 框架学习笔记:原子变量与左值引用的工程应用
c++·学习
Chloeis Syntax1 天前
MySQL初阶学习日记(2)--- 数据库的数据类型和表的操作
数据库·学习·mysql
雷工笔记1 天前
计算机更换硬盘并新装系统
运维·学习
im_AMBER1 天前
Leetcode 51
笔记·学习·算法·leetcode·深度优先
Radan小哥1 天前
Docker学习笔记---day001
笔记·学习·docker
大志若愚YYZ1 天前
嵌入式Linux学习——环境变量与配置文件的关系(⭐难理解)
linux·学习
笨鸟笃行1 天前
百日挑战——单词篇(第十九天)
学习
诗句藏于尽头1 天前
TCP、UDP 和串口通信-学习笔记
学习·tcp/ip·udp