展开 MNIST - 弹性变形 MATLAB
expand MNIST - elastic deformations MATLAB
我想扩充 MNIST 手写数字数据集。
为此,我想为每个图像分别创建一个 Elastic Deformations 图像。
我阅读了 this 论文的第 2 部分“通过 Elastic 扩展数据集”
扭曲'他们完成了弹性扭曲
之前:
之后:
我试过:
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 中对图像创建 Elastic Distortion 变换?
我不确定我是否完全遵循了位移场的 "normalization" 方法,但我认为这可以使您非常接近
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
) 是产生随机平滑变形的最直接方法,您可以考虑 2- 的采样系数nd 或 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;
我想扩充 MNIST 手写数字数据集。
为此,我想为每个图像分别创建一个 Elastic Deformations 图像。
我阅读了 this 论文的第 2 部分“通过 Elastic 扩展数据集” 扭曲'他们完成了弹性扭曲
之前:
之后:
我试过:
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 中对图像创建 Elastic Distortion 变换?
我不确定我是否完全遵循了位移场的 "normalization" 方法,但我认为这可以使您非常接近
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
) 是产生随机平滑变形的最直接方法,您可以考虑 2- 的采样系数nd 或 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;