Search code examples
androidimage-processingedge-detection

Sobel Edge Detection in Android


As part of an application that I'm developing for Android I'd like to show the user an edge-detected version of an image they have taken (something similar to the example below).

alt text

To achieve this I've been looking at the Sobel operator and how to implement it in Java. However, many of the examples that I've found make use of objects and methods found in AWT (like this example) that isn't part of Android.

My question is then really, does Android provide any alternatives to the features of AWT that have been used in the above example? If we were to rewrite that example just using the libraries built into Android, how would we go about it?


Solution

  • since you don't have BufferedImage in Android, you can do all the basic operations yourself:

    Bitmap b = ...
    width = b.getWidth();
    height = b.getHeight();
    stride = b.getRowBytes();
    for(int x=0;x<b.getWidth();x++)
      for(int y=0;y<b.getHeight();y++)
        {
           int pixel = b.getPixel(x, y);
           // you have the source pixel, now transform it and write to destination 
        }
    

    as you can see, this covers almost everything you need for porting that AWT example. (just change the 'convolvePixel' function)