I am attempting to plot histograms for batch of images in Matlab. The file structure of input images and the experimental implementation are listed as below.
File structure of input images
The matlab code
HistogramPlotting.m
file is placed in the project root folder and there are multiple folders which is named by its data index number for placing input images. For example, there are1/1.bmp
,1/2.bmp
,1/3.bmp
, ...,2/1.bmp
,2/2.bmp
, ..., etc. The output histograms for the same data index are in a folder "<data_index>/Histograms/". For example, the results of images in folder1/
are placed in folder1/Histograms/
.- / | - HistogramPlotting.m | - 1/ | - Histograms/ <= This folder will be created for placing histogram outputs | - 1.bmp | - 2.bmp | - 3.bmp | - 4.bmp ...
Histogram plotting implementation (
HistogramPlotting.m
):VideoLength = 100; for DataIndex = 1:10 for i = 1:VideoLength InputFileName = sprintf("%s%d%s%d%s", "./", DataIndex, "/", i, ".bmp"); if (isfile(InputFileName) == false) continue; end image = imread(InputFileName); f = figure; f.Position = [100 100 540 400]; histogram(image); xlabel('Intensity'); ylabel('Count'); title(sprintf("Histogram (%d)", i)); OutputFoldername = sprintf("%s%d%s", "./", DataIndex, "/Histograms/"); mkdir(sprintf("%s", OutputFoldername)); OutputFilename = sprintf("%s%d%s", OutputFoldername, i, ".bmp"); saveas(gcf, OutputFilename); close(f); end end
All suggestions are welcome.