how custom discreate colormap work with expression #721
Replies: 2 comments 2 replies
-
what is not expected in your results? I think what you want to use is not discrete colormap but interval colormap https://cogeotiff.github.io/rio-tiler/colormap/#intervals-colormaps
or maybe make a import bisect
cm = {
0: (0, 0, 255, 255), # Blue for non-vegetation (e.g., water)
63: (0, 255, 255, 255), # Cyan for barren land or built-up areas
127: (255, 255, 0, 255), # Yellow for sparse vegetation
153: (200, 255, 0, 255), # Light green for low vegetation
178: (100, 255, 0, 255), # Green for moderate vegetation
204: (0, 255, 0, 255), # Dark green for dense vegetation
255: (0, 128, 0, 255) # Very dark green for very dense vegetation
}
keys = list(cm)
ndvi_dict = {
ii: cm[keys[bisect.bisect(keys, ii) - 1]]
for ii in range(0, 255, 1)
}
ndvi_dict[255] = (0, 128, 0, 255)
cmap = cmap.register({"ndvi": ndvi_dict}) |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response and for the great work on this project. I'm a bit confused about creating a custom colormap, and I would appreciate your guidance. For example, if I have a multiband image, how should I specify the value range to set the colors? Specifically: Should I set the range using values after rescaling, such as with an expression like expression="(b3-b1)/(b1+b3)", and then assign the color red to the range (0,1)? |
Beta Was this translation helpful? Give feedback.
-
I'm attempting to create a custom colormap for my NDVI raster, but I think I might have misunderstood something, as the results aren't quite what I expected. Could you please help me figure out what might be going wrong?
first i try
ndvi_cmap = {
-1: (0, 0, 255, 255), # Blue for non-vegetation
-0.5: (0, 255, 255, 255), # Cyan for barren land
0: (255, 255, 0, 255), # Yellow for sparse vegetation
0.2: (200, 255, 0, 255), # Light green for low vegetation
0.4: (100, 255, 0, 255), # Green for moderate vegetation
0.6: (0, 255, 0, 255), # Dark green for dense vegetation
1: (0, 128, 0, 255) # Very dark green for very dense vegetation
}
then try to rescale value to 0-255
ndvi_cmap = {
0: (0, 0, 255, 255), # Blue for non-vegetation (e.g., water)
63: (0, 255, 255, 255), # Cyan for barren land or built-up areas
127: (255, 255, 0, 255), # Yellow for sparse vegetation
153: (200, 255, 0, 255), # Light green for low vegetation
178: (100, 255, 0, 255), # Green for moderate vegetation
204: (0, 255, 0, 255), # Dark green for dense vegetation
255: (0, 128, 0, 255) # Very dark green for very dense vegetation
}
and then use colormap like this
expression="(b3-b1)/(b1+b3)"
colormap = cmap
# Register the custom NDVI colormap
colormap = colormap.register({"ndvi_cmap": ndvi_cmap})
Beta Was this translation helpful? Give feedback.
All reactions