gpt4 book ai didi

image - 展开 MNIST - 弹性变形 MATLAB

转载 作者:太空宇宙 更新时间:2023-11-03 19:39:11 28 4
gpt4 key购买 nike

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

我阅读了this论文,第 2 节“通过 Elastic 扩展数据集”扭曲'他们完成了弹性扭曲

之前:

enter image description here

之后:

enter image description here

我试过:

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

enter image description here

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

enter image description here


顺便说一句,我不确定建议的方法 (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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com