使用的库:tensorflow,opencv,numpy,matlablit.

图片的读取展示:

我们首先要有这么做的思路:先导入opencv库,再使用它的API,还要让程序停下,否则图片可能会因为程序的后续动作而消失。

源码如下:

import cv2
img=cv2.imread("humor.jpg",1)#前一项是图片的名字,后一项为0是灰度图片,1是彩色的。
#img就是图片了。
cv2.imshow("humor",img)#前一项是给展现出来的图片取名(就是显示在窗口上方的名字)
                       #后一项就是展示的内容,也就是那个图片。

cv2.waitKey(0)#咋瓦鲁多!

上面的对函数的解释较简单,下面详解一下:

cv2.imread():用于读取图片文件

imread函数有两个参数,第一个参数是图片路径(上面的不用因为在同一个文件夹里),第二个参数表示读取图片的形式,有三种:

cv2.IMREAD_COLOR:加载彩色图片,这个是默认参数,可以直接写1。
cv2.IMREAD_GRAYSCALE:以灰度模式加载图片,可以直接写0。
cv2.IMREAD_UNCHANGED:包括alpha,可以直接写-1

cv2.imread()读取图片后已多维数组的形式保存图片信息,前两维表示图片的像素坐标,最后一维表示图片的通道索引,具体图像的通道数由图片的格式来决定。(就是一个3维数组,把它看成3个拼在一起的二维数组,每个2维数组的坐标对应的是原来该像素在图片上的坐标,内容就是3通道中的自己对应的那个通道的值)注意:该数组要是numpy或者scalar.

cv2.imshow()

    cv2.imShow()函数可以在窗口中显示图像。该窗口和图像的原始大小自适应(自动调整到原始尺寸)。

    第一个参数是一个窗口名称(也就是我们对话框的名称),它是一个字符串类型。第二个参数是我们的图像。您可以创建任意数量的窗口,但必须使用不同的窗口名称。(加入用同一个窗口的话不就是在同一个窗口里继续画图了吗?)

事实证明在同一个窗口里画两个同样的图没有效果。

cv2.waitKey(0): 是一个和键盘绑定的函数,它的作用是等待一个键盘的输入(因为我们创建的图片窗口如果没有这个函数的话会闪一下就消失了,所以如果需要让它持久输出,我们可以使用该函数)。它的参数是毫秒级。该函数等待任何键盘事件的指定毫秒。如果您在此期间按下任何键,程序将继续进行。我们也可以将其设置为一个特定的键。(可是我的没写这个的时候也没消失呀?难道改进了?)

opencv库的模块结构:

cv2查看图片文件信息 python cv2 读取图片_opencv

 标红了的就是今后重点的模块。

这里对文件做一个解释:

文件包括两部分:文件头和文件数据。文件数据是压缩过的,文件头就记录了压缩信息(也就说明了如何解压缩)。imread在使用一张图片时,要先读取文件,解析他的封装格式(压缩的方式),再根据这个信息进行数据解码,最后数据加载,把数据放到那个np.array数组里,我们才能用。

图片写入:cv2.imwrite("路径",要写入的图片,[cv2.IMWRITE_JPEG_QUALITY,参数])。

注意:写入的图片要是已经数据加载后的“图片”(一个三维数组),可以简单理解为imread()之后的那种东西。想要实现不同质量的图片,可以调节压缩比(0-100)。(最后那一项可以不写)

注意:jpg的那个参数越低,压缩比越高,获得的文件越小,模糊。

png的参数越低,压缩比越低,范围在(0-9)

jpg是有损压缩,压缩比跳的太小会变得很模糊。可以用png,好处多多,无损压缩,还可以调透明度。

cv2查看图片文件信息 python cv2 读取图片_深度学习_02

cv2查看图片文件信息 python cv2 读取图片_opencv_03

图片的一些介绍:

像素:图片上一个一个小方块就是像素。

RGB:三通道是红绿蓝三种颜色。(也有BGR,就是反一下)

颜色深度:就是那三通道(一个三维数组)的内容的值,有8bit,也就是说每种颜色的范围就在(0,255),一个像素点大小相当于一个char,字节。

w,h:宽和高。

刚刚还提到了png比jpg多了一个透明度属性对吧?所以png还有一个alpha通道(所以说png的数组有4个通道,是由4个二维数组组成的)

像素读取写入:

img=imread("image.jpg",1)

(b,g,r)=img[x,y]

这是一个元组,分别是蓝,绿,红

破案啦破案啦,imread返回的是一个numpy.array数组。结构就像普通的数组一样,但是引用其内容的方式很特别,如:

cv2查看图片文件信息 python cv2 读取图片_cv2查看图片文件信息 python_04

 不用两个框框,而是一个框框里面用逗号隔开。

自己画图实验:

使用普通二维列表试图画灰度图,失败。

改成np.array,成功。

使用np.array的三通道三维数组,失败。

使用普通二维数组,元素是一个元组(三个元素的,代表三通道)还是失败了。

将上述数组np.array化,成功。

代码记录如下:

import cv2
import numpy as np
a=[
[
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
],
[
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
],[
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
[34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,5,63,56,88,95,77,35,34,],
],
]
a=np.array(a)
b=[
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
[(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),(12,34,56),(78,89,0),(12,34,56),],
    ]
b=np.array(b)
cv2.imwrite("myPicColor.jpg",b)

总结:imread,imwrite用的都是np.array数组。都是”二维数组“,彩色的就是元素就是元组。

接下来接着谈提取出来之后的事。获得了元组后可以直接对元组进行修改:

(b,g,r)=(255,255,255)就可以了。

那你可能说了,元组不是不可以修改吗?元组的修改实际上是产生一个新元组。(平时修改也是这样),然后把原来的替换掉(就像是C里的指针指向了新的内存,原来的没人指着,就成了垃圾,没了)

图像基本操作就先这样吧,接下来就先学一些其他知识。