# Fast reading, writing of png images

One of the fastest implemented mathematica function to read png images was showed here by MarcoB

The code for reading a png he proposed is:

First@ImageImportExportDumpImageReadPNG[imageFileName];


Following this I tried out if ImageWritePNG exists and indeed, one can use:

ImageImportExportDumpImageWritePNG[imageFileName, image];


How can I find information that ImageReadPNG and ImageWritePNG exist and how they are used?

• This looks like two separate questions, and the second may be a duplicate of this. Mar 11, 2017 at 13:39
• @Simon Woods: thank you for the comment, I remove the avi part ... thanks
– mrz
Mar 11, 2017 at 13:55
• Keep in mind that those are internal functions which means what WRI can change them at any time without notice. Mar 11, 2017 at 14:52
• @Edmund: Thank you for the info. But a factor 4 or better (in my tests) in speed increase for reading is something very useful when you have to import many thousands files. By the way it shows how ineffective it can be for certain purposes to rely on the standard functions (here Import[image]).
– mrz
Mar 11, 2017 at 19:47

Here's one way you might find such a function.

Mathematica generally has descriptive names even for undocumented internal functions, so you can often find useful things by searching for appropriate substrings in symbol names. For example:

(* do a PNG import to make sure relevant functions are loaded *)
Import["any.png"];

(* search for symbols containing "PNG" *)
?**PNG*


One of the symbols is ImageImportExportDumpImageReadPNG which sounds like it might be useful. Check if we can see the definition:

GeneralUtilitiesPrintDefinitions[ImageImportExportDumpImageReadPNG]


In this case there is nothing useful here.

To see if (and how) the function is used during a PNG import, use Trace:

Trace[Import["any.png"], ImageImportExportDumpImageReadPNG[___],
TraceInternal -> True]


{{{ImageImportExportDumpImageReadPNG["any.png"]}}}

So it looks like the function just takes the filename as an argument. Next you can test it and time it to find out if it's any better than simply using Import.

This is the sort of approach you need to take to uncover undocumented functions - there is inevitably an element of trial and error and often you will find nothing useful at all. Of course you should always save your work before this kind of experimentation.

• This answer is great ... thanks a lot for your help.
– mrz
Mar 11, 2017 at 14:31
• The 11.1 seem have accelerated the speed of importing.
– yode
Mar 11, 2017 at 16:51