final Image processing code