# List of image data without over exposed pixels

I have a greyscale png image and want to produce a list of all pixel values which are not 1 for analyzing them further.

image:

My code is the following:

image = Import["https://i.stack.imgur.com//SC0F3.png"];

RepeatedTiming[
imageData = ImageData[image];
imageDataWithout1 = DeleteCases[Flatten@imageData, value_ /; value == 1];
]
{0.13, Null}

(*imageDataWithout1 is the resulting list *)


Check:

Dimensions[Flatten@imageData] - Dimensions[imageDataWithout1]

{34323}

Count[Flatten@imageData, value_ /; value == 1]

34323


Can this also be done different, since the code is relatively slow?

On my machine Pick seems to be way faster:

image = Import["https://i.stack.imgur.com//SC0F3.png"];
RepeatedTiming[imageData = ImageData[image];
imageDataWithout1 =
DeleteCases[Flatten@imageData, value_ /; value == 1];]
imageDataWithout1 // Dimensions
(* {0.132, Null}
{253007} *)

RepeatedTiming[imageData = ImageData[image];
imageDataWithout1 =
Pick[#, UnitStep[# - 1.0], 0] &@Flatten@imageData;]
imageDataWithout1 // Dimensions
(* {0.0058, Null}
{253007} *)

• Why is this so fast? ... incredible ... thanks – mrz Mar 9 '17 at 23:07
• @mrz I think DeleteCases and Select apply your test function sequentially. UnitStep is Listable so it applies UnitStep[# - 1.0] to a list more effectively. – BlacKow Mar 10 '17 at 15:32