遍历各个像素点并对其进行修改

#Author C

import os
import cv2
list = []
for filename in os.listdir(r'C:\Users\Uaena\Desktop\crack'): #在整个文件夹里面读取图片名称
route = r'C:\Users\Uaena\Desktop\crack\\' + filename #结合图片名称获取图片地址
list.append(route)#将该地址储存到list列表中
print(list)

#遍历每张图片#
for n in range(len(list)):

img1=cv2.imread(list[n])
sq = img1.shape
l=sq[0]
width=sq[1]
#遍历每个像素点#
for i in range(l):
for j in range(width):
if img1[i,j][0] == 0 and img1[i,j][1] ==0 and img1[i,j][2] == 0:
img1[i, j] = [0,0,0]
else:
# img1[i,j]=[0,0,0]
img1[i, j]=[255,255,255]

cv2.imwrite(r"C:\Users\Uaena\Desktop\bd\%d.jpg"%(n),img1)
posted @ 2018-07-21 20:33  mrc736  阅读(302)  评论(0编辑  收藏  举报