我想增加MNIST手写数字数据集。
为了做到这一点,我想为每个图像分别创建一个弹性变形图像。
我在这上读到了第二节“通过弹性变形扩展数据集”,它们实现了弹性变形。
在此之前:

之后:

我试过:
http://www.mathworks.com/help/images/ref/imwarp.html http://www.mathworks.com/help/images/examples/creating-a-gallery-of-transformed-images.html
百无所成。
我怎样才能在MATLAB中做到这一点?
如何在MATLAB中对图像进行变换
发布于 2016-09-06 12:13:21
我不确定我完全遵循了位移场的“归一化”方法,但我认为这能让你离得很近
img = imread('http://deeplearning.net/tutorial/_images/mnist_2.png'); %// get a digit计算随机位移场dx~U(-1,1),dy~U(-1,1)
dx = -1+2*rand(size(img));
dy = -1+2*rand(size(img)); 使该领域平滑和正常化:
sig=4;
alpha=60;
H=fspecial('gauss',[7 7], sig);
fdx=imfilter(dx,H);
fdy=imfilter(dy,H);
n=sum((fdx(:).^2+fdy(:).^2)); %// norm (?) not quite sure about this "norm"
fdx=alpha*fdx./n;
fdy=alpha*fdy./n;由此产生的位移
[y x]=ndgrid(1:size(img,1),1:size(img,2));
figure;
imagesc(img); colormap gray; axis image; axis tight;
hold on;
quiver(x,y,fdx,fdy,0,'r');

最后阶段--使用griddata插值将位移应用于实际像素:
new = griddata(x-fdx,y-fdy,double(img),x,y);
new(isnan(new))=0;由此产生的数字:
figure;
subplot(121); imagesc(img); axis image;
subplot(122); imagesc(new); axis image;
colormap gray

顺便说一句,我不确定所提出的方法(rand+imfilter)是产生随机光滑变形的最直接的方法,你可以考虑第二次或第三次多项式变形的抽样系数,
dx = a*x.^2 + b*x.*y + c*y.^2 + d*x + e*y + f;
dy = g*x.^2 + h*x.*y + k*y.^2 + l*x + m*y + n;https://stackoverflow.com/questions/39308301
复制相似问题