MATLAB【六】 ———— matlab 随机散斑模拟
生活随笔
收集整理的這篇文章主要介紹了
MATLAB【六】 ———— matlab 随机散斑模拟
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
%%
%input for image size(NX,NY) <散斑圖大小(像素)>
NX =1280;
NY =800;
%input for numble of speckles(S)<散斑數(shù)量>
S = 9226;
%輸入的散斑大小
a = 4;
%input for peak intensity of each speckle(I0)<散斑峰值強度>
I0 =1;
%input for displacement(UX,UY)<散斑圖位移>
UX = 0.04;
UY = 0;
%input for deformation gradient(ux,uy,vx,vy)<位移梯度分量>ux = 0.002;
ux = 0.02;
uy = 0.02;
vx = 0.02;
vy = 0.02;%%
%main program主程序
I = zeros(NX,NY);%創(chuàng)建一個1280*800的全0矩陣
%rand('state');
X=NY*rand(S,1);%產(chǎn)生S*1階0~1均勻分布的隨機數(shù)矩陣
Y=NY*rand(S,1);
%generation of undeformed speckle image初始散斑圖的生成
for i=1:NXfor j=1:NYI(i,j)=I0.*pi./4.*a.^2.*sum((erf((i-X(1:end))./a)-erf((i+1-X(1:end))./a)).*(erf((j-Y(1:end))./a)-erf((j+1-Y(1:end))./a)));end
end
A=uint16(I);%double(I)是將讀入的圖像I的uint8數(shù)據(jù)轉(zhuǎn)換為double類型的數(shù)據(jù)
% A = double2uint16(A);
% G=mat2gray(A);%mat2gray是一個計算機函數(shù),功能是實現(xiàn)圖像矩陣的歸一化操作。所謂”歸一化”就是使矩陣的每個元素的值都在0和1之間。
% imwrite(A,'gauss\s1.png')
imshow(A)
% M =[1-ux -uy;-vx 1-vy];
% J = (M);
% %generation of speckles image after deformation
% for i=1:NX
% for j=1:NY
% I(i,j)=I0.*pi./4.*a.^2.*sum((erf((i-i*ux-j*uy-UX-X(1:end))./a)-erf((i+1-(i+1)*ux-(j+1)*uy-UX-X(1:end))./a)).*(erf((j-j*vy-i*vx-UY-Y(1:end))./a)-erf((j+1-(j+1)*vy-(i+1)*vx-UY-Y(1:end))./a)));
% end
% end
% A=double(I);
% G=mat2gray(A);
% imwrite(G,'gauss\s2.png')
?
%input for image size(NX,NY) <散斑圖大小(像素)>
prompt={'Enter hprozontal(x) resolution for simulated image[pixels]:',...'Enter vertical(y) resolution for simulated image{pixels}:'};
dlg_title='Input for image size';
num_lines=1;
def={'512','512'};
answer=inputdlg(prompt,dlg_title,num_lines,def);%創(chuàng)建并打開輸入對話框
NX=str2double(cell2mat(answer(1,1)));%輸入的水平分辨率的值
NY=str2double(cell2mat(answer(2,1)));%輸入的豎直分辨率的值
%input for numble of speckles(S)<散斑數(shù)量>
prompt={'enter total number of speckles'};
dlg_title='input number of speckles';
num_lines=1;
def={'1200'};
answer=inputdlg(prompt,dlg_title,num_lines,def);%%創(chuàng)建并打開輸入對話框
S=str2double(cell2mat(answer(1,1)));%輸入的散斑數(shù)量
%input for speckle size(a)<散斑大小>
prompt={'enter speckle size'};
dlg_title='input for speckle size';
num_lines=1;
def={'4'};
answer=inputdlg(prompt,dlg_title,num_lines,def);
a=str2double(cell2mat(answer(1,1)));%輸入的散斑大小
%input for peak intensity of each speckle(I0)<散斑峰值強度>
prompt={'enter peak intensity of each speckle'};
dlg_title='input for peak intensity of each speckle';
num_lines=1;
def={'1'};
answer=inputdlg(prompt,dlg_title,num_lines,def);
I0=str2double(cell2mat(answer(1,1)));
%input for displacement(UX,UY)<散斑圖位移>
prompt={'enter horizontal(x)displacement for simulate image[pixels]:',...'enter vertical(y)displacement for simulated image[pixels]:'};
dlg_title='input for sub-pixel diaplacement';
num_lines=1;
def={'0.04','0'};
answer=inputdlg(prompt,dlg_title,num_lines,def);
UX=str2double(cell2mat(answer(1,1)));
UY=str2double(cell2mat(answer(2,1)));
%input for deformation gradient(ux,uy,vx,vy)<位移梯度分量>
prompt={'enter deformation gradient(ux) for simulated image[pixels]:',...'enter deformation gradient(uy) for simulated image[pixels]:',...'enter deformation gradient(vx) for simulated image[pixels]:',...'enter deformation gradient(vx) for simulated image[pixels]:'};
dlg_title='input for sub-pixel displacement';
num_lines=1;
def={'0.002','0','0','0'};
answer=inputdlg(prompt,dlg_title,num_lines,def);
ux=str2double(cell2mat(answer(1,1)));
uy=str2double(cell2mat(answer(2,1)));
vx=str2double(cell2mat(answer(3,1)));
vy=str2double(cell2mat(answer(4,1)));
%main program主程序
I=zeros(NX,NX);%創(chuàng)建一個512*512的全0矩陣
%rand('state');
X=NY*rand(S,1);%產(chǎn)生S*1階0~1均勻分布的隨機數(shù)矩陣
Y=NY*rand(S,1);
%generation of undeformed speckle image初始散斑圖的生成
for i=1:NXfor j=1:NYI(i,j)=I0.*pi./4.*a.^2.*sum((erf((i-X(1:end))./a)-erf((i+1-X(1:end))./a)).*(erf((j-Y(1:end))./a)-erf((j+1-Y(1:end))./a)));end
end
A=double(I);%double(I)是將讀入的圖像I的uint8數(shù)據(jù)轉(zhuǎn)換為double類型的數(shù)據(jù)
G=mat2gray(A);%mat2gray是一個計算機函數(shù),功能是實現(xiàn)圖像矩陣的歸一化操作。所謂”歸一化”就是使矩陣的每個元素的值都在0和1之間。
imwrite(G,'1.jpg')%生成數(shù)據(jù)為G名稱為PIP的tif格式圖像
M=[1-ux -uy;-vx 1-vy];
J=det(M);
%generation of speckles image after deformation
for i=1:NXfor j=1:NYI(i,j)=I0.*pi./4.*a.^2.*sum((erf((i-i*ux-j*uy-UX-X(1:end))./a)-erf((i+1-(i+1)*ux-(j+1)*uy-UX-X(1:end))./a)).*(erf((j-j*vy-i*vx-UY-Y(1:end))./a)-erf((j+1-(j+1)*vy-(i+1)*vx-UY-Y(1:end))./a)));end
end
A=double(I);
G=mat2gray(A);
imwrite(G,'2.jpg')
參考資料:
https://wiki.tw.lvfukeji.com/baike-%E6%95%A3%E6%96%91%E6%88%90%E5%83%8F?wprov=srpw1_0#%E6%A6%82%E8%A6%81
https://blog.csdn.net/weixin_40678482/article/details/103722035
https://blog.csdn.net/zcj6150/article/details/107347672
總結(jié)
以上是生活随笔為你收集整理的MATLAB【六】 ———— matlab 随机散斑模拟的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MATLAB【五】———— matlab
- 下一篇: MATLAB【七】———— matlab