I want to collect cloud-free surface reflectance images using a cloud masking function and then compute NDVI. However, the output image has some transparent areas that can't be used in the next step. How can I solve this problem?
Cloud masking works by removing clouds from the dataset and giving them a 'null' value, which is why you have 'holes' in your image. How you handle this will depend on how much you value the specific time point and data accuracy. For the most accurate data possible on a given date you will have to accept the null values. If you are willing to do some interpolation, you have two options.
If you care more about specific time points and the cloud masked areas are relatively small, you could use a local filter to fill in the null areas with the local average. You could do this simply with
.focal_mean across the entire image (with a radius relevant to your needs), or you could execute a more complicated function to only map this near null areas (though I am not sure how to do this in your context).
If you are ok with spatial averaging you could invoke a reducer (like
ee.Reducer.mean()) over a date window. This may fill in the cloud gaps assuming that there are not consistent clouds between image dates. This can be more easily calculated on a single window with a reducer and a date filter, but requires a moving window if you want to map it over multiple time windows throughout an image collection.