简体   繁体   中英

How to make white pixel values black by keeping rest of pixel value as it it from an image

i have an gray scale image which is showing black background, white leaf and some other color disease spots on it. What i want to do make white portion into black and making other than black and white pixels color into white.

在此处输入图像描述

img2 = cv2.imread('binary.jpeg')
binarr = np.where(img3 < 255 or img3 > 0, keep as it is, else make it 0)
plt.imshow(binarr)

but this seem like not supported by python.

any other suggestion to do this?

I labelled your question for numpy so you may get a better answer, also it is not clear what data type cv2.imread() actually returns so I've made an assumption it could be a list in which case:

binarr = [0 if pixel == 255 else 255 for pixel in img]

ie:

>>> img = [0,255,0,255,158]
>>> binarr = [0 if pixel == 255 else 255 for pixel in img]
>>> binarr
[255, 0, 255, 0, 255]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM