从numpy中的2d图像中提取特征向量 [英] Extract feature vector from 2d image in numpy
问题描述
我有一系列两种类型的2d图像,分别是星形或五边形.我的目的是分别对所有这些图像进行分类.我有30个星图和30个五边形图.每个图像的示例在此处并排显示:
I have a series of 2d images of two types, either a star or a pentagon. My aim is to classify all of these images respectively. I have 30 star images and 30 pentagon images. An example of each image is shown side by side here:
在应用KNN分类算法之前,我需要从所有图像中提取特征向量.特征向量必须全部具有相同的大小,但是2d图像的大小都不同.我提取了图像中的read,然后得到一个带有零和一的2d数组.
Before I apply the KNN classification algorithm, I need to extract a feature vector from all the images. The feature vectors must all be of the same size however the 2d images all vary in size. I have extracted read in my image and I get back a 2d array with zeros and ones.
image = pl.imread('imagepath.png')
我的问题是如何处理image
,以便产生有意义的特征向量,其中包含足以让我进行分类的信息.每个图像必须是一个向量,我将用于训练和测试.
My question is how do I process image
in order produce a meaningful feature vector that contains enough information to allow me to do the classification. It has to be a single vector per image which I will use for training and testing.
推荐答案
如果要使用opencv,则:
If you want to use opencv then:
将图像调整为标准尺寸:
Resize images to a standard size:
import cv2
import numpy as np
src = cv2.imread("/path.jpg")
target_size = (64,64)
dst = cv2.resize(src, target_size)
转换为一维矢量:
dst = dst.reshape(target_size.shape[0] * target_size.shape[1])
这篇关于从numpy中的2d图像中提取特征向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!