如何将opencv中的图像总数除以图像总数

2024-06-02 04:48:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图使用OpenCV(python)从this segment of a research paper复制代码大纲:

我的面具结果和报纸上的完全不一样。您可以在这里看到我的结果,或者只运行下面的python:binary_reference_coin_maskmean gradient mapmean_threshold_image——如果没有阈值反转,它看起来像this

我可能没有进行适当的除法(divide()似乎不适合于此,因为我没有被数组除法)或解释正确编码算法的方法。我想这是在告诉我拉普拉斯数组的和除以数组总数,然后把它加到阈值数组的和除以数组总数

下面的python是(拉普拉斯之和)除以n+(大津阈值之和)除以n的正确解释吗?

import cv2
import numpy as np
from skimage import io
import copy

urls = [
    "https://coinmodel.s3.amazonaws.com/69.jpg", 
    "https://coinmodel.s3.amazonaws.com/68.jpg",
    "https://coinmodel.s3.amazonaws.com/67.jpg",
    "https://coinmodel.s3.amazonaws.com/66.jpg",
    "https://coinmodel.s3.amazonaws.com/65.jpg",
    "https://coinmodel.s3.amazonaws.com/64.jpg",
    "https://coinmodel.s3.amazonaws.com/63.jpg",
    "https://coinmodel.s3.amazonaws.com/62.jpg",
]

i = 0
ddepth = cv2.CV_16S
#ddepth = cv2.CV_8U
kernel_size = 3

for url in urls:
    img = io.imread(url)    
    img_blur = cv2.GaussianBlur(img, (3, 3), 0)
    img_bgrL = cv2.cvtColor(img_blur, cv2.COLOR_BGR2GRAY)
    img_bgrT = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    imgL = cv2.Laplacian(img_bgrL, ddepth, ksize=kernel_size)    
    ret, imgT = cv2.threshold(img_bgrT, 0, 255, cv2.THRESH_OTSU)
    if i != 0:
        Laplacian_sum = cv2.add(imgL, imgL_last)
        Threshold_sum = cv2.add(imgT, imgT_last)
    imgL_last = copy.copy(imgL) 
    imgT_last = copy.copy(imgT)
    i=i+1    
    
mean_gradient_map = Laplacian_sum / i
mean_threshold_image = Threshold_sum / i
binary_reference_coin_mask = cv2.add(mean_gradient_map, mean_threshold_image)

cv2.imshow("Laplacian mean", mean_gradient_map)
cv2.imshow("Threshold mean", mean_threshold_image)
cv2.imshow("binary_reference_coin_mask", binary_reference_coin_mask)

cv2.waitKey(0)

Tags: httpscomimgthresholds3数组meancv2
1条回答
网友
1楼 · 发布于 2024-06-02 04:48:20

我为什么要分开-&燃气轮机/我添加像素RGB[255]+[255]=[255]

mean_gradient_map = Laplacian_sum
mean_threshold_image = Threshold_sum
#ret, imgT = cv2.threshold(img_bgr, 200, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
ret, imgT = cv2.threshold(img_bgr, 100, 255, cv2.THRESH_BINARY)

height, width = img_bgr.shape
if i != 0:
        Laplacian_sum = cv2.add(imgL, imgL_last)
        Threshold_sum = cv2.add(imgT, imgT_last)
        for y in range(height):
            for x in range(width):
                Laplacian_sum[y,x] = Laplacian_sum[y,x]/2

这是像素RGB/2

numpy像素img RGB结果添加/n

相关问题 更多 >