5

以下に示すこれらの「斑点」のそれぞれに最小境界ボックスを合わせようとしています。画像処理パイプラインの一部として、findContours を使用してデータ内の輪郭を検出し、検出された輪郭の配列を指定して最小境界ボックスを描画します。

最小境界ボックスはあまり正確ではありません。一部のフィーチャは明らかに見落とされていますが、他のフィーチャは完全に接続されたフィーチャを完全に「カプセル化」できません (代わりに、いくつかの小さな最小境界ボックスに分割されます)。検索モード(以下に示す RETR_TREE) と輪郭近似方法(以下に示す CHAIN_APPROX_TC89_L1) をいじってみましたが、本当に気に入ったものを見つけることができませんでした。OpenCV Pythonを使用してこれらの輪郭をより正確にキャプチャするためのより堅牢な戦略を誰かが提案できますか?

画像1 画像2

import numpy as np
import cv2

# load image from series of frames
for x in range(1, 20):
    convolved = cv2.imread(x.jpg)
    original = convolved.copy

    #convert to grayscale   
    gray = cv2.cvtColor(convolved, cv2.COLOR_BGR2GRAY)

    #find all contours in given frame, store in array
    contours, hierarchy = cv2.findContours(gray,cv2.RETR_TREE, cv2.CHAIN_APPROX_TC89_L1)
    boxArea = []

    #draw minimum bounding box around each discovered contour
    for cnt in contours:
        area = cv2.contourArea(cnt)
        if area > 2 and area < 100:
            rect = cv2.minAreaRect(cnt)
            box = cv2.cv.BoxPoints(rect)
            box = np.int0(box)
            cv2.drawContours(original,[box], 0, (128,255,0),1)           
            boxArea.append(area)

    #save box-fitted image        
    cv2.imwrite('x_boxFitted.jpg', original)
    cv2.waitKey(0)

** 編集: Sturkman の提案によると、すべての可能な輪郭を描画すると、視覚的に検出可能なすべての機能がカバーされるように見えました。

ここに画像の説明を入力

4

2 に答える 2

2

質問がopencvに関するものであることは知っています。しかし、私は skimage に慣れているので、ここでいくつかのアイデア (これらは確かに opencv で利用可能です)。

import numpy as np
from matplotlib import pyplot as plt
from skimage import measure
from scipy.ndimage import imread
from skimage import feature
%matplotlib inline

'''
Contour detection using a marching square algorithm.
http://scikit-image.org/docs/dev/auto_examples/plot_contours.html
Not quite sure if this is the best approach since some centers are
biased. Probably, due to some interpolation issue.
'''

image = imread('irregular_blobs.jpg')
contours = measure.find_contours(image,25,
                                 fully_connected='low',
                                positive_orientation='high')
fig, ax = plt.subplots(ncols=1)
ax.imshow(image,cmap=plt.cm.gray)
for n, c in enumerate(contours):
    ax.plot(c[:,1],c[:,0],linewidth=0.5,color='r')

ax.set_ylim(0,250)
ax.set_xlim(0,250)
plt.savefig('skimage_contour.png',dpi=150)

輪郭検出

'''
Personally, I would start with some edge detection. For example,
Canny edge detection. Your Image is really nice and it should work.
'''
edges = feature.canny(image, sigma=1.5)
edges = np.asarray(edges)
# create a masked array in order to set the background transparent
m_edges = np.ma.masked_where(edges==0,edges)
fig,ax = plt.subplots()
ax.imshow(image,cmap=plt.cm.gray,alpha=0.25)
ax.imshow(m_edges,cmap=plt.cm.jet_r)


plt.savefig('skimage_canny_overlay.png',dpi=150)

キャニーエッジ検出

本質的に、「最善の方法」はありません。たとえば、エッジ検出は位置を非常によく検出しますが、一部の構造は開いたままです。一方、輪郭検出では閉じた構造が得られますが、中心は偏っています。パラメータをいじってみる必要があります。画像に邪魔な背景がある場合は、膨張を使用して背景を差し引くことができます。ここでは、拡張を実行する方法についていくつかの情報を示します。場合によっては、閉じる操作も役立ちます。

投稿された画像から、しきい値が高すぎるか、背景がうるさすぎるようです。しきい値および/または拡張を下げると役立つ場合があります。

于 2015-12-29T09:04:33.300 に答える
0

Moritz が提案したように、SimpleBlobDetectorを試してみることをお勧めします。

さまざまなオプションを試してみると、おそらく問題に適した設定が見つかるでしょう。

于 2015-12-29T07:37:00.153 に答える