opencv pictures change color according to rules

parse

1. Read in pictures

2.Channel separation

3. If the pixel value is between [100, 200], assign a value of 128. Values ​​greater than 200 are assigned a value of 255, and values ​​less than 100 are assigned a value of 0.

Source code

import cv2
img_raw_path="past/unet-test_result0-0-1-0.png"
img_raw=cv2.imread(img_raw_path)
(r,g,b)=cv2.split(img_raw)
r_copy=r.copy()
r_copy[ r_copy.any in range(100,200)]=128
r_copy[r_copy>200]=255
r_copy[r_copy<100]=0
cv2.imwrite("New/unet-test_result0-0-1-0.png",r_copy)

image display

The original picture is as follows.

After processing the picture, the gap becomes clear.

 

Guess you like

Origin blog.csdn.net/qq_41704436/article/details/131624328