Tried adding a grid for terrain images. Problem is that terrain[] is never null even though there's no real image stored.
Empty terrain images are now recognized by matching colors.
If there's empty color in 4 points whole image is empty.