Sobel Edge Detection in Android

greenie picture greenie · May 30, 2010 · Viewed 19.5k times · Source

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?

Answer

X.Y. picture X.Y. · Jun 21, 2013

The question and answer are 3 years old... @reflog's solution works for a simple task like edge detection, but it's slow.

I use GPUImage on iOS for edge detection task. There is a equivalent library on Android: https://github.com/CyberAgent/android-gpuimage/tree/master

It's hardware accelerated so it's supposed to be very fast. Here is the sobel edge detection filter: https://github.com/CyberAgent/android-gpuimage/blob/master/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSobelEdgeDetection.java

According the doc, you can simply do this:

Uri imageUri = ...;
mGPUImage = new GPUImage(this);
mGPUImage.setGLSurfaceView((GLSurfaceView) findViewById(R.id.surfaceView));
mGPUImage.setImage(imageUri); // this loads image on the current thread, should be run in a thread
mGPUImage.setFilter(new GPUImageSobelEdgeDetection());

// Later when image should be saved saved:
mGPUImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);

Another option is using RenderScript, which you can access each pixel in parallel and do whatever you want with it. I don't see any image processing library built with that yet.