0 Replies Latest reply on Jul 30, 2009 8:28 AM by norm.mcgarry

    Pixel checking from a single point in an image

    norm.mcgarry

      Hi,

       

      I am trying to write an algorithm to analyze and image similar to the magic wand tool in photoshop and I'm hoping someone can help me with it or point me to resources to help me. I figured this would be a good place to go.

       

      I'm getting an "undefined" exception in Flex when I publish using this algorithm. I know the algorithm is horrible and it is probably due to so many recursions. I just threw it together and know there are MANY better ways, so advice would be great.

       

       

      public function processPixel(source:BitmapData, processedBitmap:BitmapData, processingPoint:Point, referencePoint:Point):void
              {
                  if(v[processingPoint.x][processingPoint.y])
                      return;
                 
                  var referenceColor:uint = source.getPixel(referencePoint.x, referencePoint.y);
                  var processingColor:uint = source.getPixel(processingPoint.x, processingPoint.y);
                 
                  var isSimilar:Boolean = MarchingSquareExtraction.testRGB(referenceColor, processingColor);
                 
                  if(isSimilar)
                  {
                      var processRect:Rectangle = new Rectangle(processingPoint.x,processingPoint.y,1,1);
                      processedBitmap.copyPixels(source,processRect,processingPoint);
                  }
                  else
                  {
                      return;
                  }
                 
                  v[processingPoint.x][processingPoint.y] = true;
                 
                  var point1:Point = new Point(processingPoint.x+1, processingPoint.y);
                  if(v[point1.x][point1.y] != true)
                      processPixel(source, processedBitmap, point1, referencePoint);
                 
                  var point2:Point = new Point(processingPoint.x-1, processingPoint.y);
                  if(v[point2.x][point2.y] != true)
                      processPixel(source, processedBitmap, point2, referencePoint);
                 
                  var point3:Point = new Point(processingPoint.x, processingPoint.y+1);
                  if(v[point3.x][point3.y] != true)
                      processPixel(source, processedBitmap, point3, referencePoint);
                 
                  var point4:Point = new Point(processingPoint.x, processingPoint.y-1);
                  if(v[point4.x][point4.y] != true)
                      processPixel(source, processedBitmap, point4, referencePoint);
              }