如何使用OpenCV(python)检测此图像中的岩石?

时间:2021-11-26 23:15:40

I am trying to find the differently shaped rocks in this image.

我试图在这张图片中找到不同形状的岩石。

image http://mars.nasa.gov/mer/gallery/all/2/n/1850/2N290598950EDNB0F8F0006L0M1.JPG

I didn't get any satisfactory results from edge detection.

我没有从边缘检测中得到任何令人满意的结果。

如何使用OpenCV(python)检测此图像中的岩石?

I did read about grabcut but again nothing satisfactory from that either. Any ideas on how I should proceed?

我确实读过关于抓取的但是再一次没有令人满意的。关于我应该如何进行的任何想法?

PS - My ultimate goal is to mark these rocks in the image with a different color.

PS - 我的最终目标是用不同的颜色标记图像中的这些岩石。

UPDATE 1: Here is the code that I used for edge detection.

更新1:这是我用于边缘检测的代码。

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

img = cv2.imread('image1.JPG',0)
edges = cv2.Canny(img,255,255)

plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])

plt.show()

UPDATE 2: I have a couple of similar images like the one below in which the rocks (big in size) are clearly visible. Edge detection is again producing unsatisfactory results on the image. I am just looking for approaches which I can try. If you suggest an approach then please add the relevant links where I can read up more, I am new to opencv.

更新2:我有几个类似的图像,如下图所示,其中岩石(大尺寸)清晰可见。边缘检测再次在图像上产生不令人满意的结果。我只是在寻找可以尝试的方法。如果你建议一种方法,请添加相关链接,我可以阅读更多,我是opencv的新手。

http://mars.nasa.gov/mer/gallery/all/2/p/2190/2P320875706EFFB27MP2400L5M5-BR.JPG

2 个解决方案

#1


2  

The rocks are segments of the image that are more plain than the sand pieces. You could try to get each line of the file, divide it in small segments, and compute the Kurtosis of the segment.

岩石是图像的一部分,比沙子更平坦。您可以尝试获取文件的每一行,将其划分为小段,并计算段的峰度。

The Kurtosis is a measure of the "height" and "width" of the bell-curve of frequencies of values in the segment. Sand will have significantly lower Kurtosis than the Rocks, since it has a "broader" spectrum of frequencies. Segments with high Kurtosis will likely belong to rocks.

峰度是对段中值的频率的钟形曲线的“高度”和“宽度”的度量。由于它具有“更广泛”的频谱范围,因此沙子的峰度将明显低于岩石。具有高峰度的区段可能属于岩石。

So it will be a matter of determining the ideal length of the segments that each line of the image will have to be divided into. Not a trivial task, but not a hard one either. Half the width of the smallest rock you want to identify (but at least 100 times the width of a grain of sand) should do the trick.

因此,确定图像的每一行必须被分成的段的理想长度是一个问题。这不是一项微不足道的任务,但也不是一项艰巨的任务。你要识别的最小岩石宽度的一半(但至少是一粒沙子宽度的100倍)应该可以解决问题。

#2


0  

From a 2- d picture ... Really challenging. I bet using 2 pictures with an offset is how it can be done much easier processed as a stereoscopic image. Lagging that, I would suggest following strategies:

从二维照片......真的很有挑战性。我打赌使用2张偏移的图片是如何做得更容易处理为立体图像。滞后,我建议遵循以下策略:

  1. Preprocessing to filter out noise outliers - median
  2. 预处理以滤除噪声异常值 - 中位数

  3. Maybe use a 2-d band pass filter to sort out rocks of a certain caliber.
  4. 也许使用2维带通滤波器来挑选出某种口径的岩石。

  5. Use the edge detection you did - seems to have done an excellent job.
  6. 使用您所做的边缘检测 - 似乎做得非常出色。

  7. Use algorithms that can identify clusters out of your vertices
  8. 使用可以识别顶点之外的群集的算法

  9. Combine points or vertices in your cluster using convex hull or voronoi.
  10. 使用凸包或voronoi组合群集中的点或顶点。

That being said, I doubt that this forum is suitable to seek an answer to your question, as it is very hard to provide a straight forward answer using coding.

话虽如此,我怀疑这个论坛是否适合寻找你的问题的答案,因为很难用编码提供直截了当的答案。

#1


2  

The rocks are segments of the image that are more plain than the sand pieces. You could try to get each line of the file, divide it in small segments, and compute the Kurtosis of the segment.

岩石是图像的一部分,比沙子更平坦。您可以尝试获取文件的每一行,将其划分为小段,并计算段的峰度。

The Kurtosis is a measure of the "height" and "width" of the bell-curve of frequencies of values in the segment. Sand will have significantly lower Kurtosis than the Rocks, since it has a "broader" spectrum of frequencies. Segments with high Kurtosis will likely belong to rocks.

峰度是对段中值的频率的钟形曲线的“高度”和“宽度”的度量。由于它具有“更广泛”的频谱范围,因此沙子的峰度将明显低于岩石。具有高峰度的区段可能属于岩石。

So it will be a matter of determining the ideal length of the segments that each line of the image will have to be divided into. Not a trivial task, but not a hard one either. Half the width of the smallest rock you want to identify (but at least 100 times the width of a grain of sand) should do the trick.

因此,确定图像的每一行必须被分成的段的理想长度是一个问题。这不是一项微不足道的任务,但也不是一项艰巨的任务。你要识别的最小岩石宽度的一半(但至少是一粒沙子宽度的100倍)应该可以解决问题。

#2


0  

From a 2- d picture ... Really challenging. I bet using 2 pictures with an offset is how it can be done much easier processed as a stereoscopic image. Lagging that, I would suggest following strategies:

从二维照片......真的很有挑战性。我打赌使用2张偏移的图片是如何做得更容易处理为立体图像。滞后,我建议遵循以下策略:

  1. Preprocessing to filter out noise outliers - median
  2. 预处理以滤除噪声异常值 - 中位数

  3. Maybe use a 2-d band pass filter to sort out rocks of a certain caliber.
  4. 也许使用2维带通滤波器来挑选出某种口径的岩石。

  5. Use the edge detection you did - seems to have done an excellent job.
  6. 使用您所做的边缘检测 - 似乎做得非常出色。

  7. Use algorithms that can identify clusters out of your vertices
  8. 使用可以识别顶点之外的群集的算法

  9. Combine points or vertices in your cluster using convex hull or voronoi.
  10. 使用凸包或voronoi组合群集中的点或顶点。

That being said, I doubt that this forum is suitable to seek an answer to your question, as it is very hard to provide a straight forward answer using coding.

话虽如此,我怀疑这个论坛是否适合寻找你的问题的答案,因为很难用编码提供直截了当的答案。