title: MATLAB: Find indices/count of specific rgb pixel values in image
body: <p>I'm using matlab to get counts of specific pixel values in an image. </p>
  
  <p>Images are RGBA &lt;512x512x4 uint8> when read into matlab (although we can disregard the alpha channel).</p>
  
  <p>Other than; </p>
  
  <pre><code>[width, height, depth] = size(im);
  
  for x = 1 : width;
      for y = 1: height;
  
          r = im(x,y,1);
          g = im(x,y,2);
          b = im(x,y,3);
  
          ...
  
      end
  end
  </code></pre>
  
  <p>Is there a way I can do this using matrix operations? Something along the lines of:</p>
  
  <pre><code>X = find(im(:,:,1) == 255 &amp;&amp; im(:,:,2) == 255 &amp;&amp; im(:,:,3) == 255);
  count = length(X);
  % Count being the number of pixels with RGB value (255,255,255) in the image.
  </code></pre>
  
  <p>I'm guessing there's more than a few ways to do this (looking at intersect, unique functions) but I'm not clever enough with matlab to do this yet. Any help? </p>