def map_image(image,func): x,y = image.size a = kd_array.gen_array((x,y), init_elem = apply(func, [image.getpixel((0,0))])) for i in range(x): for j in range(y): a[i,j] = apply(func, [image.getpixel((i,j))]) return a
def column_avg(image,band='red'): x,y = image.size func = eval("get_"+band) a = kd_array.gen_array([x], init_elem = 0.0) for i in range(x): sum_band = 0 for j in range(y): sum_band += func(image,i,j) a[i] = float(sum_band)/float(y) return a
def columns_max_spikes_red(image, band='red'): x,y = image.size func = eval("get_red") green = eval("get_green") blue = eval("get_blue") a = kd_array.gen_array([x], init_elem = 0.0) for i in range(x): maximum = 0 for j in range(y): if maximum < (func(image, i, j) - green(image,i,j) - blue(image,i,j)): maximum = func(image, i, j) a[i] = maximum return a
def column_avg(image,band='red',y_scope_to=1,y_scope_from=0): """ Extended with scope settings for Y-axis. """ x,y = image.size func = eval("get_"+band) a = kd_array.gen_array([x], init_elem = 0.0) for i in range(x): sum_band = 0 from_ = int(math.ceil(y*y_scope_from)) to_ = int(math.floor(y*y_scope_to)) for j in range(from_, to_): sum_band += func(image,i,j) a[i] = float(sum_band)/float(to_-from_) return a