rewritten from c code
it works!
tested on 1 image...
it works!
tested on 1 image...