在白色图像上识别线/点丢弃图案

发布于 2025-01-29 22:28:57 字数 1010 浏览 3 评论 0原文

我正在研究计算机视觉,并且有一个图像,如下所示:

“

我想识别组织上的黑线。我尝试了以下代码,

import cv2
img = cv2.imread('image.png')
# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# do morphology gradient
kernel = cv2.getStructuringElement(cv2.MORPH_RECT , (3,3))
morph = cv2.morphologyEx(gray, cv2.MORPH_GRADIENT, kernel)

# apply gain
morph = cv2.multiply(morph, 10)
morph=cv2.resize(morph, (1000, 552))
imgStack = stackImages(0.5, ([img ], [morph]))
cv2.imshow('Stacked Images', imgStack)
cv2.waitKey(0)

上面的代码行给出了:

“

如我们所见,现有模式占上风,很难识别该行。如何丢弃真实的模式并识别无元。

我确实尝试了Stackoverflow中的其他答案,但是似乎没有任何作用

I'm working on computer vision and I have an image as shown below:

tissue

I want to identify the black line on the tissue. I have tried the following code

import cv2
img = cv2.imread('image.png')
# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# do morphology gradient
kernel = cv2.getStructuringElement(cv2.MORPH_RECT , (3,3))
morph = cv2.morphologyEx(gray, cv2.MORPH_GRADIENT, kernel)

# apply gain
morph = cv2.multiply(morph, 10)
morph=cv2.resize(morph, (1000, 552))
imgStack = stackImages(0.5, ([img ], [morph]))
cv2.imshow('Stacked Images', imgStack)
cv2.waitKey(0)

the above line of code gives:

outputimage

As we can see, the existing pattern prevails and it is difficult to identify the line. How to discard the true pattern and identify the anamolies.

I did try the other answers in stackoverflow, but nothing seem to work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世态炎凉 2025-02-05 22:28:57

关于评论,我建议应用全局阈值cv2.threshold()

代码:

img = cv2.imread(r'C:\Users\524316\Desktop\Stack\tissue.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
threshold_value = 20
th = cv2.threshold(gray, threshold_value, 255, cv2.THRESH_BINARY_INV)[1]
cv2.imshow(cv2.hconcat([gray, th]))
cv2.waitKey(0)

结果:

注意到黑线突出显示,而没有其他图案受到影响。

In reference to the comments, I was suggesting to apply global threshold cv2.threshold():

Code:

img = cv2.imread(r'C:\Users\524316\Desktop\Stack\tissue.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
threshold_value = 20
th = cv2.threshold(gray, threshold_value, 255, cv2.THRESH_BINARY_INV)[1]
cv2.imshow(cv2.hconcat([gray, th]))
cv2.waitKey(0)

Result:

enter image description here

Notice the black line highlighted while no other patterns are affected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文