小编Bms*_*waj的帖子

将叶子与背景分开

我有一组图像,所有这些图像看起来几乎都像这里的这片叶子:

低分辨率图像...

我想从背景中提取叶子,为此我使用了此处GrabCut使用的算法。

作为一种不同的方法,我还使用基于 r、g 和 b 值比率的阈值,如下所示:

import numpy as np
import cv2
import matplotlib.pyplot as plt

testImg = cv2.imread('path_to_the_image')
testImg = cv2.resize(testImg, (256, 256))
#bgImg = cv2.imread('')
#blurBg = cv2.GaussianBlur(bgImg, (5, 5), 0)
#blurBg = cv2.resize(blurBg, (256, 256))

#testImg = cv2.GaussianBlur(testImg, (5, 5), 0)
cv2.imshow('testImg', testImg)
#plt.imshow(bgImg)
cv2.waitKey(0)
#plt.show()

modiImg = testImg.copy()    
ht, wd = modiImg.shape[:2]

print(modiImg[0][0][0])

for i in range(ht):
    for j in range(wd):
        r = modiImg[i][j][0]
        g = modiImg[i][j][1]
        b = modiImg[i][j][2]

        r1 = …
Run Code Online (Sandbox Code Playgroud)

python opencv image-processing python-3.x background-subtraction

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