So, around a week ago I was struggling to compare similarities between two images and found a way i.e Phash (perceptual hash) algorithm. It's based upon https://www.phash.org/.❤️
repositories {
maven { url 'https://jitpack.io' } // Add jitpack
}
dependencies {
implementation 'com.github.KapilYadav-dev:Phasher:Tag'
}
fun Phash(
fileOnePath: String?, // path of Image one
fileTwoPath: String?, // path of Image two
bitSize: Int = 8 // This is the size you want to resize, can play with it for more accuracy and its best with the value 8
)
fun Phash(
uriOne: Uri?, // Uri for Image one
uriTwo: Uri?, // Uri for Image two
context: Context
)
val score = Phash(path1,path2).getSimilarityScore()
// score = 70 %
val scoreTwo = Phash(uri1,uri2,context).getSimilarityScore()
// score = 70%
Image 1 | Image 2 |
---|---|
Choose your threasold for your image as per your usecase.
For a standard one, we use 75 % threasold that means above its image are similar.
👤 mrkaydev
- Linkedin: @mrkaydev
- Email: [email protected]
Feel free to ping me 😉
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Open an issue first to discuss what you would like to change.
- Fork the Project
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a pull request
Please make sure to update tests as appropriate.
Give a ⭐️ if this project helped you!
Copyright © 2022 - mrkaydev
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.