python hog特征提取,直接从原始图像的HoG特征提取编辑图像的HoG特征
我有很多图像,我从中提取了HoG特征并保存了它们。在
我现在已经丢失了图像,很明显那是我在机器出故障之前没有备份过的数据集。在
但是我有包含这些图像的HoG特征的文件。在
如果我现在有图像,我会对图像应用剪切和旋转来创建更多的示例,然后获取这些编辑图像的HoG特征。在
但既然我没有图像。。。有没有可能只处理原稿的HoG特征,以获得编辑后的HoG特征?在
这是我用来编辑图像的代码,如果我还有图像的话,我会从中提取HoG特征用于对象分类:import numpy as np
from skimage import data, io, filter, color, exposure
from skimage.feature import hog
import skimage.transform as tf
from skimage.transform import resize, rescale, rotate, setup, warp, AffineTransform
import matplotlib.pyplot as plt
import os
from os import listdir
from os.path import isfile, join
import pickle
import Image
def generateSamples(path, readfile):
print "generating samples from " + path+"\\"+readfile
img = color.rgb2gray(io.imread(path+"\\"+readfile))
img = resize(img, (50,100))
filename = os.path.splitext(readfile)[0]
angles = [3, 0, -3]
shears = [0.13, 0.0, -0.13]
i = 0
no_samples = len(angles) * len(shears)
samples = np.empty((no_samples, int(img.shape[0]), int(img.shape[1])), dtype=object)
for myangle in angles:
myimg = rotate(img, angle=myangle, order=2)
for myshear in shears:
afine_tf = tf.AffineTransform(shear=myshear)
mymyimg = tf.warp(myimg, afine_tf)
samples[i] = np.array(mymyimg)
i+=1
#io.imshow(mymyimg)
#io.show()
newfile = filename + "_samples.vec"
pickle.dump(samples, file(path+"\\"+newfile,'w'))
print "saved vec file"