Color reversal image python-opencv-

The image is composed of pixels one by one, each pixel in turn a different color values ​​(for the OpenCV bgr mode), where each color channel values ​​are 0-255. 

The so-called reversal color image, each color channel is the primary channel minus the value 255, to give a new color channel values, and then reassembled into new bgr generate new pixel color channels to form a new image. To take an extreme example, such as a pure white pixel point value (255,255,255), the new pixel after it is reversed and changed color formed is (0,0,0), which is turned into a pure black pixels.

 

Grayscale image color inversion:

Import CV2
 Import numpy AS NP 

IMG = cv2.imread ( " 3.jpg " , 0)   # reading an image, the gradation 
height, width = img.shape 
DST = np.zeros ((height, width,. 1 ), np.uint8)
 for I in Range (height):
     for J in Range (width): 
        DST [I, J] = 255- IMG [I, J] 

cv2.imshow ( ' IMG ' , IMG) 
cv2.imshow ( ' DST ' , DST) 
cv2.waitKey ()   # window wait for any keyboard key input, 0 waits for the other digital milliseconds

Renderings:

 

Bgr image color image is reversed:

For bgr image, we need to b (blue), g (green), r (red) three color channels for processing. First, we still use imread () function reads the original image data and acquires the properties related image using the shape information, and then traversing pixels, the grayscale difference is, we need to b, g, r while the three color channels 255 minus the processing done with the current color channel values, and then form a new bgr value is assigned to pixels, thereby realizing a color image bgr inverted image.

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/liming19680104/p/12220566.html