Can't you fold all of the above into a call to smooth_img?