Solved an important bug when working on inverted images