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

devtools/2024/9/25 23:21:09/

图像处理

  • 9. 转换类型
    • 9.1转换成浮点数类型
    • 9.2转换成无符号字节类型
  • 10.颜色空间转换
    • 10.1RGB转GRAY
    • 10.2RGB转HSV
    • 10.3RGB转LAB
    • 10.4HSV转RGB
    • 10.5LAB转RGB
    • 10.6 convert_colorspace函数进行颜色转换
  • 11.标签化处理图像
    • 11.1导入模块
    • 11.2加载图片
    • 11.3RGB图像转灰度图像
    • 11.4遍历图像
    • 11.5打印图像并显示
  • 12.颜色图谱
    • 12.1None
    • 12.2autumn
    • 12.3bone
    • 12.4cool
    • 12.5copper
    • 12.6flag
    • 12.7gray
    • 12.8hot
    • 12.9hsv
    • 12.10inferno
    • 12.11jet
    • 12.12magma
    • 12.13pink
    • 12.14plasma
    • 12.15prism
    • 12.16spring
    • 12.17summer
    • 12.18viridis
    • 12.19winter

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]=0else: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()

运行结果:
在这里插入图片描述


http://www.ppmy.cn/devtools/32829.html

相关文章

抽象类~~

抽象类的介绍 当父类的某些方法&#xff0c;需要声明&#xff0c;但是又不确定如何实现时&#xff0c;可以将其声明为抽象方法&#xff0c;那么这个类就是抽象类。用abstract关键字来修饰一个类时&#xff0c;这个类就叫抽象类 访问修饰符 abstract 类名{}用abstract关键字来修…

php中常见的运算符和使用方法

PHP中常见的运算符包括算术运算符、赋值运算符、比较运算符、逻辑运算符、位运算符、字符串运算符、三元条件运算符&#xff08;也称为三目运算符&#xff09;、递增/递减运算符等。以下是这些运算符的简要说明和使用方法&#xff1a; 算术运算符&#xff1a; &#xff1a;加法…

【C++】文件

目录 文件文件分类文本文件的读写(ASCII文件)的读写打开文件打开文件的方式关闭文件将数据写入ASCII文件从ASCII文件读入数据 二进制存储对比ASCII和二进制存储用成员函数read和write读写二进制文件打开方式文件的读入与读出 文件 所谓文件&#xff0c;一般指存储在外部介质上…

SQL 基础 | AVG 函数的用法

在SQL中&#xff0c;AVG()是一个聚合函数&#xff0c;用来计算某个列中所有值的平均值。 它通常与GROUP BY子句一起使用&#xff0c;以便对分组后的数据进行平均值计算。 AVG()函数在需要了解数据集中某个数值列的中心趋势时非常有用。 以下是AVG()函数的一些常见用法&#xff…

springmvc下

第二类初始化操作 multipartResolver应用 localeResolver应用 themeResolver应用 handlerMapping应用 handlerAdapter应用 handlerExceptionReslver requestToViewNameTranslator应用 viewResolver应用 flashMapManager应用 dispatcherServlet逻辑处理 processRequest处理web请…

C语言 | Leetcode C语言题解之第61题旋转链表

题目&#xff1a; 题解&#xff1a; struct ListNode* rotateRight(struct ListNode* head, int k) {if (k 0 || head NULL || head->next NULL) {return head;}int n 1;struct ListNode* iter head;while (iter->next ! NULL) {iter iter->next;n;}int add n…

Vitis HLS 学习笔记--HLS流水线基本用法

目录 1. 简介 2. 示例 2.1 对内层循环打拍 2.2 对外层循环打拍 2.3 优化数组访问后打拍 3. 总结 1. 简介 本文介绍pipeline的基本用法。pipeline是一种用于提高硬件设计性能的技术。本文介绍了pipeline在累加计算函数中的应用。通过优化内外层循环和数组访问&#xff0c…

高德地图+HTML+点击事件+自定心信息窗体

代码如下 <!doctype html> <html><head><meta charset"utf-8"><meta http-equiv"X-UA-Compatible" content"IEedge"><meta name"viewport" content"initial-scale1.0, user-scalableno, width…