日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

MATLAB【十三】————仿真函数记录以及matlab变成小结

發布時間:2023/11/27 生活经验 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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变成小结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。