简体   繁体   中英

How can I detect rocks in this image using OpenCV (python)?

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.

在此输入图像描述

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.

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

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.

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

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.

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:

  1. Preprocessing to filter out noise outliers - median
  2. Maybe use a 2-d band pass filter to sort out rocks of a certain caliber.
  3. Use the edge detection you did - seems to have done an excellent job.
  4. Use algorithms that can identify clusters out of your vertices
  5. Combine points or vertices in your cluster using convex hull or 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM