raster2polygon slow for input masks that contain many small raster polygons.
Might be fixed by GDALSieveFilter like:
from osgeo import gdal
Image = gdal.Open('SomeImageName.tif', 1) # open image in read-write mode
Band = Image.GetRasterBand(1)
gdal.SieveFilter(srcBand=Band, maskBand=None, dstBand=Band, threshold=100, connectedness=8, callback=gdal.TermProgress_nocb)
del Image, Band # close the datasets.