From 8a8a5938fa79807e648443d838fc7dc1a830bc20 Mon Sep 17 00:00:00 2001 From: Swathi Sheshadri Date: Tue, 10 Dec 2019 21:50:52 +0100 Subject: [PATCH] code edits to improve plotting functions #3 and reduce amount of user input needed in config file --- .DS_Store | Bin 14340 -> 14340 bytes Codes/.DS_Store | Bin 10244 -> 10244 bytes Codes/core_functions/reconstruct_3D.m | 3 - Codes/helper_functions/.DS_Store | Bin 0 -> 6148 bytes .../make_illustrative_movie.m | 112 +++++++++++++----- .../helper_functions/simple_3Ddata_plotter.m | 59 ++++----- Codes/template_config_file.m | 104 +++++++++++++--- 7 files changed, 200 insertions(+), 78 deletions(-) create mode 100644 Codes/helper_functions/.DS_Store mode change 100755 => 100644 Codes/helper_functions/make_illustrative_movie.m diff --git a/.DS_Store b/.DS_Store index 5a864c57ffb1a49f9852a99dbbbcb8ed7be2e7d0..b1313e06d0ac3260eb844d48ff0ff4efc5c24371 100644 GIT binary patch delta 1007 zcmeIu%}Z2K7{~GFr>6Jb#_^0V;~kkhFV2i8jW)hik}r)K5~w*4MP^x!ccLkChBU0q zMnWP|Dmo}+8Q7wTRyx(DlG?NgYLoP~2^VdmTC~WhO=m`NQ~d{>#es9aJRHtvG&&l+ z+>Wx@z(YIC+~7E42oCl~gT0X;5k2Qm93yKjLqi*?E4_~LDj#ok+AzhPCOfY2F=vla zZ8j;}c87Z+eLKRZLVU)ulgHe7vdixi<6?0X?C~*UR;FTAZ8Ezr?bW*nLTwQ}d@vl+ z7ZOFas)dr&nYeE{781M8#|rdVGS#boiOox0iP+lRKhPcx^@*`eV-{<)s%l5#zCqVR zx+F<1fAR90G6P9up+c&nS_)7H=`={=G(nSelkU<3dPL9YCB358^oHKjB7LII^o73C z68)f`^a~P90c0Zwb`+xo>)=H>Hlqf0s7Di8(S~*eunYTf073NN2nKK*CvXyHF@|wm z#3kIoZOmd0aoodW%=3{_J8yBXH)_qfiu(^TZIw)ZXGr|dl%12CXLA*M%Qx2e`HXcq zX3keFc88|11c|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g<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 60 %after every 60 seconds prompts user to check if she/he wants to stop watching movie @@ -199,6 +199,7 @@ avgerrorall = nanmean(temperror(:)); stderrorall = nanstd(temperror(:)); disp(['Average error (mm) for reconstruction with mode ' modes_3drecon{imodes} ':' num2str(avgerrorall) ' ' char(177) ' ' num2str(stderrorall)]) + disp('Error values corresponding to individual time-points and line-segments on the skeleton available in the workspace variable errorinrecond(timeXlinesegmentsXmodes_of_3Dreconstruction)') end diff --git a/Codes/template_config_file.m b/Codes/template_config_file.m index 960021c..56cb712 100755 --- a/Codes/template_config_file.m +++ b/Codes/template_config_file.m @@ -41,14 +41,14 @@ % Change this to match your current experiment nfeatures = 8; %Edit this to match your current experiment -% Fill in precise duration of recording in **seconds** (eg: for our demo rec_time = 10;) -%If you have acquired images and no videos during your experiment rec_time and fps values -%are not important (you can fill any number into them or leave blank). Make sure to enter the right value to variable -%nframes in the section of this config file called "Edit below for -%post-processing and data visualization" -rec_time = 10; %Edit this to match your experiment recording time -% Fill in frames per second (eg: for our demo fps = 100;) -fps =100; %Edit this to match your current experiment** +% % Fill in precise duration of recording in **seconds** (eg: for our demo rec_time = 10;) +% %If you have acquired images and no videos during your experiment rec_time and fps values +% %are not important (you can fill any number into them or leave blank). Make sure to enter the right value to variable +% %nframes in the section of this config file called "Edit below for +% %post-processing and data visualization" +% rec_time = 10; %Edit this to match your experiment recording time +% % Fill in frames per second (eg: for our demo fps = 100;) +% fps =100; %Edit this to match your current experiment** % Fill in the overall number of cameras in your experiment (for our demo we had 5 cameras) % Change this to the number of cameras you have in your setup @@ -142,16 +142,24 @@ % values so only a few example frames are vizualized while saving everything) plotresults = 1; %plots resulting 3D coordinates at recorded fps -have2Dtrackedvideos = 1; %set this to 0 if you have 2D tracked images instead of videos +%setting both have2Dtrackedvideos and have2Dtrackedimages to 0, lets you +%visualize only the 3D reconstructed data. +%It is recommended to set have2Dtrackedvideos and have2Dtrackedimages to 0, if your video/images size is larger than your working memory use +%make_illustrative_movie.m function in the repository for 3D reconstruction +%visualization alongside 2D video/images +have2Dtrackedvideos = 1; %set this to 1 if you have 2D tracked videos +have2Dtrackedimages = 0; %set this to 1 if you have 2D tracked images instead of videos -%this variable is used when have2Dtrackedvideos is 1 -path_to_2Dtracked_video = '.../*.mp4'; %full path of the 2D tracked video you want to visualize alongside 3D tracked results +%this variable is used when have2Dtrackedvideos is 1 (provide path to +%primary camera video here) +path_to_2Dtracked_video = '.../*.mp4'; %full path of the 2D video you have tracked from **primary camera** to visualize alongside 3D tracked results %below 2 variables are only needed when you have 2D tracked images instead -%of videos -path2Dtrackedimages_folder = '/Users/username/2DTrackedImageFiles/'; %full path to the folder holding 2D tracked images +%of videos (provide path to images tracked by primary camera +path2Dtrackedimages_folder = '/Users/username/2DTrackedImageFiles/'; %full path to the folder holding 2D tracked images from **primary camera** format_of_images = '.png'; %can also be '.tif','.jpeg' or any other format supported by imread function in matlab + color_bw = 1; % 1 if video/images of 2D tracked data is in color and 0 for black and white nskip = 1; %(integer) min value nskip can take is 1, increase this when you have long recording (plots results from every nskip frames) @@ -168,14 +176,25 @@ 7 8;8 5;1 5; 2 6;3 7; 4 8]; %0 : skeleton will not be drawn, Eg : [ 1 2; 2 3;], draws lines between features 1 and 2, 2 and 3 calc_error = 1; %to be set to 0 if ground truth lengths are not available -ground_truth = [57 57 57 57 57 57 57 57 57 57 57 57] ; %enter line segment lengths 1xn vector (where n corresponds to the number of lines in the skeleton) +%enter line segment lengths 1xn vector (where n corresponds to the number of lines in the skeleton) +%If you don't have ground truth for some of the line-segments on the +%skeleton, enter NaN for the corresponding line-segment +ground_truth = [57 57 57 57 57 57 57 57 57 NaN 57 57] ; %this variable is automatically calculated if you have videos and have entered video duration and fps if have2Dtrackedvideos + try + temp = VideoReader(path_to_2Dtracked_video); + catch + flag_mis = 1; + uiwait(msgbox('have2Dtrackedvideos is set however path to a 2D tracked video is not properly defined or has a wrong video format. Change this and re-run main program to proceed.')) + end + rec_time = temp.Duration; + fps = temp.Framerate; nframes = rec_time*fps; %nframes is calculated for you if you have acquired videos for tracking -else - nframes = 1; %to be filled by users who have images and not videos +elseif have2Dtrackedimages + nframes = 1000; %to be filled by users who have images and not videos end %% Some checks to make pose3d user-friendly (nothing to edit here onwards) @@ -256,3 +275,56 @@ flag_mis = 0; %Nothing to flag, checks passed end +%To check if fast visualization of movies is possible and defualt to +%visualizing only 3D reconstructed results if movie files are too large +if plotresults + + if have2Dtrackedvideos + + %Load your DLC labelled video file + cam{1,1} = VideoReader(path_to_2Dtracked_video); + + if color_bw + try + movie1 = zeros(cam{1,1}.Height,cam{1,1}.Width,3,length(1:nskip: nframes),'uint8'); + catch + uiwait(msgbox('Movie file is too large for quick visualization, default visualization of 3D reonstructed data is enabled (Try increasing nskip in the config file or use function make_illustrative_movie.m in the repository instead)')) + have2Dtrackedvideos = 0; + end + else + try + movie1 = zeros(cam{1,1}.Height,cam{1,1}.Width,1,length(1:nskip: nframes),'uint8'); + catch + uiwait(msgbox('Movie file is too large for quick visualization, default visualization of 3D reonstructed data is enabled (Try increasing nskip in the config file or use function make_illustrative_movie.m in the repository instead)')) + have2Dtrackedvideos = 0; + end + end + end + + if have2Dtrackedimages %when you have 2D tracked images + + files = dir([path2Dtrackedimages_folder '/*' format_of_images]); + if isempty(files) + flag_mis = 1; + uiwait(msgbox(sprintf('No 2D tracked images found at the location indicated by config file'),'Problem detected')) + return + end + temp_info = imfinfo([files(1).folder '/' files(1).name]); + if color_bw + try + movie1 = zeros(temp_info.Height,temp_info.Width,3,length(1:nskip:nframes),'uint8'); + catch + uiwait(msgbox('Images are too large and too many for quick visualization, default visualization of 3D reonstructed data is enabled (Try increasing nskip in the config file or use function make_illustrative_movie.m in the repository instead)')) + have2Dtrackedimages = 0; + end + else + try + movie1 = zeros(temp_info.Height,temp_info.Width,1,length(1:nskip:nframes),'uint8'); + catch + uiwait(msgbox('Images are too large and too many for quick visualization, default visualization of 3D reonstructed data is enabled (Try increasing nskip in the config file or use function make_illustrative_movie.m in the repository instead)')) + have2Dtrackedimages = 0; + end + end + end + +end