function to downsample images