图像处理的一些操作(2)

图像处理

9. 转换类型

9.1转换成浮点数类型

python 复制代码
dst=img_as_float(img)

9.2转换成无符号字节类型

python 复制代码
dst1=img_as_ubyte(img)

from skimage import data,img_as_float,io
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
print(img.dtype.name)

dst=img_as_float(img)
dst1=img_as_ubyte(img)

print(dst.dtype.name)
print(img)
print(dst1.dtype.name)
print(img)

运行结果:



10.颜色空间转换

10.1RGB转GRAY

python 复制代码
from skimage import io, color
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
gray = color.rgb2gray(img)
io.imshow(gray)

运行结果:

10.2RGB转HSV

python 复制代码
from skimage import io, color
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
hsv = color.rgb2hsv(img)
io.imshow(hsv)

运行结果:

10.3RGB转LAB

python 复制代码
from skimage import io, color
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
lab = color.rgb2lab(img)
io.imshow(lab)

运行结果:

10.4HSV转RGB

python 复制代码
from skimage import io, color
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
hsv2 = color.hsv2rgb(img)
io.imshow(hsv2)

运行结果:

10.5LAB转RGB

python 复制代码
from skimage import io, color
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
lab2 = color.lab2rgb(img)
io.imshow(lab2)

运行结果:

10.6 convert_colorspace函数进行颜色转换

python 复制代码
from skimage import io, color
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
hsv = color.convert_colorspace(img,'RGB','HSV')
io.imshow(hsv)

运行结果:

11.标签化处理图像

11.1导入模块

python 复制代码
from skimage import io,data,color
import cv2

11.2加载图片

python 复制代码
image = cv2.imread(r"C:\Users\song\Desktop\2.jpg")

11.3RGB图像转灰度图像

python 复制代码
img_gray = color.rgb2gray(image)
rows,cols=img_gray.shape

11.4遍历图像

python 复制代码
for i in range(rows):
    for j in range(cols):
        if (img_gray[i,j]<=0.5):
            img_gray[i,j]=0
        else:
            img_gray[i,j]=1

11.5打印图像并显示

python 复制代码
print(img_gray.dtype.name)
dst=img_as_ubyte(img_gray) # 从浮点型转换成8位无符号整形
print(dst.dtype.name)
io.imshow(dst)

运行结果:

12.颜色图谱

12.1None

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap=None)

运行结果:

12.2autumn

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='autumn') # 将'autumn'作为字符串传递给cmap参数
plt.show()

运行结果:

12.3bone

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='bone')
plt.show()

运行结果:

12.4cool

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='cool')
plt.show()

运行结果:

12.5copper

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='copper')
plt.show()

运行结果:

12.6flag

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='flag')
plt.show()

运行结果:

12.7gray

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='gray')
plt.show()

运行结果:

12.8hot

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='hot')
plt.show()

运行结果:

12.9hsv

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='hsv')
plt.show()

运行结果:

12.10inferno

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='inferno')
plt.show()

运行结果:

12.11jet

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='jet')
plt.show()

运行结果:

12.12magma

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='magma')
plt.show()

运行结果:

12.13pink

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")

plt.imshow(img, cmap='pink')
plt.show()

运行结果:

12.14plasma

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='plasma')
plt.show()

运行结果:

12.15prism

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='prism')
plt.show()

运行结果:

12.16spring

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='spring')
plt.show()

运行结果:

12.17summer

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='summer')
plt.show()

运行结果:

12.18viridis

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='viridisr')
plt.show()

运行结果:

12.19winter

python 复制代码
import matplotlib.pyplot as plt
img = io.imread(r"C:\Users\song\Desktop\2.jpg")
plt.imshow(img, cmap='winter')
plt.show()

运行结果:

相关推荐
测试员周周4 小时前
【Appium 系列】第16节-WebView-H5上下文切换 — 混合应用的自动化难点
运维·开发语言·人工智能·功能测试·appium·自动化·测试用例
测试19984 小时前
软件测试 - 单元测试总结
自动化测试·软件测试·python·测试工具·职场和发展·单元测试·测试用例
K姐研究社5 小时前
怎么用AI制作电商口播视频,开拍APP一键生成
人工智能·音视频
LaughingZhu6 小时前
Product Hunt 每日热榜 | 2026-05-21
前端·人工智能·经验分享·chatgpt·html
曲幽6 小时前
我用了FastApiAdmin后,连夜把踩过的坑都整理出来了
redis·python·postgresql·vue3·fastapi·web·sqlalchemy·admin·fastapiadmin
传说故事6 小时前
【论文阅读】MotuBrain: An Advanced World Action Model for Robot Control
论文阅读·人工智能·具身智能·wam
北京耐用通信7 小时前
全域适配工业场景耐达讯自动化Modbus TCP 转 PROFIBUS 网关轻松实现以太网与现场总线互通
网络·人工智能·网络协议·自动化·信息与通信
火山引擎开发者社区7 小时前
TRAE × 火山引擎 Supabase:为你的 AI 应用装上“数据引擎”
人工智能
小a彤7 小时前
GE 在 CANN 五层架构中的位置
人工智能·深度学习·transformer
前端若水7 小时前
会话管理:创建、切换、删除对话历史
前端·人工智能·python·react.js