Trending News
Home / Web Development / PHP / Image Cropping using Entropy – PHP

Image Cropping using Entropy – PHP

Cropping or resizes the images are very common scenario for most websites. This technique is used for create the thumbs in web sites.



Cropping Using Traditional Techniques

First, assume that we want to use below photo of a man holding a camera in our website.

entropy1



Now let’s also assume that our website uses 230×270 thumbs. The current image is 800*533 pixel, resizing and cropping is in order.

Most libraries in order to avoid stretching, utilize what is known as smart cropping. This means that, when one dimension is equal to the desired one, the code will resize the image, the code will check if the other dimension is also correct. If not, the code will crop starting from the center in order to reach the final dimensions. Using this technique the generated thumb is similar to this.

entropy2



This result however is less than ideal. The more “interesting” part of the photo is obviously the right one, the man actually holding the camera, and part of it got cut off. By calculating the image’s entropy, we can determine which part of the photo has more energy and keep that one instead.

What is Image Entropy

The Image entropy is used to describe the `business’ of an image. And the amount of information coded by a Compression algorithm.

Calculating Image Entropy

entropy_calculation



If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Loading Facebook Comments ...
Social Media Auto Publish Powered By : XYZScripts.com