25

Does anyone know of any good image processing tutorials for android? I'm new to android, and I'm coding an app that places an effect on a bitmap. I can find plenty of tutorials in java, but android does not support awt. I'd like to manipulate the pixels in the bitmap just using the android sdk, e.g. warping, fisheye etc. I can access the pixels and change their colour but I'm not too good with transformations, and not sure where to start.

Jota
  • 17,281
  • 7
  • 63
  • 93
turtleboy
  • 8,210
  • 27
  • 100
  • 199
  • Any chance of charing the code with the rest of the world? – netlander Jun 15 '11 at 16:36
  • @netlander of course there is sir. I've got the app effect working now and did so in Android alone. i re-coded a filters class to use bitmap instead of buffered image. http://stackoverflow.com/questions/1927145/how-to-simulate-fisheye-lens-effect-by-opencv – turtleboy Jun 15 '11 at 19:30

4 Answers4

19

Check this out (scroll down after [The Basics] 29):

http://xjaphx.wordpress.com/learning/tutorials/

Has some great tutorials like:

  • Mean Removal effect
  • Smooth effect
  • Emboss effect
  • Engraving effect
  • Boost up color intensity
  • Rounded Corner Image
  • Watermarking on the fly
  • Image Flipping / Mirroring
  • Pixel Color Replacement
  • Tint Color
  • Flea / Noise Effect
  • Black Filter (Increasing the Darkness)
  • Snow Effect
  • Shading Filter
  • Saturation Filter
  • Hue Filter
  • Image Reflection Effect
  • Draw Text on a Curve
Oded Breiner
  • 28,523
  • 10
  • 105
  • 71
8

You can also checkout JavaCV that give you Java Objects with bindings to opencv lib. This way you wouldn't need to do any c/c++ coding, you can do all directly in Java and access functions from opencv.

Google code Project

Answer to your followup question:

For example, take a cylindrical projection: Take a look at the image -

image

(sorry I'm not allowed to post pictures) this is taken from Szeliskis book (http://szeliski.org/Book/). The relation you have here in the end is

x'=s*tan⁻¹(x/f) 

and

y'=s*(y/sqrt(x²+f²)) 

where f is the focal lenght of a camera and s the radius of the cylinder, you can use f=s. Now to get this into loops, here is some pseudocode:

%% xMitte , yMitte are the coordinates for the point in the middle
for yNeu =1: height
   for xNeu =1: width
      dx = xNeu - xMitte ; %% X relativ to origin
      dy = yNeu - yMitte ; %% Y relativ to origin
      theta = atan(dx / f);
      h = dy / sqrt(dx ^2+f^2);
      x = (f * theta) + xMitte ;
      y = (f * h) + yMitte ;
      BildNeu (xNeu ,yNeu) = BildAlt (x, y);
   end
end

BildNeu is the new picture, this array has the same size as BildAlt (the original picture).

The Line with BildNeu and BildAlt at the end of the inner loop could be like:

/** returns the color value of that pixel **/
CvScalar pixel = cvGet2D(originalImage, i, j);
/** writes the new color value of that pixel **/
cvSet2D(destinationImage, y, x, pixel);
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
rac2030
  • 507
  • 3
  • 10
  • ok thanks, is it easy to do radial transforms using javacv? – turtleboy May 30 '11 at 19:29
  • I have to say that I never worked with javacv... only directly with opencv (android branch => http://opencv.willowgarage.com/wiki/AndroidTrunk). You can do transformations if you know the transformation matrix very easily, else if you just know the formula for the projection you want you can write loops and transform every pixel to the new coordinate by your own. – rac2030 Jun 05 '11 at 10:26
  • hi thanks for getting back. i found a post where somebody had transcribe a fisheye distortion from C++ into java. It used awt's bufferedImage so i just matched up the setARGB methods in that class to the corresponding setPixel methods in the bitmap class and it works:). i would be interested in what you mentioned above with the loops. how would you do that if you only know the formular for the projection? how would i transform each pixel to it's new coordinate? do i just have a src array and a dst array and apply the formular? – turtleboy Jun 05 '11 at 11:09
  • @turtleboy I added an example in my answer (as formatting in the code is not possible that it looks nice. And sorry for not translating variable names but I just copy pasted from my diploma thesis (on German) as I've explained in there the projection I used in my code – rac2030 Jun 05 '11 at 18:27
  • Thanks alot for the example and taking time to share it. Maths is not my strong point but i'll have a look. i've found some code that works that somebody transcribed from c++ into java. i then refactored that code to work with a bitmap instead of bufferedImage. But i need to delve deeper into graphics for my own benefit. thanks again. matt – turtleboy Jun 07 '11 at 17:26
3

OpenCV Android is preferred due to the ease of use on an Android platform, although there maybe limitations. Here are some references that might help:

1.The best way to learn Image Processing on an Android platform is via implementation. Try running and understanding the existing OpenCV4Android Samples on Android Studio/Eclipse. They are available on https://github.com/joaopedronardari/OpenCV-AndroidSamples .

The description of each sample is available on the OpenCVAndroid Samples page. Mixed Processing, Camera Control, Image Manipulations and color-blob-detection deal with pre-processing and image manipulations. They comprise:

RGBA and GRAY preview

Canny (Edge Detection)

Finding Features

Colour Effects

Histograms

Sepia

Sobel Filter

Zoom

Pixelize

Posterize

Watershed transformation

Markers (blob detection)

  1. Since you will be working on a Java platform ,the OpenCV Java tutorials will be of use.

  2. http://web.stanford.edu/class/ee368/Android/ has sample projects.

4.Check out The Android Arsenal, for Image Processing libraries.

Note:A Mat object has to be converted to a Bitmap object, in order to display it on the device screen (ImageView).

Sukriti
  • 66
  • 5
1

Perhaps you will have some success with the OpenCV java bindings. Other than that there is not really anything that I know of that will help.

Robert Massaioli
  • 13,379
  • 7
  • 57
  • 73