我想将图片准确地转换为黑白图像,其中种子将由白色表示,背景为黑色。我想把它放在 python opencv 代码中。请帮帮我
I got good result for the above picture using the given code below. Now I have another picture for which thresholding doesn't seem to work. How can I tackle this problem. The output i got is in the following picture
also, there are some dents in the seeds, which the program takes it as the boundary of the seed which is not a good results like in the picture below. How can i make the program ignore dents. Is masking the seeds a good option in this case.
我将图像从 BGR 颜色空间转换为 HSV 颜色空间。
然后我提取了hue渠道:
然后我对其执行了阈值:
Note:
每当您在某些领域遇到困难时,请尝试在不同的色彩空间中工作,其中 HSV 色彩空间最为突出。
UPDATE:
这是代码:
import cv2
import numpy as np
filename = 'seed.jpg'
img = cv2.imread(filename) #---Reading image file---
hsv_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV) #---Converting RGB image to HSV
hue, saturation, value, = cv2.split(hsv_img) #---Splitting HSV image to 3 channels---
blur = cv2.GaussianBlur(hue,(3,3),0) #---Blur to smooth the edges---
ret,th = cv2.threshold(blur, 38, 255, 0) #---Binary threshold---
cv2.imshow('th.jpg',th)
现在您还可以执行轮廓操作来突出显示您感兴趣的区域。试试看!! :)
另一个更新:
我发现轮廓高于某个约束来得到这个:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)