如何在Ruby中找到带有imagemagick的"entropy",最好是mini_magic?我需要这个作为一个更大的项目的一部分,在图像中找到"有趣",以便裁剪它.
我在Python/Django中找到了一个很好的例子,它提供了以下伪代码:
image = Image.open('example.png')
histogram = image.histogram() # Fetch a list of pixel counts, one for each pixel value in the source image
#Normalize, or average the result.
for each histogram as pixel
histogram_recalc << pixel / histogram.size
endfor
#Place the pixels on a logarithmic scale, to enhance the result.
for each histogram_recalc as pixel
if pixel != 0
entropy_list << log2(pixel)
endif
endfor
#Calculate the total of the enhanced pixel-values and invert(?) …Run Code Online (Sandbox Code Playgroud)