什么是负片?
负片是经曝光和显影加工后得到的影像,其明暗与被摄体相反,其色彩则为被摄体的补色,它需经印放在照片上才还原为正像。我们平常所说的用来冲洗照片的底片就是负片。
python
"""
将彩色图像转换成负片
"""
from cv2 import destroyAllWindows, imread, imshow, waitKey
def convert_to_negative(img):
# 获取图像中的像素数量
pixel_h, pixel_v = img.shape[0], img.shape[1]
# converting each pixel's color to its negative
for i in range(pixel_h):
for j in range(pixel_v):
img[i][j] = [255, 255, 255] - img[i][j]
return img
if __name__ == "__main__":
# 读取原始图像
img = imread("image_data/test.jpg", 1)
# 转换
neg = convert_to_negative(img)
# 展示处理后的图像
imshow("negative of original image", img)
waitKey(0)
destroyAllWindows()
图像处理前:
图像处理后: