【发布时间】:2019-05-03 18:07:52
【问题描述】:
我要做的是在 Python 中使用 opencv 识别图片中的涟漪。我只是在学习这个图书馆,所以我不知道图书馆里的所有怪癖。我做了一些研究,但找不到与这个类似的问题,这个特别困难,因为涟漪会产生阴影。我的预期结果应该与此相反,使所有的涟漪都比其他功能更突出。下面是一个男人的照片,他的头发是突出的特征。我想对下面沙丘中的涟漪做同样的事情。
以下代码是我下面的代码,这是我最终产品的输出,但仍需要一些工作。
path = "C:/some path//to get//to my picture//Dune field_resize.jpg"
# image I'm using
img = cv2.imread ( path , cv2.IMREAD_GRAYSCALE )
kernel = np.ones ( (5 , 5) , np.uint8 )
# Canny edge detecting
edges = cv2.Canny ( img , 75 , 200 )
th , img = cv2.threshold ( img , 220 , 255 , cv2.THRESH_BINARY_INV );
# Copy the thresholded image.
img_floodfill = img.copy ()
# Mask used to flood filling.
# Notice the size needs to be 2 pixels than the image.
h , w = img.shape[:2]
mask = np.zeros ( (h + 2 , w + 2) , np.uint8 )
# Floodfill from point (0, 0)
cv2.floodFill ( img_floodfill , mask , (0 , 0) , 255 );
# Invert floodfilled image
img_floodfill_inv = cv2.bitwise_not ( img_floodfill )
# Combine the two images to get the foreground.
img_out = img | img_floodfill_inv
# Display images.
cv2.imwrite ( "Thresholded Image.png" , img )
cv2.imwrite ( "Floodfilled Image.png" , img_floodfill )
cv2.imwrite ( "Inverted Floodfilled Image.png" , img_floodfill_inv )
cv2.imwrite ( "Foreground.png" , img )
cv2.waitKey ( 0 )
cv2.imwrite ( "canny_edge.png" , edges )
img_erosion = cv2.erode ( img , kernel , iterations=1 )
cv2.waitKey ( 0 )
cv2.destroyAllWindows ()
【问题讨论】:
-
这是一个有趣的问题。但是,目前还不清楚预期的输出是什么。您能否编辑您的问题,提供有关您期望结果的更多详细信息?
-
刚刚添加了更多细节,希望它更有意义。
-
您似乎正在检测阴影。反转你的结果怎么样?
-
我同意,如果您可以发布一些内容(甚至是草图)来显示您想要的输出类型,那将会很有帮助。如果你不能,那么我建议查看 Haralick 纹理(还有其他纹理属性)。如果您对完全不同的方法持开放态度,那么您应该知道现在很多人都在用深度学习来解决这样的问题(例如,用于图像分割问题的 U-Net,看起来就像这样)。但这需要训练数据...
标签: python image numpy opencv image-processing