title: Assign color to a pixel based on its neighbors
body: <p>I've put all the black pixels of the image in an array and I want them to get the color of their left neighbor. I run the code without errors but the result is not really what I'm expecting.
  Where those black stripes comes form? I was expecting it to be all red.</p>
  
  <p>Here's my code and results.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.image.BufferedImage;
  import java.util.*;
  
  
  public class ImageTest {
      public static BufferedImage Threshold(BufferedImage img) {
  
          int height = img.getHeight();
          int width = img.getWidth();
          BufferedImage finalImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  
          int r = 0;
          int g = 0;
          int b = 0;
          List&lt;Integer&gt; blackpixels = new ArrayList&lt;Integer&gt;();
  
  
  
          for (int x = 0; x &lt; width; x++) {
              try {
  
                  for (int y = 0; y &lt; height; y++) {
  
                      //Get RGB values of pixels
                      int rgb = img.getRGB(x, y); 
                      r = ImageTest.getRed(rgb);
                      g = ImageTest.getGreen(rgb);
                      b = ImageTest.getBlue(rgb);
  
                      int leftLoc = (x-1) + y*width;
  
                      if ((r &lt; 5) &amp;&amp; (g &lt; 5) &amp;&amp; (b &lt; 5)) {
                          blackpixels.add(rgb);
                          Integer[] simpleArray = new Integer[ blackpixels.size() ];
                          System.out.print(simpleArray.length);
  
                          int pix = 0;
  
                          while(pix &lt; simpleArray.length) {
                              r = leftLoc;
                              pix = pix +1;   
                          }
  
  
                      }
  
                      finalImage.setRGB(x,y,ImageTest.mixColor(r, g,b));  
                  }
  
                  }
              catch (Exception e) {
                      e.getMessage();
              }
      }
      return finalImage;
  
      }
      private static int mixColor(int red, int g, int b) {
          return red&lt;&lt;16|g&lt;&lt;8|b;
      }
  
      public static int getRed(int rgb) {
          return (rgb &amp; 0x00ff0000)  &gt;&gt; 16;
      }
  
      public static int getGreen(int rgb) {
          return  (rgb &amp; 0x0000ff00)  &gt;&gt; 8;
      }
  
      public static int getBlue(int rgb) {
          return (rgb &amp; 0x000000ff)  &gt;&gt; 0;
  
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xPwmy.jpg" alt="enter image description here"></p>