I have a large set of subsequent 8bit gray scale png images (50 Hz). They show the noise of a CMOS camera, with the lens covered.
A subset of 50 images is available here: https://goo.gl/Sa3P9P
I want to plot for each image its brightness histogram and export it to a numbered png file.
An histogram example is given here:
The problem is that my code is extremely slow. How can I improve the speed?
ChoiceDialog[{FileNameSetter[Dynamic[imageDir], "Directory"],
Dynamic[imageDir]}];
SetDirectory[imageDir];
fNames = FileNames["*.png"];
numFiles = Length[fNames];
Table[
strCounter = ToString@PaddedForm[i, 2, NumberPadding -> {"0", ""}];
image = Import[fNames[[i]]];
imageData = Flatten[ImageData[image, "Byte"]];
imageDataHistogram =
Histogram[imageData, {1}, Frame -> True, ScalingFunctions -> "Log",
PlotRange -> {{0, 255}, All}, ImageSize -> 2000,
BaseStyle -> {FontWeight -> "Bold", FontSize -> 40,
FontFamily -> "Calibri"},
FrameLabel -> {{"# of Pixels", ""}, {"Brightness [0,255]", strCounter}}];
fileName = StringJoin[imageDir, "\\histogram_", strCounter, ".png"];
Export[fileName, imageDataHistogram, "PNG"],
{i, 1, numFiles}
];
Unfortunately ParallelTable
behaves very strange:
Replacing Table
by ParallelTable
produces once images with axis labeling and once not ... very randomly.
Here are the first 10 histogram plots using Table
: https://goo.gl/H3ftw3
and here using ParallelTable
: https://goo.gl/sk6uHu
ImageHistogram
is much faster thanHistogram
in my experience. Sorry, I didn't read through your code other than looking for which of these two you used ... I hope this will help though. $\endgroup$Table
$\rightarrow$ParallelTable
$\endgroup$