Image partition algorithm implementing.