06 December 2011

After my first solution to unshredder challenge I started working on the bonus part of the problem: auto-detecting how wide the uniform slices are.

My plan was pretty simple:

for each vertical column of pixels X[i]
    calculate distance D[i] = distance(X[i], X[i+1]
Dmax = sort D desc
for each slice width W
    M = number of borders with slice width *W*
    P = number of borders in the first *M* elements of Dmax with slice width *W*
    return w with max(P / M)

The plan worked otherwise great except that slice width 256 (2 slices) maximized my P / M. I fixed that by returning the first W that exceeds a given threshold.

The result is the following python code:

Links

sources



blog comments powered by Disqus