({{, (RefLink[ImageScan, paclet:ref/ImageScan])[f,image] 
evaluates f applied to each pixel of image in turn.}})

OpenersNotesSection(Spacer1)Details and Options

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.

(RefLink[ImageScan, paclet:ref/ImageScan])[f,image] discards the results of applying f to the pixels in image. Unlike (RefLink[ImageApply, paclet:ref/ImageApply]), (RefLink[ImageScan, paclet:ref/ImageScan]) does not build up a new image and returns (RefLink[Null, paclet:ref/Null]).

(RefLink[ImageScan, paclet:ref/ImageScan]) is useful in carrying out an operation on parts of expressions where the operation has a "side effect", such as making an assignment.

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

You can also use (RefLink[Throw, paclet:ref/Throw]) to exit from (RefLink[ImageScan, paclet:ref/ImageScan]). »

(RefLink[ImageScan, paclet:ref/ImageScan]) traverses the pixels of image in a row-wise order from left to right.

(RefLink[ImageScan, paclet:ref/ImageScan]) has the option (RefLink[Interleaving, paclet:ref/Interleaving]), which specifies whether f should be applied to individual channel values or to the complete list of channel values for a given pixel. The default setting is (RefLink[Interleaving, paclet:ref/Interleaving])->(RefLink[True, paclet:ref/True]).

With the setting (RefLink[Masking, paclet:ref/Masking])->roi, a region of interest to be scanned can be specified.

(RefLink[ImageScan, paclet:ref/ImageScan]) works with (RefLink[Image3D, paclet:ref/Image3D]) objects.

OpenersPrimaryExamplesSection(Spacer1)Examples  (11)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Scan pixels of a grayscale image:

ImageScan[Print,]

Scan pixels of a color image:

ImageScan[Print[Style[#,RGBColor@@#]]&,]

Scan pixels of a 3D image:

ImageScan[Print,]

Count the number of white pixels in an image:

count=0;
ImageScan[If[Mean[#]==1,count++]&,]

count

Compute the mean pixel value:

mean={0,0,0};
ImageScan[mean+=#&,i=]

mean/=Times@@ImageDimensions[i]

OpenersExampleSection1(Spacer1)Generalizations & Extensions  (1)

(RefLink[Throw, paclet:ref/Throw]) works inside (RefLink[ImageScan, paclet:ref/ImageScan]):

Catch[ImageScan[If[#<0,Throw[#1]]&,]]

OpenersExampleSection2(Spacer1)Options  (4)

OpenersExampleSubsection0(Spacer1)Interleaving  (2)

By default, lists of channel values are scanned:

ImageScan[Print,]

Using (RefLink[Interleaving, paclet:ref/Interleaving])->(RefLink[False, paclet:ref/False]), individual channel values can be scanned:

ImageScan[Print,,Interleaving->False]

The interleaving setting does not affect the traversal of a single-channel image:

ImageScan[Print,,Interleaving->True]

ImageScan[Print,,Interleaving->False]

OpenersExampleSubsection1(Spacer1)Masking  (2)

By default, all image pixels are scanned:

counter=0;
ImageScan[counter++&,]
counter

Scan only the pixels specified by the mask:

counter=0;
ImageScan[counter++&,,Masking->]
counter

Compute the mean color of the Spikey:

i=;mask=;
counter=0;mean={0,0,0};
ImageScan[(mean+=#;counter++)&,i,Masking->mask]
mean/counter

Create a disk of the computed mean color:

Graphics[{RGBColor[%],Disk[]},ImageSize->Tiny]

Mean color computed without masking:

counter=0;mean={0,0,0};
ImageScan[(mean+=#;counter++)&,i];
Graphics[{RGBColor[mean/counter],Disk[]},ImageSize->Tiny]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

(RefLink[ImageScan, paclet:ref/ImageScan]) does the same as (RefLink[ImageApply, paclet:ref/ImageApply]), but without returning a result:

ImageScan[(Print[#];#)&,]

ImageApply[(Print[#];#)&,]

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

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Basic Image Manipulation, paclet:guide/BasicImageManipulation])}, {▪(RefLinkPlain[Color Processing, paclet:guide/ColorProcessing])}})}})