小编hol*_*boy的帖子

我想使用 python 对图像中的像素应用阈值。我哪里做错了?

我想生成作为阈值的输出。还有我的错误:

img_thres = n_pix[y, x]
TypeError: 'int' 对象不可下标

import cv2
import numpy as np
import matplotlib as plt

img = cv2.imread("cicek.png",0)
img_rgb = cv2.imread("cicek.png")

h = img.shape[0]
w = img.shape[1]

img_thres= []
n_pix = 0
# loop over the image, pixel by pixel
for y in range(0, h):
    for x in range(0, w):
        # threshold the pixel
        pixel = img[y, x]
        if pixel < 0.5:
            n_pix = 0
        img_thres = n_pix[y, x]

cv2.imshow("cicek", img_thres)
Run Code Online (Sandbox Code Playgroud)

python image image-processing threshold image-thresholding

1
推荐指数
1
解决办法
8227
查看次数