[TLDR] I am working on converting a segmentation model output into a shapefile that can be added as a layer on a map. I was hoping to find how to make each pixel value have a different color instead of all black?
I am relatively new to all of this. So far, I've been able to generate the shapefile using the script below:
from osgeo import gdal, ogr, osr raster = gdal.Open(r'test.tif') band = raster.GetRasterBand(1) array = band.ReadAsArray() proj = raster.GetProjection() shp_proj = osr.SpatialReference() shp_proj.ImportFromWkt(proj) output_file = 'test.shp' call_drive = ogr.GetDriverByName('ESRI Shapefile') create_shp = call_drive.CreateDataSource(output_file) shp_layer = create_shp.CreateLayer('LandCover', srs = shp_proj) new_field = ogr.FieldDefn(str('ID'), ogr.OFTInteger) shp_layer.CreateField(new_field) gdal.Polygonize(band, None, shp_layer, 0, , callback=None) create_shp.Destroy() raster = None
Are there any ways we can generate the shapefile so that each pixel values have different colors? eg
- 0 => transparent
- 1 => blue
- 2 => green etc.