This code is slightly slower than Astro-SCRAPPY, and I've done some microbenchmarks to investigate. The majority of the time difference appears to be during the median filtering. I suspect the completely hand-written medians in AstroSCRAPPY's C source are the reason why.