如何在 OpenCV 中将图像的总和除以图像总数

  • 本文关键字:图像 OpenCV python opencv
  • 更新时间 :
  • 英文 :


我正在尝试使用OpenCV(python(重现研究论文的这一部分的代码大纲:

我对面具的结果看起来与论文中的内容完全不同。 你可以在这里看到我的结果,或者只是运行下面的python:binary_reference_coin_mask,平均梯度图,mean_threshold_image - 没有阈值的反比,它看起来像这样。

我可能没有适当地划分(divide(( 似乎不适合这样做,因为我没有除以数组(或解释正确编码算法的方式。 我认为它告诉我将拉普拉斯数组除以数组总数的总和,然后将其添加到阈值数组的总和除以数组总数。

下面的蟒蛇是(拉普拉斯之和(除以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)

为什么要除以 i ? ->/i 添加像素 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

最新更新