4
$\begingroup$

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@Image`ImportExportDump`ImageReadPNG[imageFileName];

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

Image`ImportExportDump`ImageWritePNG[imageFileName, image];

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

$\endgroup$
4
  • $\begingroup$ This looks like two separate questions, and the second may be a duplicate of this. $\endgroup$ Mar 11, 2017 at 13:39
  • $\begingroup$ @Simon Woods: thank you for the comment, I remove the avi part ... thanks $\endgroup$
    – mrz
    Mar 11, 2017 at 13:55
  • $\begingroup$ Keep in mind that those are internal functions which means what WRI can change them at any time without notice. $\endgroup$
    – Edmund
    Mar 11, 2017 at 14:52
  • $\begingroup$ @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]). $\endgroup$
    – mrz
    Mar 11, 2017 at 19:47

1 Answer 1

10
$\begingroup$

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*

enter image description here

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

GeneralUtilities`PrintDefinitions[Image`ImportExportDump`ImageReadPNG]

enter image description here

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"], Image`ImportExportDump`ImageReadPNG[___], 
  TraceInternal -> True]

{{{Image`ImportExportDump`ImageReadPNG["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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.