some refactoring

some image processing code refactoring