我想扩充MNIST手写数字数据集。
为此,我想为每个图像分别创建一个弹性变形图像。

我在this纸上阅读了第2节“通过Elastic扩展数据集”
变形是指他们完成了弹性变形

前:

image - 扩展MNIST-弹性变形MATLAB-LMLPHP

后:

image - 扩展MNIST-弹性变形MATLAB-LMLPHP

我试过了:

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 中的图像上创建弹性变形转换?

最佳答案

我不确定我是否完全遵循位移场的“归一化”方法,但是我认为这可以使您更加接近

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');

image - 扩展MNIST-弹性变形MATLAB-LMLPHP

最后阶段-使用 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

image - 扩展MNIST-弹性变形MATLAB-LMLPHP

顺便说一句,我不确定所提出的方法(rand + imfilter)是产生随机平滑变形的最直接方法,您可能会考虑2阶或3阶多项式变形的采样系数,
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;

关于image - 扩展MNIST-弹性变形MATLAB,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39308301/

10-09 15:55