处理效果对比:
#图片处理
def imgDeal(img_path,save_path):
img = Image.open(img_path)
img = levelsDeal(img,108,164)
img_res = Image.fromarray(img.astype('uint8'))
print(u'图片[' + img_path + u']处理完毕')
img_res.save(save_path)
#图像矩阵处理
def levelsDeal(img, black,white):
if white > 255:
white = 255
if black < 0:
black = 0
if black >= white:
black = white - 2
img_array = np.array(img, dtype = int)
cRate = -(white - black) /255.0 * 0.05
rgb_diff = img_array - black
rgb_diff = np.maximum(rgb_diff, 0)
img_array = rgb_diff * cRate
img_array = np.around(img_array, 0)
img_array = img_array.astype(int)
return img_array
如果您有大量需要处理的需求,可以联系作者提供在线接口使用