working version for generating binary image, however the binary image is of low quality (WIP)