【发布时间】:2020-03-19 13:21:00
【问题描述】:
所以,我正在尝试在 python 中复制图像上的“Floyd–Steinberg 抖动”,到目前为止,这是我所做的:
import cv2
# returns an array with rgb values of all pixels
x_img = cv2.imread("lenac.tif")
# returns an image with the rgb values turned to black and white
x_img_g = cv2.cvtColor(x_img,cv2.COLOR_BGR2GRAY)
def dither(img):
col = len(img[0])
li = len(img)
print(col)
print(li)
for i in range (li):
for j in range(col):
oldpixel = img[li][col]
newpixel = quantificacao(oldpixel)
print(newpixel)
print(dither(x_img_g))
所以基本上这个方法还没有完成,它唯一要做的就是遍历“lena.tif”图像上黑白版本的每个像素(在图像处理中非常有名),并应用于他们有一种叫做“quantificacao”的方法,与问题无关。
图像为 512 x 512
一切正常,直到在给定点弹出以下错误:
oldpixel = img[li][col]
IndexError: index 512 is out of bounds for axis 0 with size 512
变量col 和li 都显示为512,所以for cycle 应该从0 变为511 对吧?
因此只能索引到 511
我有点迷路了,如果有人可以帮助我,我会非常感激
【问题讨论】:
标签: python arrays image indexing cv2