ENIMDA
Entropy-based image border detection algorithm: detect border or whitespace offset for every side of image, supports animated GIFs.
Prerequisites
GraphicsMagick (http://www.graphicsmagick.org/)
Algorithm (simplified)
For each side of the image starting from top, rotating image counterclockwise to keep side of interest on top:
- Get upper block 25% of image height
- Get lower block with the same height as the upper one
- Calculate entropy for both blocks and their difference
- Make upper block 1px less
- Repeat from p.2 until we hit image edge
- Border is between blocks with entropy difference maximum
Example
Find image borders:
#include "ENIMDA.hpp"
#include <iostream>
using namespace std;
using namespace Magick;
using namespace ENIMDA;
int main(int argc, char **argv) {
InitializeMagick(*argv);
Loader em("example.jpeg", 0, 0, 0.25, 0);
vector<unsigned int> borders = em.scan(true, true, 0.5);
for (auto &border : borders) {
cout << border << " ";
}
cout << endl;
return 0;
}
Demo
For demo please refer to ENIMDA Demo
Also it lives at Picture Instruments as 'Remove borders' instrument