0
$\begingroup$

I have large data sets of grayscale images of 1024*2048 pixels.

What is a fast method to count the number of overexposed pixels in image columns?

The following example shows what I did:

SeedRandom[1];
imageData = RandomInteger[255, {100, 200}];
image = Image[imageData, "Byte"]

enter image description here

n = Count[#, value_ /; value == 255] & /@ Transpose@imageData;

ListPlot[n, Frame -> True, 
 FrameLabel -> {"row", "overexposed pixels per column"}]

enter image description here

$\endgroup$
  • $\begingroup$ Using Count without the conditional (/;) seems to be 30 x faster. Count[#, 255] & /@ Transpose@imageData; $\endgroup$ – Anjan Kumar Feb 9 '18 at 15:34
  • $\begingroup$ @Anjan Kumar: Thanks. Put it into an answer. This is really much faster. In your solution the Transpose itself takes much more time than the counting. $\endgroup$ – mrz Feb 9 '18 at 15:47
  • $\begingroup$ Check the new version which is faster and avoids transpose operation. $\endgroup$ – Anjan Kumar Feb 9 '18 at 16:26
4
$\begingroup$

Update A faster version using Vectorized operations.

Total[UnitStep[imageData - 255]];// AbsoluteTiming

{0.0000731023, Null}

--

Using Count without the conditional (/;) is 30 x faster.

Count[#, 255] & /@ Transpose@imageData;// AbsoluteTiming
Count[#, value_ /; value == 255] & /@ Transpose@imageData;// AbsoluteTiming

{0.000198258, Null}

{0.00582259, Null}

$\endgroup$
  • $\begingroup$ Thanks. This is great. $\endgroup$ – mrz Feb 9 '18 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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