algorithmmatlabimage-processingcolor-mappingindexed-image

What Algorithm(s) do(es) rgb2ind() in MATLAB use?


I am reading the documentation of the RGB2IND function, and found that it uses Uniform Quantization, Minimum Variance Quantization, and Inverse Colormap, though I don't quite get how these fit into the algorithm given the parameters.

Are there any code examples in any interpreted language (MATLAB, JavaScript, Python) that demonstrate exactly how this function works in this syntax?

[X,map] = rgb2ind(RGB,n);

Solution

  • As the documentation page says, it depends on which form of the function you use:

    You could always read the source code yourself (edit rgb2ind)


    Here are examples showing how to use all forms of the functions:

    %% some truecolor image
    RGB = imread('pears.png');
    imshow(RGB)
    
    %% 16 colors
    [X,map] = rgb2ind(RGB, 16);
    imshow(X,map)
    
    %% 0.15 tolerance, no dithering
    [X,map] = rgb2ind(RGB, 0.15, 'nodither');
    imshow(X,map)
    
    %% use a pinkish colormap with 32 colors
    map = pink(32);
    X = rgb2ind(RGB, map);
    imshow(X,map)