【发布时间】:2014-02-27 19:53:51
【问题描述】:
是否可以在 numpy 数组中实现此图像过滤过程?我需要检查上一列和上一行中的像素是否与当前像素不同。
width, height = orig_bin.size
pixels = orig_bin.load()
delta = 50
begin = 10
min_w = 30
max_w = 260
min_h = 10
max_h = 40
w_range = range(begin, width - min_w - delta)
h_range = range(begin, height - min_h - delta)
is_changing = False
for x in w_range:
for y in h_range:
change_pixel = False
current_pixel = pixels[x,y]
if current_pixel != pixels[x, y+1]:
change_pixel = True
if current_pixel != pixels[x+1, y]:
change_pixel = True
if change_pixel:
pixels[x,y] = (0,0,0)
else:
pixels[x,y] = (255,255,255)
最好的问候, 埃米利奥
【问题讨论】:
-
此实现是否存在问题,或者您是否正在寻求优化?这里具体有什么问题?