How to despeckle to remove point noise from an image in Java
Often the most subtle of filters have the best effect on a photo. This is certainly true of noise reduction, which can have a pleasantly smoothing effect on an image without the detail loss of a blur. That being said, writing a script for this effect is quite an undertaking. What would you say if we could shave off about 99% of the work required? We can accomplish this easily using an API, as you shall see.
The first step for us is to install our library using Jitpack. To do this, we must simply add these two references to pom.xml via the following code snippets:
Repository snippet
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Dependency snippet
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v2.75</version>
</dependency>
</dependencies>
Now we can invoke filterDespeckle and give it an imageFile, as you see demonstrated here:
// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.FilterApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");FilterApi apiInstance = new FilterApi();File imageFile = new File("/path/to/file"); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try {byte[] result = apiInstance.filterDespeckle(imageFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling FilterApi#filterDespeckle");e.printStackTrace();}
And it’s as simple as that. How about we try it out on a photo?
Now here is the result after despeckling:
Subtle, but undeniably improved.