I have images that are very tall (~6000px tall by ~1000px wide) and I want to remove "boring parts" from them, where "boring parts" means segments where the same (or almost the same) rows of pixels are repeated more than 50 rows at a time. So for a simple example, if I had a 6000px tall image where the first 1000 rows had lots of text and shapes etc, and then the next 5000 rows were just (from left to right) 50 blue pixels followed by 950 red pixels) repeated row-after-row all the way down, I'd want to crop all but 50 of those rows.
Is there a clever/easy way of doing this with ImageMagick (or some other tool)?
If I were writing the algorithm (naively), I would do something like this:
Code: Select all
Current50rows = 2-dimensional array of pixel RGBs
while (not at end of image) {
Next50Rows = 2-dimensional array of pixel RGBs
differenceBetweenSlices = 0;
For (rowNum = 0; rowNum < 50; rowNum++) {
for (colNum = 0; colNum < 1000; colNum++) {
//if the pixels are more than just slightly different, increment the "difference meter"
if (abs( Current50Rows[rowNum,colNum] - Next50Rows[rowNum,colNum] ) < threshold) {
differenceBetweenSlices++
}
}
}
//slices are basically the same
if (differenceBetweenSlices < 50) {
DeleteCurrent50RowsFromImage
}
Current50Rows = Next50Rows;
}