Not getting output.

13 views (last 30 days)
Madhura Patil
Madhura Patil on 12 Aug 2022
Answered: Image Analyst on 15 Aug 2022
I'm new to matlab. I've a certain clips of videos. I've a code to resize each frames of these clips and save the frames in a directory. The directory will have same as the video. I'm supposed to give the input and output path of the folders.The code is not giving me any output. It does not give any error.
Here is the code:
%% Input
dataset_path = '<input_dataset>/features/fullFrame-210x260px';
%% Ouput
output_path = '<output_dataset>/features/fullFrame-227x227px';
%%
% reshape_size = [256 256]
reshape_size = [227 227];
data_partitions = dir(dataset_path);
data_partitions=data_partitions(~ismember({data_partitions.name},{'.','..'}));
for i = 1:numel(data_partitions)
curr_partition_path = [dataset_path '/', data_partitions(i).name];
curr_sequences = dir(curr_partition_path);
curr_sequences = curr_sequences(~ismember({curr_sequences.name},{'.','..'}));
curr_sequences(~[curr_sequences(:).isdir]) = [];
for j = 1:numel(curr_sequences)
curr_sequence_path = [curr_partition_path, '/', curr_sequences(j).name '/'];
curr_frames = dir(curr_sequence_path);
curr_frames = curr_frames(~ismember({curr_frames.name},{'.','..'}));
curr_output_path = [output_path, '/', data_partitions(i).name, '/', curr_sequences(j).name];
if ~(exist(curr_output_path,'dir'))
mkdir(curr_output_path)
disp(curr_sequence_path);
for f = 1:numel(curr_frames)
curr_frame = [curr_sequence_path, '/',curr_frames(f).name];
curr_output_frame = [curr_output_path, '/', curr_frames(f).name];
imwrite(imresize(imread(curr_frame),reshape_size), curr_output_frame)% ,'Method', 'lanczos3');
end
end
end
end
What exactly should be the format of my path?
Thankyou.
  2 Comments
Benjamin Thompson
Benjamin Thompson on 12 Aug 2022
It is hard to guess at the input and output folder and file setup that lets your code run. Have you tried stepping through your code in the MATLAB debugger to identify the problem? If you want help, post a ZIP file that quickly reproduces a folder structure that allows your code to run so that the Community can try it out and find a problem.
dpb
dpb on 12 Aug 2022
Edited: dpb on 12 Aug 2022
data_partitions = dir(dataset_path);
data_partitions=data_partitions(~ismember({data_partitions.name},{'.','..'}));
for i = 1:numel(data_partitions)
curr_partition_path = [dataset_path '/', data_partitions(i).name];
...
You get the result of the dir() command and use the .name field but then don't use .folder
Also, use fullfile to build fully-qualified file names instead of klunky, easy to get wrong manual string manipulations.
After fixing up these issues to make the code simpler and easier to debug, start by setting a breakpoint at the first line past the first call to dir and make sure it works to that point -- then step on to the next line and rinse and repeat, fixing your logic errors as you go...
data_partitions=data_partitions(~ismember({data_partitions.name},{'.','..'}));
If you'll add a wildcard filename to the search-for filename string then you'll be ensured of not returning file names that don't match the desired type and have no need for the above. Even otherwise, using the .isdir member of the dir() struct to remove such entries is "more better".
".The code is not giving me any output. It does not give any error."
Those symptoms would match the case the initial dir() failed to match any files and consequently numel(data_partitions) is zero and the outer for...end loop never executed.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 15 Aug 2022
See attached demo. It writes out all frames to a new subfolder, and then after that reads them back in and rebuilds a video.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!