简体   繁体   English

如何使用循环将灰度图像转换为 python 中的二进制图像?

[英]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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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