What is the most efficient way to create a large image database from MATLAB plots or figures for use in Deep Learning?

5 次查看(过去 30 天)
I am working with a large dataset and have created a looped code that:
  • Creates a colourmap / surface plot from Continuous Wavelet Transform (cwt) data.
  • Alters the image size and axes to make them suitable for use in 'Deep Learning Toolbox'.
  • Writes the image, as a .png, to a file name and location using imwrite.
  • Repeats for each set of data.
I have approximately 340,000 images to create and as you can imagine, this has been taking >2days to create and even though each file size is ~30kb, the total folder size is ~10Gb.
The code is as shown:
(Missing: DB2data = raw data; file_list = file name list; save_path = directory save path)
for m = 1:length(DB2data)
%% SIGNAL PROCESSING
fig = figure('visible','off');
[cfs,frq]=cwt(DB2data(m,:),fs);
surf(t,frq,abs(cfs),'edgecolor','none')
colormap parula %Set colour to 'parula'
view(2)
%% IMAGE SETTINGS
ylim([0.5 40]) %Set frequency axis
zlim([0 56.5]) %Set colourbar limits
xlim([0 5]) %Set time axis
axis off %Remove axes
colorbar off %Remove colorbar
set(gca,'LooseInset',get(gca,'TightInset')); %Remove background
set(gca,'units','normalized','position',[0 0 1 1]); %Remove additional background
fig2 = getframe(fig); %Get 'image' from figure
image = fig2.cdata; %Imgage data
image = imresize(image, [227 227]); %Resize image
imwrite(image, fullfile(save_path, strcat(file_list(m),'.png'))); %Save image
close(fig) %Close figure
end
Does anyone have any suggests on a more efficient way to create a large image database like this?
Thanks in advance.

采纳的回答

Srivardhan Gadila
Srivardhan Gadila 2020-2-24
The following suggestions might help you:
  1. Use parfor instead of the regular for loop, this would save time.
  2. While loading the generated dataset, make use of the imageDatastore or imageSet

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by