https://fr.mathworks.com/help/matlab/ref/imapprox.html
imapprox - Approximate indexed image by reducing number of colors - MATLAB
This MATLAB function approximates the colors in indexed image X and associated colormap map by using minimum variance quantization with Q quantized colors.
approximateindexedimagereducingnumber