【问题标题】:Feature extraction and take color histogram特征提取并取颜色直方图
【发布时间】:2019-02-08 18:15:01
【问题描述】:

我正在研究图像处理特征提取。我有一张鸟的照片,我必须在其中提取鸟类区域并告诉鸟的颜色。我使用精明的特征提取方法来获取鸟的边缘。

如何只提取鸟类区域并将背景设为蓝色?

openCv 解决方案也应该没问题。

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)

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

实拍鸟图可取自bird link

【问题讨论】:

  • 问题是什么?
  • 我想从图像中提取鸟,然后创建鸟颜色的直方图@desertnaut
  • 背景是否总是模糊不清或颜色大致一致?
  • 背景颜色统一,但可以是任何颜色@SilverMonkey
  • 尝试使用normalized-cut 分割图像,然后使用与 Canny 找到的边缘图重叠的标签。这样,您可以准备一个前景蒙版,从中提取您感兴趣的像素,以计算直方图。如果您只想为背景着色,可以使用前景蒙版轻松完成。

标签: python opencv image-processing scikit-learn scikit-image


【解决方案1】:
  1. Identify the edges你的图片

  2. Binarize the image 通过自动阈值处理

  3. 使用contour detection 识别黑色区域which are inside a white region 并将它们与白色区域合并。 (样机,图片可能略有不同)

  4. 使用创建的图像作为蒙版为背景着色并着色 这可以通过简单地将每个背景像素(黑色)设置为其各自的颜色来完成。

如您所见,该方法远非完美,但应该让您大致了解如何完成任务。最终的图像质量可能会通过略微侵蚀地图以将其收紧到鸟的轮廓来提高。然后,您还可以使用遮罩通过仅考虑前景像素来计算颜色直方图。 编辑:看这里:

  1. Eroded mask

  1. 最终图像

【讨论】:

  • 我正在阅读 OpenCV 并从 step-1 开始,你能帮我一些示例代码吗?
  • 我个人不使用OpenCV,所以只能收集每个步骤各自的方法。
  • 我认为对一个未指定的问题的回答非常好。请记住,识别和分割照片中的鸟是非常非常困难的,因此这种方法几乎可以获取任何物体的直方图,无论是否有鸟。如果这对 OP 来说还不够好,他们需要重新表述问题。
  • 这个解释很好,我正在阅读opencv并正在尝试。如果有人知道 opencv 可以发布代码
【解决方案2】:

据本文https://www.pyimagesearch.com/2016/04/11/finding-extreme-points-in-contours-with-opencv/ 还有这个问题CV - Extract differences between two images

我写了一些python代码如下。正如我的前任所说,它也远非完美。该代码的主要缺点是需要手动设置常量值:minThres(50)、maxThres(100)、dilate 迭代次数和 erode 迭代次数。

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)

【讨论】:

    猜你喜欢
    • 2012-08-15
    • 2019-12-14
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多