photo duplicate

Find Duplicate Images using Java Cloud SDK

Our brain dedicates itself to visual processing and our love for images lies with our cognition and ability to pay attention. The images are able to grab our attention easily and many devices including cellular phones digital cameras, scanners etc. produce a large amount of images. Further, images have different compression algorithms and raster images are very common among them because, they consume less storage space. But still, with the passage of time, we end up creating duplicate photos, redundant images etc. We have a plethora of applications offering the capabilities to find duplicate images including duplicate picture finder. In case you have images stored in google photos, you may try using google photo duplicate finder, install duplicate photo finder windows 10 or duplicate photo finder mac (depending upon your operating system). However in this article, we are going to shed light on how to develop an awesome duplicate photo finder using REST API which can be used on any platform.

Image Processing API

A variety of applications are available for image processing offering the features to create, edit and manipulate image files. They also provide the capabilities including image search based on reverse image search techniques or any other algorithm. However, if you’re interested in having REST API based programmatic solution based on reverse image search, then Aspose.Imaging Cloud is the definite choice. Its powerful search engine helps developers to add reverse image search features in their application on any platform seamlessly. You may even start image comparison operation to find photo duplicate among several other images. As a result of this operation, you get the list of most similar images in-accordance to the following conditions:

  • Degree of similarity
  • The minimal threshold of similarity
  • Algorithm of comparison

Now in order to have similar image processing and duplicate picture finder capabilities within Java application, we need to use Aspose.Imaging Cloud SDK for Java as it’s a wrapper around Cloud API. So the next step is to add its reference in java project by including following information in pom.xml of maven build type project.

<repositories> 
    <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>http://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-imaging-cloud</artifactId>
        <version>22.4</version>
    </dependency>
</dependencies>

Now if you have not created an account over Aspose Cloud Dashboard, you can sign up for a Free Trial through a valid email address. Now login using newly created account and lookup/create Client ID and Client Secret at Cloud Dashboard. These details are required for authentication purposes in the following sections.

Find Duplicate Images using Java

The Reverse Image Search is a technique that helps you search visually similar images based upon your sample image. Given below are the most common use cases for this feature:

Search for duplicate image and remove the duplicates
Search for content similar images
Search for inappropriate content
Search for digitally signed images

Our API currently supports content-based image search, duplicate image search, image search by custom registered tags, image comparison and similarity detection and Image features extraction operations. Now in this section, we are going to discuss the details on how to find duplicate images using reverse image technique. Now in order to accomplish this requirement, we use AKAZE algorithm for features detection and RandomBinaryTree algorithm for feature matching in the example. We’ll follow these steps to find the duplicate images:

  • Upload Images to Cloud Storage
  • Create Search Context
  • Extract Image Features
  • Find Duplicate Images

Upload Images to Cloud Storage

Please use the following code snippet to upload image files from local drive to cloud storage

  • Firstly, create an object of ImagingApi while providing ClientID and Client
  • Secondly, read all image files from specified directory
  • Filter only image files and add them to the filtered list
  • Upload the images to Cloud storage using uploadFile(…) method while taking UploadFileRequest object as argument

Create Search Context

  • First we need to specify feature detection algorithm as akaze
  • Secondly, specify algorithm for feature matching as randomBinaryTree
  • Thirdly, create Image Search Request using CreateImageSearchRequest object
  • Now create create search context status through createImageSearch(…) method

Extract Image Features

Now its time to extract images features and add them to search context.

Find Duplicate Images

  • Specify similarity threshold value
  • Secondly, create duplicate image set using ImageDuplicatesSet object
  • Now iterate through the list of duplicate images and find image similarity using getSimilarity(…) method

Find Photo Duplicate using cURL Commands

In this section, we are going to take leverage of using cURL commands to access REST APIs over the command line terminal. Now as a pre-requisite, we need to first generate a JWT access token (based on client credentials) while executing the following command.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

This step expects that all images are uploaded to cloud storage and now we need to create search context ID through CreateImageSearch API call. Please execute the following command

curl -v -X POST "https://api.aspose.cloud/v3.0/imaging/ai/imageSearch/create?detector=akaze&matchingAlgorithm=randomBinaryTree" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Response body

{
  "id": "0b9ac539-07fb-462a-91cb-8a8d5069ba4d",
  "searchStatus": "Idle"
}

Please execute the following command to find Image duplicates using FindImageDuplicates API call. In following command, the search context ID generated above is used.

curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/ai/imageSearch/da150333-57b4-4371-b13d-4889578ce2bd/findDuplicates?similarityThreshold=90" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Conclusion

In this article, we are have learned about the details on how to find duplicate Images using Java Cloud SDK. Similarly, we have learned how cURL commands can serve as a duplicate picture finder. In case you need to try out these APIs within browser, please try using the swagger API Reference. Similarly, we highly recommend exploring Product documentation to learn other exciting features being offered by this API. Also, please note that all our Cloud SDKs are published under MIT license, so you may consider downloading the complete source code from GitHub and modify it as per your requirements. In case of any issues, you may consider approaching us for a quick resolution via free product support forum.

Please visit the following links to learn more about: