({{, (RefLink[ImageFileApply, paclet:ref/ImageFileApply])[f,inputfile,outputfile] 
applies the function f to the list of channel values for each pixel of the image stored in inputfile and stores the result in outputfile.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ImageFileApply, paclet:ref/ImageFileApply]) can be used to read, process, and write successive blocks of data from a very large image file whose size could exceed available memory.

(RefLink[ImageFileApply, paclet:ref/ImageFileApply])[f,inputfile] stores the result of an image file in the working directory where the output file name is the concatenation of inputfile and the result of (RefLink[DateString, paclet:ref/DateString])[].

(RefLink[ImageFileApply, paclet:ref/ImageFileApply]) works with TIFF, JPEG, and PNG files. The created outputfile always has the same file format, data type, and dimensions as inputfile.

(RefLink[ImageFileApply, paclet:ref/ImageFileApply]) works on images with any number of channels.

The image files inputfile and outputfile can be given as a string or a (RefLink[File, paclet:ref/File]) object.

The function f should always return a number or a list of any length.

The channel values supplied to f are normally in the range 0 to 1, regardless of the underlying type used in the (RefLink[Image, paclet:ref/Image]) object. The function f is assumed to return channel values that are normally in the range 0 to 1.

The following options can be given:

The following suboptions can be given to (RefLink[Method, paclet:ref/Method]):

For the most efficient file processing, stripes or tiles of the image may be accessed in a specific order.

The value of the option "MaxBlockSize" may be exceeded if it is smaller than the smallest block supported for the input file.

With "ImageList"->{(Subscript[l, 1]),(Subscript[l, 2]),…}, the output image only contains the processed frames.

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Out-of-core negation of a JPEG file:

ImageFileApply[1-#&, ExampleData[{"TestImage", "Apples"}, "FilePath"]]

Import a thumbnail of the result:

Thumbnail[%]

Specify the output file name:

ImageFileApply[Mean,ExampleData[{"TestImage", "Flower"}, "FilePath"],"ImageFileApply-example.jpeg"]

OpenersExampleSection1(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)Interleaving  (1)

Use (RefLink[Interleaving, paclet:ref/Interleaving])->(RefLink[False, paclet:ref/False]) when the function has to be applied to each channel separately:

f[x_Real]:=Piecewise[{{2x,x<=.5},{2-2x,x>.5}}];
ImageFileApply[f,ExampleData[{"TestImage", "RadcliffeCamera"}, "FilePath"],Interleaving->False]

Import the resulting image:

Thumbnail@Import[%]

OpenersExampleSubsection1(Spacer1)Method  (2)

Apply the function to only one frame of a multi-image file using "ImageList":

path =ExampleData[{"TestImage3D", "Orbits"}, "FilePath"];

Import@ImageFileApply[1-#&,path,Method->{"ImageList"->50}]

Apply the function to a list of frames:

Import@ImageFileApply[1-#&,path, Method->{"ImageList"->{50,60}}]

Choosing an appropriate value of "MaxBlockSize" may significantly improve the performance:

path = ExampleData[{"TestImage", "Marruecos"}, "FilePath"];

Table[
AbsoluteTiming[ImageFileApply[#^2&,path,Method->{"MaxBlockSize"->size}];]//First,{size,{1000000,8000000}}]

OpenersExampleSection2(Spacer1)Applications  (2)

Out-of-core binarize a single channel image:

ImageFileApply[Boole[#<0.7]&,ExampleData[{"TestImage","ResolutionChart"},"FilePath"]]

Import the resulting image:

Import[%]

Create a darker version of an image:

ImageFileApply[0.5#&,ExampleData[{"TestImage", "Boat"}, "FilePath"]]

Import the resulting image:

Import[%]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ImageApply, paclet:ref/ImageApply])  ▪  (RefLink[ImageFileFilter, paclet:ref/ImageFileFilter])  ▪  (RefLink[ImageFileScan, paclet:ref/ImageFileScan])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[3D Images, paclet:guide/3DImages])}, {▪(RefLinkPlain[Image Processing & Analysis, paclet:guide/ImageProcessing])}})}})