optimize image array allocation (-3s in average)