For some time I've been interested in the concept of "smart cropping". There've been lots of articles about various approaches used, but most are relatively abstract. In order to better understand the techniques I find it best to experiment myself.
The first method I chose to experiment with is to estimate interesting parts of an image using
entropy. The entropy of an image, or region, is calculated using the histogram of the image. Then
for each pixel we determine the probability of that value being in the histogram and then
sum(p + log(p)).
The scripts load image data, and render the results, client side using a <canvas> element. Depending on your computer they might take a few seconds to finish. Red lines are overlaid at the "center of mass", this is just one way that image entropy might be used to find a cropping point.
The first script splits an image into regions and then calculates the entropy of each region. Each region then has its entropy overlaid, where the minimum entropy in the image is black and the maximum entropy is white. You can play with the region size to see how it effects the center of mass.
The second script calculates an "energy" for each pixel, based on the entropy of the 25 surrounding pixels. The histogram is compressed to 25-colors, to create better separation. The visualization is a bit different from the first script, hovering over will show you the original.