1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > opencv-python遍历整个图像的每个像素点

opencv-python遍历整个图像的每个像素点

时间:2023-07-11 05:53:58

相关推荐

opencv-python遍历整个图像的每个像素点

from PIL import Imageimport numpy as npimg = Image.open("F:/PYproject/unet_camvid/CamVid/testimage/2.png")#img.show()img_array = np.array(img)#把图像转成数组格式img = np.asarray(image)shape = img_array.shapeprint(img_array.shape)for i in range(0,shape[0]):for j in range(0,shape[1]):value = img_array[i, j]#print("",value)if value[0] != 0:print("", value)height = shape[0]width = shape[1]dst = np.zeros((height,width,3))for h in range(0,height):for w in range (0,width):(b,g,r) = img_array[h,w]if (b,g,r)==(255,255,255):#白色img_array[h,w] = (0,255,255)#蓝色if (b, g, r) == (85, 85, 85): # 深灰img_array[h, w] = (0, 128, 0) # 绿色if (b, g, r) == (170, 170, 170): # 灰色img_array[h, w] = (255, 255, 0) # 黄色if (b, g, r) == (0, 0, 0): # 黑色img_array[h, w] = (255, 0, 0) # 红色dst[h,w] = img_array[h,w]img2 = Image.fromarray(np.uint8(dst))img2.show(img2)img2.save("3.png","png")

行优先,一次访问。注意行坐标(y)的位置

for 行 --- 行总数:for 列----列总数:value = img[行,列]

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。