Function Resource

ImageRead

Reads an image file from disk and return it

ResourceFunction["ImageRead"][type,file]

reads file as a type image and returns the image.

Details and Options

The type argument is one of the following: "JPEG", "PNG", "TIFF".
ResourceFunction["ImageRead"] returns $Failed if it can not read the file as an image of type.
ResourceFunction["ImageRead"] bypasses most of the functionality of the Import making it less flexible and more limited, but significantly faster. It should be used judiciously when performance is critical.

Examples

Basic Examples

Export a random image as a PNG file:

In[1]:=
file = Export["test.png", RandomImage[1, {1000, 1000}]]
Out[1]=

Import the file with ImageRead one hundred times, noting the elapsed time:

In[2]:=
timing1 = Do[ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/\
Function/ImageRead"]["PNG", file], 100] // AbsoluteTiming // First
Out[2]=

Repeat the same experiment with Import:

In[3]:=
timing2 = Do[Import[file], 100] // AbsoluteTiming // First
Out[3]=

Note how ImageRead is significantly faster than Import:

In[4]:=
timing2/timing1
Out[4]=

However, ImageRead only imports a file as an Image. Import provides many more options:

In[5]:=
Import[file, "Elements"]
Out[5]=

Scope

Read from a "JPEG" image file:

In[6]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Function/\
ImageRead"]["JPEG", FindFile["ExampleData/coneflower.jpg"]]
Out[6]=

Read from a "TIFF" image file:

In[7]:=
ResourceFunction[ "https://www.wolframcloud.com/obj/arnoudb/DeployedResources/Function/\
ImageRead"]["TIFF", FindFile["ExampleData/spikey.tiff"]]
Out[7]=