实现图像反色:
实现原理:
读取每个像素值P,再将255-P写入新的图片中;
对于灰度图,只有一个通道,所以 img2[i,j] = (255-image[i,j]) ;
对于彩色图片,则要RGB值分别做处理,255-image[i,j][0],255-image[i,j][1],255-image[i,j][2];
灰度图:
def inverse_color(image):
height,width = image.shape
img2 = image.copy()
for i in range(height):
for j in range(width):
img2[i,j] = (255-image[i,j])
return img2
彩色图:
def inverse_color(image):
height,width,temp = image.shape
img2 = image.copy()
for i in range(height):
for j in range(width):
img2[i,j] = (255-image[i,j][0],255-image[i,j][1],255-image[i,j][2])
return img2
https://blog.csdn.net/geyalu/article/details/50190121