Changing to imwrite and fixing preallocation bug for color images