散斑图像位移场

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

clc;clear all;close all;
input_img= imread('C:\Users\Dell\Desktop\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;0, 0, 1];
rotation_matrix = [cos(th), -sin(th), 0;sin(th), cos(th), 0;0, 0, 1];
% 计算仿射变换矩阵
transform_formulation = translation_matrix * scale_matrix * shear_matrix;
transform_formulation = transform_formulation';
% 生成网格
grid_lin = linspace(-255.5, 255.5, 512);
[x, y] = meshgrid(grid_lin, grid_lin);
% 进行仿射变换
transformed_coords = transform_formulation \ [x(:), y(:), ones(numel(x), 1)]';
transformx = reshape(transformed_coords(1, :), size(x));
transformy = reshape(transformed_coords(2, :), size(y));
% 计算位移场
disp_field_x = x - transformx;
disp_field_y = y - transformy;
% 生成随机参数和高斯噪声
para = rand(2, 6) * 4 - 2;
poisson = rand() * 0.3 + 0.05;
mu1 = (para(1, 1) / 2 + 1) / 2;
mu2 = (para(1, 3) / 2 + 1) / 2;
sig1 = para(1, 2) + 2 / 8 + 0.05;
sig2 = para(1, 4) + 2 / 8 + 0.05;
cov1 = sig1^2;
cov2 = sig2^2;
amp = para(1, 5) * 0.1 + 0.005 * sign(para(1, 5));
vo = para(1, 6) / 2;
% 生成高斯分布场
[Xgrid, Ygrid] = meshgrid(linspace(0, 1, 512));
Disp_gaus_1x = 0.6 * gauss2D(Xgrid, Ygrid, sig1, mu1, sig2, mu2, amp, vo);
Disp_gaus_1y = -0.6 * poisson * gauss2D(Xgrid, Ygrid, sig1, mu1, sig2, mu2, amp, vo);
mu1 = (para(2, 1) / 2 + 1) / 2;
mu2 = (para(2, 3) / 2 + 1) / 2;
sig1 = para(2, 2) + 2 / 8 + 0.05;
sig2 = para(2, 4) + 2 / 8 + 0.05;
cov1 = sig1^2;
cov2 = sig2^2;
amp = para(2, 5) * 0.1 + 0.005 * sign(para(2, 5));
vo = para(2, 6) / 2;
Disp_gaus_2x = -0.6 * poisson * gauss2D(Xgrid, Ygrid, sig1, mu1, sig2, mu2, amp, vo);
Disp_gaus_2y = 0.6 * gauss2D(Xgrid, Ygrid, sig1, mu1, sig2, mu2, amp, vo);
% 计算最终位移场
disp_field_x = disp_field_x - (Disp_gaus_1x + Disp_gaus_2x);
disp_field_y = disp_field_y - (Disp_gaus_1y + Disp_gaus_2y);
% 将 disp_field_x 和 disp_field_y 两个数组添加到列表中
% 将 disp_field_x 和 disp_field_y 两个数组合并成一个三维数组
disp_field_output2 = cat(3, disp_field_x, disp_field_y);
% 将合并后的数组进行转置,以满足 (2, 512, 512) 的格式
disp_field_output2 = permute(disp_field_output2, [3, 1, 2]);
imagesc(disp_field_x);
% imagesc(disp_field_y);
colorbar;
function result = gauss2D(x, y, sig1, mu1, sig2, mu2, amp, vo)
xnumerator = (x - mu1) .^ 2;
xdenom = 2 * sig1 .^ 2;
xterm = xnumerator ./ xdenom;
ynumerator = (y - mu2) .^ 2;
ydenom = 2 * sig2 .^ 2;
yterm = ynumerator ./ ydenom;
result = amp * (exp(-(xterm + yterm))) + vo;
end

位移场随机结果1(左图为x方向,右图为y方向)

 

位移场随机结果2(左图为x方向,右图为y方向)

 

imagesc函数显示使用经过标度映射的颜色的图像。colorbar是显示色阶的颜色栏。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值