图像的数组表示及变换

一、图像的数组表示

RGB能够构成人眼所能识别的所有颜色。

二、图像的变换

Example:

img.shape
Out[329]: (512, 768, 3)
img.dtype
Out[330]: dtype('uint8')
#补值变换
shift_temp_img = [255,255,255] - img
shift_img = Image.fromarray(shift_temp_img.astype('uint8'))
shift_img.save("D:/shift1.jpg")

img = np.array(Image.open("practice_dataset/train/ants_image/0013035.jpg").convert('L'))
b = 255 - img
shift_img = Image.fromarray(b.astype('uint8'))
shift_img.save("D:/shift2.jpg")

img = np.array(Image.open("practice_dataset/train/ants_image/0013035.jpg").convert('L'))
#区间变换
c =  (200/255) * img + 55
shift_img = Image.fromarray(c.astype('uint8'))
shift_img.save("D:/shift3.jpg")

img = np.array(Image.open("practice_dataset/train/ants_image/0013035.jpg").convert('L'))
d =  255 * (img/255)**2
shift_img = Image.fromarray(d.astype('uint8'))
shift_img.save("D:/shift4.jpg")

注:

uint8 是一个数据类型,表示无符号 8 位整数(unsigned 8-bit integer)。在许多编程语言和图像处理库中,包括 Python 中的 NumPy 和 PIL(Pillow),uint8 常用于表示图像像素的颜色值。

在 NumPy 中,uint8 是一种数据类型,用于表示范围在 0 到 255 之间的整数。它占用 8 位(1 字节)内存空间。可以使用 np.uint8 或 np.dtype('uint8') 来表示 uint8 数据类型。

在 PIL(Pillow)中,uint8 是默认的像素数据类型,用于表示图像的每个像素的颜色值。PIL 中的图像对象可以通过 Image.mode 属性来查看图像的模式,通常会显示为 "L"(灰度图像)或 "RGB"(真彩色图像)。对于 "L" 模式的图像,每个像素的值是一个 uint8 类型的灰度值(0 到 255);对于 "RGB" 模式的图像,每个像素的值是一个长度为 3 的 uint8 类型的元组,表示红、绿、蓝三个通道的颜色值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DQ小恐龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值