added image processing code to function