0

I have few 100x100 bitmaps stored and I want to compare other incoming 100x100 bitmaps in my app with the existing ones to find out similarity between the images and return the result to the user that which bitmap the matches with the incoming bitmap.

For example, Consider this exciting bitmap which I already have: The background of the image is transparent in reality

Existing Bitmap

Then I receive the following bitmap as input from the user :

User input image

Now, I want to output the user some similarity measure and tell the user that these both are similar since they are straight, pointing upwards and they have a trailing like an effect from the bottom.

Currently I have tried the following approaches but they don't work as expected

  1. Extract pixels from the bitmap object and compare the arrays
  2. Encode the bitmap to base64 string and then compare

If anyone suggests me OpenCV then please explain the OpenCV approach in detail. I couldn't find any proper material/resources for OpenCV android / Java tutorials for finding similarity between images.

jashgopani
  • 565
  • 7
  • 13
  • For that, you will need to use advanced tools like ML libs. Because it is something you can't do with simple code unless the images are the same. – Omid.N Jun 08 '20 at 14:12
  • Have a look at this question https://stackoverflow.com/questions/8567905/how-to-compare-images-for-similarity-using-java and this example also https://rosettacode.org/wiki/Percentage_difference_between_images#Java and the task you want to perform is not of basic level you need some advance concepts or an algorithm. – Prathamesh Jun 08 '20 at 14:15
  • @Omid.N, can you share what kind of concepts/algorithms can help me achieve my goal? – jashgopani Jun 08 '20 at 14:35
  • @Prathamesh Jadhav I've already tried those methods which you shared in the links which are based on comparing images based on difference of pixel values, it didn't help me to get desired output – jashgopani Jun 08 '20 at 14:38
  • @struct_dhancha Sorry! I don't have any speciality in Machine Learning. But I know that there is no single method that would do that so easily. – Omid.N Jun 08 '20 at 14:52

1 Answers1

0

I finally achieved what i wanted by

  1. Scale the input and stored bitmap to 100x100.
  2. Extract the alpha layer of the above two by using bitmap.extractAlpha().
  3. Calculate the cosine similarity of the input by extracting pixels using getPixels(); the similarity will be in range -1 to 1.
  4. If the similarity > threshold (0.6 in my case) , then return same else different
jashgopani
  • 565
  • 7
  • 13