# -*- coding: utf-8 -*-
import cv2
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
path = 'lena.bmp'
def show_image():
img = cv2.imread(
path)
plt.imshow(img)
plt.show()
def img2bit():
# 位图模式
lena = Image.open(path)
# 转换
lena_1 = lena.convert("1")
lena_1.show()
lena_1 = np.array(lena_1) # 矩阵
print(lena_1[:][0][0])
def img2gray():
# 位图模式
lena = Image.open(path)
# 转换
lena_1 = lena.convert("L")
lena_1 = np.array(lena_1) # 矩阵
plt.imshow(lena_1, 'gray')
plt.show()
def img2idx():
# 索引彩色模式
lena = Image.open(path)
# 转换为调色板模式
print(lena.getpixel((0, 0)))
lena_1 = lena.convert("P")
print(lena_1.mode)
palette = lena_1.palette
print(lena_1.getpixel((0, 0)))
lena_1.show()
# print(lena_1.palette.__dict__)
def img2RGBA():
# 位图模式
图像基本处理 填充 / 颜色模式转换等 python
最新推荐文章于 2021-12-08 19:43:51 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)