我有许多图像,我从中提取出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"