Image processing in Android and in Java (Eclipse) has different results

asked 2016-08-28 08:50:05 -0600

I'm having a strange problem trying to do some image processing. I've developed a script in Eclipse that does some processing with an image and returns a list of values about color comparing between fixed pixels of the image. In the processing I do these actions in the following order:

  • Resizing
  • Contours detection
  • Warp transformation
  • Conversion from BGR to Lab
  • Fixed pixels value comparison using Delta

I've implemented the exact same code in Android.

In Android I take a photo with the native camera, save it in the gallery, and pass the path of the photo in an intent, like this:

Intent intent = new Intent(this, ElaborationActivity.class);
intent.setData(Uri.parse(mCurrentPhotoPath));
startActivity(intent);

Then, in the new activity (the one that does the elaboration), I load the image and start the processing doing so:

String photoPath = getIntent().getData().toString();
Bitmap intentPhoto = BitmapFactory.decodeFile(photoPath);
Mat imgOr = new Mat();
Utils.bitmapToMat(intentPhoto, imgOr);
Elaboration ImElab = new Elaboration(imgOr.height(), imgOr.width());

In Eclipse I start the processing in this way:

Mat imgOr = Imgcodecs.imread(fileName);
ImageElaboration ImElab = new ImageElaboration(imgOr.height(), imgOr.width());

The rest of the code is exactly the same. The problem is that the elaboration done in Eclipse is way more precise and if I load in Eclipse the photo captured with the phone - photo that has been saved in .jpg in the gallery - and I try to use it to launch the script, the output I get in Eclipse is different from what I've got in Android.

Does anyone know why I get different results with the same photo? Could it be because in Android the photo is decoded in bitmap and in Eclipse I use the jpeg version? If so I'd like to know if there's a way to load in Android the jpeg version stored in the gallery.

Thanks

edit retag flag offensive close merge delete

Comments

1

you are using lossy jpg images, and 2 different libraries for decompressing will give differing results.

just avoid jpg images, if you need the results to be the same.

berak gravatar imageberak ( 2016-08-28 08:55:38 -0600 )edit

The real problem is that in Android I got wrong results, so I guess that in my particular case, the photo stored as jpeg let me do better processing (I can't understand why and how). I need to compare colors. For one specific pixel, I have to choose from 5 different colors which one is more similar. In Android, just to say, when I have light pink, the chosen color is dark brown (and in Eclipse light pink).

aguys91 gravatar imageaguys91 ( 2016-08-28 09:02:05 -0600 )edit
1

really, try with png images instead.

berak gravatar imageberak ( 2016-08-28 09:57:31 -0600 )edit

@aguys91 please, if people give you a suggestion, then actually try it before getting back with more questions :D

StevenPuttemans gravatar imageStevenPuttemans ( 2016-08-29 04:40:27 -0600 )edit

Thanks! I'm actually trying to figure out how to follow the suggestion, as I can only find Utils.bitmapToMat() and no implementations with png. I hope to solve this soon :)

aguys91 gravatar imageaguys91 ( 2016-08-29 04:44:43 -0600 )edit