web-dev-qa-db-ja.com

特徴抽出と色ヒストグラムの取得

画像処理機能の抽出に取り組んでいます。私は鳥の写真を撮っており、その中で鳥の領域を抽出し、鳥の色を教えなければなりません。私は鳥のエッジを取得するためにキャニーフィーチャ抽出方法を使用しました。

鳥の領域のみを抽出し、背景を青色にする方法は?

openCvソリューションも問題ないはずです。

enter image description here

import skimage
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt

import os
filename = os.path.join(os.getcwd(),'image\image_bird.jpeg')
from skimage import io
bird =io.imread(filename,as_grey=True)
plt.imshow(bird)

enter image description here

from skimage import feature
edges = feature.canny(bird,sigma=1)
plt.imshow(edges )

enter image description here

実際の鳥の画像は bird link から取得できます

20
Sumeet
  1. エッジの特定 画像の Sobel Edge map

  2. 画像の二値化 自動しきい値処理経由 binarized Edge map

  3. 輪郭検出 を使用して黒い領域を識別します 白い領域内にあります を使用して、白い領域とマージします。 (モックアップ、画像は若干異なる場合があります) Mockup of the merged mask

  4. 作成した画像をマスクとして使用して、背景に色を付けて色を付けます final image これは、各背景ピクセル(黒)をそれぞれの色に設定するだけで実行できます。

ご覧のとおり、このアプローチは完璧とはほど遠いですが、タスクを達成する方法についての一般的なアイデアを提供するはずです。最終的な画像品質は、マップを少し浸食して鳥の輪郭に合わせることで改善される場合があります。次に、マスクを使用して、前景ピクセルのみを考慮してカラーヒストグラムを計算します。編集:こちらをご覧ください:

  1. 侵食されたマスク

eroded mask

  1. 最終画像

Final image with eroded mask

22
SilverMonkey

この記事によると https://www.pyimagesearch.com/2016/04/11/finding-extreme-points-in-contours-with-opencv/ とこの質問 CV- 2つの画像の違いを抽出する

以下のようにいくつかのpythonコードを書きました。前任者が言ったように、これも完璧にはほど遠いです。このコードの主な欠点は、手動で設定する定数値です:minThres(50)、maxThres(100) 、反復回数を拡張し、反復回数を侵食します。

import cv2
import numpy as np

windowName = "Edges"
pictureRaw = cv2.imread("bird.jpg")

## set to gray
pictureGray = cv2.cvtColor(pictureRaw,  cv2.COLOR_BGR2GRAY)

## blur
pictureGaussian = cv2.GaussianBlur(pictureGray, (7,7), 0)

## canny Edge detector - you must specify threshold values
pictureCanny = cv2.Canny(pictureGaussian, 50, 100)

## perform a series of erosions + dilations to remove any small regions of noise
pictureDilate = cv2.dilate(pictureCanny, None, iterations=20)
pictureErode = cv2.erode(pictureDilate, None, iterations=5)

## find the nozero regions in the erode
imask2 = pictureErode>0

## create a Mat like pictureRaw
canvas = np.full_like(pictureRaw, np.array([255,0,0]), dtype=np.uint8)

## set mask 
canvas[imask2] = pictureRaw[imask2]
cv2.imwrite("result.png", canvas)
7
ElConrado