简体   繁体   中英

How can i convert a grayscale image to a binary image in python with loops?

I want to convert an grayscale image to binary without using threshold methods.I can reach all the pixels of the image with the code below but i dont know how to convert the pixel colours accordingly.Can you help me?

import cv2


img=cv2.imread('rose.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

height=img.shape[0]
print("h=",h)
width=img.shape[1]
print("w=",w)  

for i in range(height):
    for j in range(width):
        k=img[i,j]
        print(k)

I want to convert an grayscale image to binary without using threshold methods.I can reach all the pixels of the image with the code below but i dont know how to convert the pixel colours accordingly.Can you help me?

import cv2


img=cv2.imread('rose.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

height=img.shape[0]
print("h=",h)
width=img.shape[1]
print("w=",w)  

for i in range(height):
    for j in range(width):
        k=img[i,j]
        print(k)

I want to convert an grayscale image to binary without using threshold methods.I can reach all the pixels of the image with the code below but i dont know how to convert the pixel colours accordingly.Can you help me?

import cv2


img=cv2.imread('rose.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

height=img.shape[0]
print("h=",h)
width=img.shape[1]
print("w=",w)  

for i in range(height):
    for j in range(width):
        k=img[i,j]
        print(k)

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