1 of 4

Extraction of specific image pixels as bytes

I have a large set (>10000) of uncompressed 8 bit images. Their size is 1600*1200 pixels.

The first 24 pixels in the upper most line starting from left contain some important information (time stamp etc.) about the image.

I want to read out all byte vlaues of these 24 pixels.

Finally I want to save all byte data as right alignes numbers into a text file, a single line with 24 numbers for each image.

I CANNOT READ IN ALL IMAGES INTO THE MEMORY AT ONCE BECAUSE OF MEMORY PROBLEMS.

For testing I have uploaded a set of 1000 cropped images, each having a dimension of 50*50 pixels. They can be downloaded from here: https://drive.google.com/open?id=0B9wKP6yNcpyfUUlsQU1iVWJ0b2M

I have two questions:

- how can I improve (speed up) my code?

- how can I save the byte values right aligned into a text file?

My code is:

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

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

timeStampValues = Array[0 &, {n, 24}];
SetSharedVariable[timeStampValues];

ParallelDo[

   byteValues = Import[fNames[[i]], "Data"];
   timeStampValues[[i, All]] = Flatten@byteValues[[1, 1 ;; 24]];

   , {i, 1, n}
]; // AbsoluteTiming

{17.7253, Null}

(* Saving into text file *)

Export[StringJoin[imageDir, "\\timeStampBytes.txt"], 
   Flatten /@ timeStampValues, "Table"] // Import // Dimensions

The exported file containes the numbers in columns, but they are left aligned.