MATLAB【十三】————仿真函数记录以及matlab变成小结
part one:matlab 编程小结。
1.char 与string的区别,char使用的单引号 ‘’ ,string使用的是双引号“”。
2.一般标题中的输出一定要通过 num2str 处理,画图具体的图像细节参考:https://blog.csdn.net/Darlingqiang/article/details/108748638
3.查找字符A中是否包含字符串object_info,使用 obj_lookup=strfind(A,'object_info');如果 obj_lookup==1 寻找的A变量所在的数组存在object_info
4. 高斯函数仿真图片
dia = 1;%散斑直径
sigma = 1;
gausFilter = fspecial('gaussian', [dia,dia], sigma);
5.超像素处理, kernel=imresize(gausFilter,times);%%imresize 使用双三次插值。 B = imresize(A,scale) 返回图像 B,它是将 A 的长宽大小缩放 scale 倍之后的图像。
6. 图像旋转imrotate,逆时针为正,
7.投影模型公式 s=B*f*(d1-d0)/(d1*d0);其中其中,B为基线长度,f为焦距,d0为标定距离,d1为当前深度,s为视差。
8.保存数组到txt文件demo.
fileID=fopen([save_path,'scene',num2str(变量),'_obj_info.txt'],'w'); %输出集合数组fmt = '%6f %6f %6f %6f\n'; %%精确到多少位fprintf(fileID,fmt, col2,row2, disparity_x, disparity_y);%保存数组为竖图fclose(fileID);
再一次加载:
cur_obj=load([save_path,'scene',num2str(scene_index),'_dis', num2str(distance(dis_index)),'_ref',num2str(d0),'_obj_info.txt']);
9.显示图像,不包含白色边框,保存图片不包含边框。
figure(10000), imshow(obj_image_rot, 'border', 'tight') image_name=[ 'scene',num2str(d0),'.bmp']; imwrite(obj_image,[save_path,image_name]);
10.matlab调用exe
[status,result] = system(['C:\bin\RelWithDebInfo\depth_magic_runner.exe "', [save_path,image_name],'" --config "C:\Users\Administrator\Desktop\vescl_after\getconfig"']) ;
sttaus返回值为0时,说明程序运行成功,可以通过‘echo’,将输出中间结果打印到屏幕
11.文件更改名称和移动,拷贝等操作。
movefile("debug_output",string(hole_image_name),'f');%改名pause(0.001);movefile(string(hole_image_name),targetPathOri,'f');%移动pause(0.001);
由于移动速度比较低,很多的IO读入写入操作,防止程序阻塞可以使用pause等待程序执行完之后再运行其他程序
12.文件检索遍历图片,见https://blog.csdn.net/Darlingqiang/article/details/108286336
13.直方图统计与三维直方图统计
figure(112) histogram_y = histogram(disparity_y); title(['y disparity analyze ---- ','y truth mean=',num2str(disparity_y_mean_real_value),',y truth var=',num2str(disparity_y_val_real_value)]) xlabel('the value of disparity y') ylabel('the histogram of disparity y'); led_y=legend(['y mean=',num2str(disparity_y_mean),' y var=',num2str(disparity_y_var)]); title(led_y,'speckle center extract '); saveas(figure(112), [allresult(1).folder, '\disparity_y.bmp'])
% look up biger x bias distribute along x figure(105) histogram_bias_x = histogram2((disparity_diff_matching_x(1:match_num)-disparity_x_mean_real_value),x_ordinate_of_matching_point,...'Normalization','probability','FaceColor','flat'); title('bias x after speckle center extract '); xlabel('x coordinate') ylabel('bias x'); saveas(figure(105), [allresult(1).folder, '\bias_x_after_speckle_center_extract.bmp']);
14.点云处理相关。
读取ply:
data_source=pcread('C:\Users\Administrator\Desktop\vescl\ply\adis800_pc_wave.ply');
仿真生成点云参考part two函数:
function [data_target]=scene_to_ply_downsample_function(scene,height,width,distance,multiplier)点云可视化:
figure(1) point_plane = [z_plane_row,z_plane_col,depth_z_plane]; pc_plane = pointCloud(point_plane); pcshow(pc_plane);
点云保存:
tic pcwrite(pc_plane,['adis',num2str(dis),'_pc_plane.ply'],'PLYFormat','ascii'); % pcwrite(pc_plane,['adis',num2str(dis),'_pc_plane.ply'],'PLYFormat','ascii'); toc
part two:函数记录
function [data_target]=scene_to_ply_downsample_function(scene,height,width,distance,multiplier)
输入:对应的场景深度scene1 ,及其对应的宽高,以及当前的仿真距离(也即深度),以及变大或者变小的倍数因子。
function [data_target]=scene_to_ply_downsample_function(scene,height,width,distance,multiplier)% clear;
% close all;
% clc;% dis=300;
% multip =1/2;
% height_low=400;
% width_low=640;
dis=distance;
multip =multiplier;
height_low=height;
width_low=width;
% %***************************** plane ****************************************************
tx_plane=-height_low:1:height_low-1;
ty_plane=-width_low:1:width_low-1;
[x_plane,y_plane]=meshgrid(tx_plane,ty_plane);%形成格点矩阵
z_plane=0*(10*sin(pi*x_plane/(20))+10*cos(pi*y_plane/(20)));z_plane=imresize(z_plane,multip);[z_plane_row,z_plane_col] = find(z_plane>=-20);
len_z_plane =length(z_plane_row);
depth_z_plane = zeros(len_z_plane,1);
for index_plane = 1:len_z_planez_plane_x =z_plane_row(index_plane,:);z_plane_y =z_plane_col(index_plane,:); depth_z_plane(index_plane) = z_plane(z_plane_x,z_plane_y)+dis;
end% figure(11)
point_plane = [z_plane_row,z_plane_col,depth_z_plane];
pc_plane = pointCloud(point_plane);
% pcshow(pc_plane);% tic
% pcwrite(pc_plane,['adis',num2str(dis),'_pc_plane.ply'],'PLYFormat','ascii');
% % pcwrite(pc_plane,['adis',num2str(dis),'_pc_plane.ply'],'PLYFormat','ascii');
% toc
% %***************************** step ****************************************************
% clc;
% close all;
% clear ;
% dis=300;
% multip =1/2;
% height_low=400;
% width_low=640;
z_step(2*height_low,2*width_low) = 0;
for x_step=0:(2*width_low)for y_step=0:(2*height_low)if ((y_step>190)&&(y_step<400)&&(x_step>150)&&(x_step<395))z_step(y_step,x_step) = 4;elseif ((y_step>400)&&(y_step<610)&&(x_step>150)&&(x_step<395))z_step(y_step,x_step) = 1;elseif ((y_step>190)&&(y_step<400)&&(x_step>395)&&(x_step<640))z_step(y_step,x_step) = 3;elseif ((y_step>400)&&(y_step<610)&&(x_step>395)&&(x_step<640))z_step(y_step,x_step) = 2; elseif ((y_step>190)&&(y_step<400)&&(x_step>640)&&(x_step<885))z_step(y_step,x_step) = 2; elseif ((y_step>400)&&(y_step<610)&&(x_step>640)&&(x_step<885))z_step(y_step,x_step) = 3; elseif ((y_step>190)&&(y_step<400)&&(x_step>885)&&(x_step<1130))z_step(y_step,x_step) = 1;elseif ((y_step>400)&&(y_step<610)&&(x_step>885)&&(x_step<1130))z_step(y_step,x_step) = 4; elseif ((y_step<190)&&(y_step>610)&&(x_step<150)&&(x_step>1130))z_step(y_step,x_step) = 1;endend
endz_step=imresize(z_step,multip);
% [rows_step,cols_step]=size(z_step);
[z_step_row,z_step_col] = find(z_step>=-20);
len_z_step =length(z_step_row);
depth_z_step = zeros(len_z_step,1);
for index_step = 1:len_z_stepz_step_x =z_step_row(index_step,:);z_step_y =z_step_col(index_step,:); depth_z_step(index_step) = z_step(z_step_x,z_step_y)+dis;
end% figure(22)
point_step = [z_step_row,z_step_col,depth_z_step];
pc_step = pointCloud(point_step);
% pcshow(pc_step);
% pcwrite(pc_step,'scene.ply','PLYFormat','ascii')
% tic
% pcwrite(pc_step,['adis',num2str(dis),'_pc_step.ply'],'PLYFormat','ascii');
% toc
% %***************************** wave *********************************************
ty_single=-height_low:1:height_low-1;
tx_single=-width_low:1:width_low-1;
[x_single,~]=meshgrid(tx_single,ty_single);%形成格点矩阵
z_single=10*sin(pi*x_single/(20));%+10*cos(pi*y_wave/(20));
z_single=z_single';
z_single=imresize(z_single,multip);[z_single_row,z_single_col] = find(z_single>=-20);
len_z_single =length(z_single_row);
depth_z_single = zeros(len_z_single,1);
for index_single = 1:len_z_singlez_single_x =z_single_row(index_single,:);z_single_y =z_single_col(index_single,:); depth_z_single(index_single) = z_single(z_single_x,z_single_y)+ dis;
end% figure(33)
point_wave = [z_single_row,z_single_col,depth_z_single];
pc_wave = pointCloud(point_wave);
% pcshow(pc_wave);% tic
% pcwrite(pc_wave,['adis',num2str(dis),'_pc_wave.ply'],'PLYFormat','ascii');
% toc
% %***************************** egg *********************************************
tx_wave=-height_low:1:height_low-1;
ty_wave=-width_low:1:width_low-1;
[x_wave,y_wave]=meshgrid(tx_wave,ty_wave);%形成格点矩阵
z_egg=5*sin(pi*x_wave/(20))+5*cos(pi*y_wave/(20));z_egg=imresize(z_egg,multip);[z_wave_row,z_wave_col] = find(z_egg>=-20);
len_z_wave =length(z_wave_row);
depth_z_wave = zeros(len_z_wave,1);
for index_wave = 1:len_z_wavez_wave_x =z_wave_row(index_wave,:);z_wave_y =z_wave_col(index_wave,:); depth_z_wave(index_wave) = z_egg(z_wave_x,z_wave_y)+dis;
end% figure(44)
point_plate =[z_wave_row,z_wave_col,depth_z_wave];
pc_egg = pointCloud(point_plate);
% pcshow(pc_egg);if(strcmp(scene,'scene1'))data_target=pc_plane;
elseif(strcmp(scene,'scene2'))data_target=pc_step;
elseif(strcmp(scene,'scene3'))data_target=pc_wave;
elseif(strcmp(scene,'scene4'))data_target=pc_egg;
end
% tic
% pcwrite(pc_egg,['adis',num2str(dis),'_pc_egg.ply'],'PLYFormat','ascii');
% toc
% %***************************** triangular profiler ****************************************************
end
scene_ref_creat_function仿真生成原始散斑
输入设计的vescl pattern输出模拟散斑参考图
function [ref_speckle]=scene_ref_creat_function(center_coordinate)
max_value=800;M=1280;
N=800;
MAX=1023;% 生成一个高斯函数,函数与散斑点的灰度分布具有有较高的一致性,即可以很好的仿真当前的
dia = 1;%散斑直径
sigma = 1;
gausFilter = fspecial('gaussian', [dia,dia], sigma);times=1;%奇数
kernel=imresize(gausFilter,times);%%imresize 使用双三次插值。 B = imresize(A,scale) 返回图像 B,它是将 A 的长宽大小缩放 scale 倍之后的图像。
cx=round(dia*times/2);
cy=round(dia*times/2);
R=floor(dia*times/2);kernel_mask=ones(size(kernel));
for m=1:times*diafor n=1:times*diaif (cx-n)^2+(cy-m)^2>=(R+1)*Rkernel_mask(m,n)=0;endend
endmax_kernel = max(max(kernel));
kernel = kernel.*kernel_mask*(max_value/max_kernel)*0.3;%
IR_speckle=zeros(M*times,N*times);
L=length(center_coordinate);for i=1:Lcenter_x=round(center_coordinate(i,1)*times);center_y=round(center_coordinate(i,2)*times);if(((center_y-R)>0) && ((center_y+R) < M*times) && ((center_x-R)>0) && ((center_x+R) < N*times) ) IR_speckle(center_y-R:center_y+R,center_x-R:center_x+R)=IR_speckle(center_y-R:center_y+R,center_x-R:center_x+R)+ 255;end
endref_speckle=(imresize(IR_speckle,1/times));
ref_speckle(ref_speckle>MAX)=MAX;end
disparity_analyze函数,输入obj_match匹配数组,或者object_info.txt信息,输出匹配点对以及对应的视差
%% 统计六近邻中目标点的视差分布
function [disparity_diff_matching_x,disparity_diff_matching_y,x_ordinate_of_matching_point,y_ordinate_of_matching_point]=disparity_analyze(obj_match)
% obj_info_name = '';
% obj_info_name = dir(fullfile('C:\Users\Administrator\Desktop\vescl_after\result\scene1_dis500_ref400\',obj_info_name,'*object_info*.txt'));% if exist(['C:\Users\Administrator\Desktop\vescl_after\result\scene1_dis500_ref400\' obj_info_name(1).name])
% obj_match = importdata(['C:\Users\Administrator\Desktop\vescl_after\result\scene1_dis500_ref400\' obj_info_name(1).name]);x_thresholod=0.1;y_thresholod=1;match_list = find(obj_match(:,end)>0);match_num = size(find(obj_match(:,end)>0),1);disparity_diff_x_each_other=zeros(match_num,6);disparity_diff_y_each_other=zeros(match_num,6);disparity_diff_x = zeros(match_num*6,1);% show matching statusdisparity_diff_matching_x=obj_match(match_list(:),end-2);disparity_diff_matching_y=obj_match(match_list(:),end-1);disparity_diff_matching_y_size = size(disparity_diff_matching_y);for i = 1:disparity_diff_matching_y_sizeif(disparity_diff_matching_y(i)>5)disparity_diff_matching_y(i)=0;endendx_ordinate_of_matching_point = obj_match(match_list(:),1);y_ordinate_of_matching_point = obj_match(match_list(:),2);%% disparity_diff_y = zeros(match_num*6,1);disparity_diff_num = 0;for i = 1:match_numobj_num = match_list(i);disp_x = obj_match(obj_num,end-2);disp_y = obj_match(obj_num,end-1);descriptor = obj_match(obj_num,end-8:end-3);desp_list = descriptor(descriptor>0);desp_list = desp_list + ones(size(desp_list));% from one start for j = 1:size(desp_list,2)if obj_match(desp_list(j),end)>0disparity_diff_num = disparity_diff_num + 1;disparity_diff_x(disparity_diff_num) = disp_x - obj_match(desp_list(j),end - 2);if abs(disp_x - obj_match(desp_list(j),end - 2))-x_thresholod >=0 disparity_diff_x_each_other(i,j)=abs(disp_x - obj_match(desp_list(j),end - 2));endif abs(disp_y - obj_match(desp_list(j),end - 1))-y_thresholod >=0 disparity_diff_y_each_other(i,j)=abs(disp_y - obj_match(desp_list(j),end - 1));end% 邻域视差分布问题disparity_diff_y(disparity_diff_num) = disp_y - obj_match(desp_list(j),end - 1); endend end%% 统计非零个数cnt_x = zeros(match_num,1); for i=1:match_numcnt_x(i)= nnz(disparity_diff_x_each_other(i,:)>0);endx_index=find(cnt_x(:));x_size=size(x_index,1);
% figure
% plot(1:x_size, cnt_x(x_index(:)),'r.')
% title('x disparity diff threshold great 3 distribution ');
% grid on
cnt_y = zeros(match_num,1); for i=1:match_numcnt_y(i)= nnz(disparity_diff_y_each_other(i,:)>0);endy_index=find(cnt_y(:));y_size=size(y_index,1);%% y 视差 纵坐标 x轴为横坐标
% figure(100)
% plot(1:match_num,disparity_diff_matching_y(1:match_num),'b.')
% title(' y disparity matching result according point num')
% grid on
%
% figure(101)
% plot(y_ordinate_of_matching_point(1:match_num),disparity_diff_matching_y(1:match_num),'b.')
% title(' y disparity matching result along y disparity')
% grid on% figure
% plot(1:disparity_diff_num,disparity_diff_x(1:disparity_diff_num),'r.')
% title('all matching points decriptors x disparity diff ')
% grid on
%
% figure
% plot(1:disparity_diff_num,disparity_diff_y(1:disparity_diff_num),'r.')
% title('all matching points decriptors y disparity diff ')
% grid on
% figure
% histogram(disparity_diff_x(1:disparity_diff_num),'DisplayStyle','bar')
% title('histogram disparity diff x')
% saveas(gcf,strcat(root_dir, 'histogram_disparity_diff_x.bmp'));
% figure
% histogram(disparity_diff_y(1:disparity_diff_num),'DisplayStyle','bar')
% title('histogram disparity diff y') % else
% disp(['不存在*object_info*.txt'])
% end
end
compute_IoU:求取IOU交并比,可以用于评估重建效果
function [IoU, area] = compute_IoU(region_a, region_b)
%COMPUTE_IOU Is compute the two region overlap area.
%
% ************************
% * *
% * (x_a,y_a)******************
% * * * *
% * * * *
% * * * *
% *******************(x_b,y_b) *
% * *
% * *
% ***********************x_a = max(region_a(1), region_b(1));
y_a = max(region_a(2), region_b(2));
x_b = min(region_a(3), region_b(3));
y_b = min(region_a(4), region_b(4));area_a = (region_a(3) - region_a(1) + 1) * (region_a(4) - region_a(2) + 1);
area_b = (region_b(3) - region_b(1) + 1) * (region_b(4) - region_b(2) + 1);area = max(0, x_b - x_a + 1) * max(0, y_b - y_a + 1);
IoU = area / (area_a + area_b - area);end
scene_creat_function.m 输入宽高,输出场景平面深度图
function [scene1,scene2,scene3,scene4]=scene_creat_function(height,width)
tx_plane=-height/2:1:height/2-1;
ty_plane=-width/2:1:width/2-1;
[x_plane,y_plane]=meshgrid(tx_plane,ty_plane);%形成格点矩阵
z_plane=0*(x_plane+y_plane);
scene1=z_plane;
% %***************************** SENCE 2 step ****************************************************
z_step(height,width) = 0;
for x_step=0:widthfor y_step=0:heightif ((y_step>190)&&(y_step<400)&&(x_step>150)&&(x_step<395))z_step(y_step,x_step) = 5;elseif ((y_step>400)&&(y_step<610)&&(x_step>150)&&(x_step<395))z_step(y_step,x_step) = 2;elseif ((y_step>190)&&(y_step<400)&&(x_step>395)&&(x_step<640))z_step(y_step,x_step) = 4;elseif ((y_step>400)&&(y_step<610)&&(x_step>395)&&(x_step<640))z_step(y_step,x_step) = 3; elseif ((y_step>190)&&(y_step<400)&&(x_step>640)&&(x_step<885))z_step(y_step,x_step) = 3; elseif ((y_step>400)&&(y_step<610)&&(x_step>640)&&(x_step<885))z_step(y_step,x_step) = 4; elseif ((y_step>190)&&(y_step<400)&&(x_step>885)&&(x_step<1130))z_step(y_step,x_step) = 2;elseif ((y_step>400)&&(y_step<610)&&(x_step>885)&&(x_step<1130))z_step(y_step,x_step) = 5; elseif ((y_step<190)&&(y_step>610)&&(x_step<150)&&(x_step>1130))z_step(y_step,x_step) = 0;endend
end
scene2=z_step';
% %***************************** SENCE 3 wave *********************************************
ty_single=-height/2:1:height/2-1;
tx_single=-width/2:1:width/2-1;
[x_single,~]=meshgrid(tx_single,ty_single);%形成格点矩阵
z_wave=10*sin(pi*x_single/(20));%+10*cos(pi*y_wave/(20));
scene3=z_wave';
% %***************************** SENCE 4 egg *********************************************
tx_wave=-height/2:1:height/2-1;
ty_wave=-width/2:1:width/2-1;
[x_wave,y_wave]=meshgrid(tx_wave,ty_wave);%形成格点矩阵
z_egg=5*sin(pi*x_wave/(20))+5*cos(pi*y_wave/(20));
scene4=z_egg;end
MATLAB【十三】————仿真函数记录以及matlab变成小结相关推荐
- 【雷达通信】基于matlab雷达仿真模拟系统【含Matlab源码 150期】
⛄一.获取代码方式(附课程作业报告) 获取代码方式1: 完整代码已上传我的资源:[雷达通信]基于matlab雷达仿真模拟系统[含Matlab源码 150期] 点击上面蓝色字体,直接付费下载,即可. 获 ...
- 无模型自适应迭代学习控制原理和matlab代码仿真学习记录
无模型自适应ILC原理及代码实现 这里学习的是很老的一篇论文<基于无模型自适应控制的反馈-前馈迭代学习控制系统收敛性研究>,作者是晏静文和侯忠生,大家有兴趣可以找来看看.这里主要介绍的无模 ...
- Matlab应变片仿真,一种基于Matlab/Adams联合仿真的真实路谱再现系统和方法与流程...
本发明属于汽车系统动力学仿真技术领域,特别是一种基于Matlab/Adams联合仿真的真实路谱再现系统和方法. 背景技术: 汽车系统动力学仿真技术是汽车设计制造中一项不可或缺的技术,尤其是在汽车操纵稳 ...
- matlab中simple函数怎么用,matlab里simple函数
值 realmin:系统所能表示的最小数值 nargin: 函数的输出引数个数 ---MATLAB 中基本绘图函数有: plot: x 轴和 y 轴均为线性刻度 数刻度 semilogx: x 轴为对 ...
- MATLAB绘制主函数动态图,matlab绘制动态图
mathematica绘制动态图,"绘图之王"争霸赛--Excel才是绘图王道,matlab绘制动态图,动态三维图绘制 matlab动态图画法_数学_自然科学_专业资料.Matla ...
- Adams 与MATLAB联合仿真 失败,adams与matlab联合仿真例子(正确没商量).doc
adams与matlab联合仿真例子(正确没商量) Adams与Matlab联合仿真例子 作者寄语:这个文件是基于李增刚<adams入门详解与实例>一书中,Adams与Matlab联合仿真 ...
- matlab动力学仿真_机械系统动力学MATLAB仿真(上)
机械系统动力学MATLAB仿真(上) 寒假期间预习李有堂编著.国防工业出版社出版的<机械系统动力学>,对其中第四章:单自由度系统的振动,第五章:两自由度系统的振动,的部分内容进行matla ...
- adams与matlab联合仿真天线,雷达天线模型MATLAB与ADAMS联合仿真 实验.doc
雷达天线模型MATLAB与ADAMS联合仿真 实验 雷达天线模型MATLAB与ADAMS联合仿真实验 1.导入雷达天线机械系统模型 启动ADAMS,弹出如图1所示的对话框,选择"Open a ...
- amesim与matlab联合仿真原理,amesim与matlab联合仿真步骤(自己总结)
Amesim与matlab 联合仿真参数设置 实验软件平台 Matlab2009a,amesimR8a ,VC6.0 企业版(英文版) 步骤: 1 将VC++中的"vcvar32.bat&q ...
最新文章
- linux中-i选项的作用,linux – find中的-prune选项有什么作用?
- webpack - vue Component 从入门到放弃(三)
- Symfony2学习笔记之HTTP Cache
- 从支付宝面试题谈:怎样有效减少用户咨询的客服成本
- 【论文解读】Knowledge Review:知识蒸馏新解法
- adapter为null_软件设计精要之——适配器(Adapter)模式
- mapreduce shuffle过程问答
- 数学教育中的AI:NeurIPS’21 Workshop 欢迎投稿!
- 客户端和服务器各种报错解释
- 一步步学Qt,第九天-QSTL与STL-Qvector,vector
- 2021 最热门的 20 个数据库学习总结,你会用哪几个
- python 吃cpu 显卡 内存_浅析 Pycharm 内存、cpu 占用率
- html编辑唐诗的格式,古诗竖着写的格式
- 利用c#快速知道哪些qq好友空间屏蔽了自己
- word 文档如何加密
- 现在很多人都想做抖音短视频,那我们应该怎样去做呢?一起来看一吧
- cmpp 免提短信(闪信)
- layui 下拉表格选择器
- Python 技术篇-用mutagen库提取MP3歌曲图片实例演示
- 利用LSTM+CNN+glove词向量预训练模型进行微博评论情感分析(二分类)