Image Processing for each Pixel Performance Problem

Problems with Canvas, OpenGL, etc...

Image Processing for each Pixel Performance Problem

Postby Dadom85 » Wed Mar 09, 2011 2:38 pm

Hello all,

i have a question concerning a ASyncTask in my app which should take a Bitmap and Check each Pixel for Color Value (R, G, B) and color this pixel white if its in the ReferenceColor or near this Color (Tolerance of 30 for R , G and B to both sides) and black if its not.

i realized it in a 2 dimensional array in which i extract the r g b colors , of each pixel, make a check and change the color value into black or white.

But this type of algorithm seems to take much time beyond acceptable response times (4 mp image takes ca. 5 mins)

my first question is: is there a option to improve the performance of my algorithm ??
(for example by calculate for the argb int value instead seperated for r g b. if yes, how?

i am open for all recommendations!

HEre is the Code:

Code: Select all
   final class BitmapToColorArray extends AsyncTask <Bitmap, Integer, File>
   {
   @Override
   protected File doInBackground(Bitmap... params) {      
      try {
         Bitmap uneditedBMP = params[0];
         int Treshold = 30;
         int ReferenceColor = Color.WHITE;
         int R_Reference = Color.red(ReferenceColor);
         int G_Reference = Color.green(ReferenceColor);
         int B_Reference = Color.blue(ReferenceColor);      
         
             int width = uneditedBMP.getWidth();
             int height = uneditedBMP.getHeight();
             int[][] IntArrayPresentation = new int[width][height];
             //TODO Check Possibility of taking 2 1-dimensional arrays
             int x;
             int y;
             int count = 0;
             
             for (x=0; x<width;x++)
             {
             for (y=0; y<height;y++)
             {
             IntArrayPresentation[x][y] = uneditedBMP.getPixel(x, y) ;
             int R_ActualPixel = Color.red(IntArrayPresentation[x][y]);
             int G_ActualPixel = Color.green(IntArrayPresentation[x][y]);
             int B_ActualPixel = Color.blue(IntArrayPresentation[x][y]);
             
             if (R_ActualPixel <= R_Reference + Treshold && R_ActualPixel >= R_Reference - Treshold && G_ActualPixel <= G_Reference + Treshold && G_ActualPixel >= G_Reference - Treshold && B_ActualPixel <= B_Reference + Treshold && B_ActualPixel >= B_Reference - Treshold)
             {
             IntArrayPresentation[x][y] = Color.WHITE;      
             }
             else
             {
             IntArrayPresentation[x][y] = Color.BLACK;
             }
             publishProgress(count++);           
             }
             } // Hier ist ende der ForSchleife             
      }
      catch (Exception e)
      {
      Log.e("Bitmap Convertion", "Error while Converting Bitmap to Int Array");
      Log.e("Bitmap Convertion", e.getMessage());
      Log.e("Bitmap Convertion", e.toString());
      }   
      Log.i("hmz","huhu");
      Log.i("hmz","huhu");
      Log.i("hmz","huhu");
      return null;      
   }
   @Override
   protected void onProgressUpdate(Integer... values) {      
   ViewCounter.setText(values[0].toString());
   }
   }
   }
Dadom85
Freshman
Freshman
 
Posts: 3
Joined: Wed Mar 09, 2011 2:19 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests