扩展MNIST – MATLAB中的弹性变形

我想增强MNIST手写数字数据集。
为此,我希望为每张图像分别创建一个弹性变形图像。

我在这篇论文的第2节“通过弹性变形扩展数据集”中读到,他们实现了弹性变形

之前:

enter image description here

之后:

enter image description here

我尝试过:

http://www.mathworks.com/help/images/ref/imwarp.htmlhttp://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 (?) 不确定这个“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)是产生随机平滑变形的最直接方法,你可以考虑采样二次或三次多项式变形的系数,

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;

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注