title: Converting 3-dimensional byte array to a single byte array
body: <p>I have a 3 dimensional byte array.</p>
  
  <p>The 3-d array represents a jpeg image. Each channel/array represents part of the RGB spectrum.</p>
  
  <p>I am not interested in retaining black pixels. A black pixel is represented by this atypical arrangement:</p>
  
  <pre><code>myarray[0,0,0] =0;
  myarray[0,0,1] =0;
  myarray[0,0,2] =0;
  </code></pre>
  
  <p>So, I have flattened this 3d array out to a 1d array by doing this <code>byte[] AFlatArray = new byte[width x height x 3]</code> and then assigning values respective to the coordinate.</p>
  
  <p>But like I said I do not want black pixels. So this array has to only contain color pixels with the x,y coordinate. The result I want is to re-represent the image from the i dimension byte array that only contains non-black pixels. How do I do that?</p>
  
  <p>It looks like I have to store black pixels as well because of the xy coordinate system. I have tried writing to a binary file but the size of that file is greater than the jpeg file as the jpeg file is compressed.</p>
  
  <hr>
  
  <p>I need a single byte array because I have an image which has Red green and Blue components. I want to store the difference between 2 images. So, this is a 3 dim array. As not all the pixels will be different I wanted to store only the differences. But, even flattening out the size is still bigger than the byte size of the image (because it is a jpeg and compressed). </p>
  
  <p>I am using emgu image framework. When you enumerate through the data of an image it can give you 3 channels each represented by a dimension in a byte array. The 3 channels I am working with are (R)ed, (G)reen and (B)lue. I could be working in the color space of HSL or HSV (etc) and then I could be working with 3 channels of Hue, Saturation and luminance.</p>