Histograms of gray scale images

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[

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 than Histogram 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. – Szabolcs Jan 15 '16 at 16:47
• Table $\rightarrow$ ParallelTable – rhermans Jan 15 '16 at 16:56
• Please see my comment above ... – mrz Jan 15 '16 at 17:30

Thank you very much to Szabolcs and rhermans.

I have used ImageHistogram together with ParallelTable. For 10 images the improved code needs on my computer 2.51 sec (AbsoluteTiming) whereby the old code needed 124.22 sec. The speed is improved to a factor of about 50 ... great ...

The only small but important difference is: I need a logarithmic y scale for ImageHistogram. Is this possible?

ChoiceDialog[{FileNameSetter[Dynamic[imageDir], "Directory"],
Dynamic[imageDir]}];
SetDirectory[imageDir];

fNames = FileNames["*.png"];
numFiles = Length[fNames];

ParallelTable[

image = Import[fNames[[i]]];
imageHistogram =
ImageHistogram[image, 255, Frame -> True, FrameTicks -> True,
ImageSize -> 2000, AspectRatio -> 2/3,
BaseStyle -> {FontWeight -> "Bold", FontSize -> 40,
FontFamily -> "Calibri"},
FrameLabel -> {{"# of Pixels", ""}, {"Brightness [0,1]", strCounter}}]
;

fileName = StringJoin[imageDir, "\\histogram_", strCounter, ".png"];
Export[fileName, imageHistogram, "PNG"],

{i, 1, numFiles}

];


The solution on how to get a logarithmic vertical scale in ImageHistogram was send to me by the the Mathematics support team:

ImageHistogram with logarithmic y scale

• Alternative solution: see my answer in mathematica.stackexchange.com/questions/104328/… – mrz Mar 15 '16 at 11:16
• mrz you should accept your answer so this question doesnt keep getting bumped as unanswered. (Unless obviously you still hold out for a better answer..). BTW ParallelDo would seem more appropriate here, though it probably doesn't make any difference. – george2079 May 8 '16 at 16:00