以下の画像とコードは、私が実行している実験を反映したおもちゃの例です。 私はHoughCircles
手順を用いて、画素強度が(この例では青みがかったディスク)と同じ又は類似している画像における境界近傍ピクセルの強度を解析してディスクを描画する
に対応するディスクを抽出したいと思い、私が最も可能性の円の中心を抽出することができます画像の そこから、検出された中心からの様々な半径(より高いまたはより低い)の中心から360°をプローブして、下の画像の青みがかった色の境界(最大半径および最小半径)を定義したいと考えています。
どうすればいいですか? 私は成功しないで複数のマスクを適用することによってヒストグラムを分析しようとします。 緑色の円はHoughCircles
で検出されたもので、青色と赤色の円は+/- 15%の半径の円です。
import cv2
import numpy as np
from matplotlib import pyplot as plt
image = cv2.imread("./picture.jpg")
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 2, 800,
param1=300,
param2=1,
minRadius=100,
maxRadius=0)
if circles is not None:
# convert the (x, y) coordinates and radius of the circles to integers
circles = np.round(circles[0, :]).astype("int")
output = image.copy()
# loop over the (x, y) coordinates and radius of the circles
for (x, y, r) in circles:
# draw the circle in the output image, then draw a rectangle
# corresponding to the center of the circle
cv2.circle(output, (x, y), r, (0, 255, 0), 2)
cv2.rectangle(output, (x - 2, y - 2), (x + 2, y + 2), (0, 128, 255), -1)
# create the mask and explore histograms
# height,width,depth = output.shape
# mask = np.zeros((height,width), np.uint8)
# cv2.circle(mask, (x, y), int(round(r - (r* .15))), 1, thickness=-1)
# output = cv2.bitwise_and(output, output, mask=mask)
# hist_full = cv2.calcHist([output],[0],None,[256],[0,256])
# hist_mask = cv2.calcHist([output],[0],mask,[256],[0,256])
# plt.hist(image.ravel(),256,[0,256]); plt.show()
# plt.plot(hist_full),
# plt.plot(hist_mask)
# plt.xlim([0,256])
# plt.show()
cv2.circle(output, (x, y), int(round(r * 1.15)), (255, 0, 0), 2)
cv2.circle(output, (x, y), int(round(r - (r* .15))), (0, 0, 255), 2)
# show the output image
cv2.imshow("output", np.hstack([image, output]))
cv2.waitKey(0)
私の英語が悪いので、私はあなたの目的だものを手に入れることができない...あなたは「全体」ディスク、または何を取得したいですか? – Silencer
はいグレーの部分ではなく、青い部分からディスクを抽出したいです。 – Michael
私はこのように "ディスク"を分離しようとします:https://i.stack.imgur.com/B7kT6.jpg – Silencer