通常DIC的数据集的制作是先的得到位移场,然后再将位移场插赋给散斑图像(即参考图),就可以得到变形图像。且位移场的变形方式有旋转、拉伸、剪切、缩放、高斯等。公式如下图

接下来就是代码了。
%第一种插值方式是为了对输入图像进行 X 和 Y 方向上的插值,目的是根据给定的网格 (Xgrid 和 Ygrid) 对图像进行重采样。
%第二种插值方式是在应用位移矩阵到原始散斑图像上后,根据计算出的位移值在图像上进行插值,目的是对散斑图像进行变形。
%input_img= imread('C:\Users\Administrator\Desktop\test\test1\Sample3 Reference.tif');
% 生成随机参数
tx = rand() * 4 - 2; % rand x transation
ty = rand() * 4 - 2; % rand y translation
sx = rand() * 0.03 + 0.985; % scale x, stretch/compress x
sy = 2 - sx; % scale y, stretch/compress y
sh_x = (rand() - 0.5) * 0.1; % sheer x
sh_y = (rand() - 0.5) * 0.1; % sheer y
th = rand() * 2 * pi; % 这个是表示弧度 %当时是修改了
% 构建仿射变换矩阵
translation_matrix = [
1, 0, 0;
0, 1, 0;
tx, ty, 1
];
scale_matrix = [
sx, 0, 0;
0, sy, 0;
0, 0, 1
];
shear_matrix = [
1, sh_y, 0;
sh_x, 1, 0;</