lol*_*olo 5 matlab image machine-learning image-processing computer-vision
我想增加MNIST手写数字数据集.
为了做到这一点,我想分别为每个图像创建一个弹性变形图像.
我读了这个文件,第2节"扩展的数据通过弹性扭曲设置",他们完成的弹性变形
之前:
后:
我试过了:
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中对图像创建弹性失真变换?
Sha*_*hai 10
我不确定我是否完全遵循位移场的"标准化"方法,但我认为这可以让你非常接近
img = imread('http://deeplearning.net/tutorial/_images/mnist_2.png'); %// get a digit
Run Code Online (Sandbox Code Playgroud)
计算随机位移字段dx~U(-1,1),dy~U(-1,1):
dx = -1+2*rand(size(img));
dy = -1+2*rand(size(img));
Run Code Online (Sandbox Code Playgroud)
平滑和规范化领域:
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;
Run Code Online (Sandbox Code Playgroud)
由此产生的位移
[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');
Run Code Online (Sandbox Code Playgroud)
最后阶段 - 使用griddata插值将位移应用于实际像素:
new = griddata(x-fdx,y-fdy,double(img),x,y);
new(isnan(new))=0;
Run Code Online (Sandbox Code Playgroud)
结果数字:
figure;
subplot(121); imagesc(img); axis image;
subplot(122); imagesc(new); axis image;
colormap gray
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我不确定所提出的方法(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;
Run Code Online (Sandbox Code Playgroud)