%% This is code that will convert a selection of videos from a video_info file into stacks of TIFF images % Matteo Fratarcangeli % Ivan A. Moreno-Hernandez % August 2024 % % for information on preparing the video_info file, see https://github.com/morenohernandezlab/IrO2_Dissolution clear all load video_info_IrO2_900C_FeCl_final_2024_08_02_rates_Mdrive.mat %load a previously prepared video_info file save_images_folder = uigetdir('','*Select Folder for saved images*'); %prepare directory for saving videos %% This section sets .tif parameters tagstruct.ImageLength = 1024; %Image length tagstruct.ImageWidth = 1024; %Image width tagstruct.Photometric = Tiff.Photometric.MinIsBlack; %Set greyscale tagstruct.BitsPerSample = 32; %Single precision tagstruct.SamplesPerPixel = 1; %One-dimensional depth tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky; %Store component values for each pixel contiguously tagstruct.Software = 'MATLAB'; %MATLAB tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP; %IEEE floating-point data tagstruct.Compression = Tiff.Compression.LZW; %LZW compression %% for v = 1:size(video_info_900c,2) %All videos in video_info folder_name = strcat(save_images_folder,'\',erase(video_info_900c(v).video_folder,'M:\Matteo\In_Situ\')); %prepare folder name from video_info mkdir(folder_name) %make directory for saving videos frames = 1:10:size(video_info_900c(v).frame_list,1); %select frames to save (here, 1/10) parfor k = 1:size(frames,2) %for all frames in framelist f = frames(k) %select frame I_e = read_frame(video_info_900c(v).file_dir(f)).*video_info_900c(v).intscale; %using read_frame, pull frame into MATLAB I_e_round = imresize(I_e,[1024,1024]); %resize to 1024x1024 px I_e_round = round(I_e_round,1); %round pixel values to 1 decimal tfile = Tiff(strcat(save_images_folder,'\',erase(video_info_900c(v).video_folder,'M:\Matteo\In_Situ\'),'\frame_',num2str(f,'%06d'),'.tif'),'w') %open tiff object setTag(tfile,tagstruct) %attach tags tfile.write(I_e_round); %write image tfile.close(); %close tiff object end end