fixed the index of output image;optimized file output;