Chan-Vese Segmentation
Functions
rgb2ind.h File Reference

Convert a truecolor RGB image to an indexed image. More...

Go to the source code of this file.

Functions

int Rgb2Ind (unsigned char *Dest, unsigned char *Palette, int NumColors, const unsigned char *RgbImage, long NumPixels)
 Convert a truecolor RGB image to an indexed image. More...
 

Detailed Description

Convert a truecolor RGB image to an indexed image.

Author
Pascal Getreuer getre.nosp@m.uer@.nosp@m.gmail.nosp@m..com

Copyright (c) 2011, Pascal Getreuer All rights reserved.

This program is free software: you can redistribute it and/or modify it under, at your option, the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version, or the terms of the simplified BSD license.

You should have received a copy of these licenses along with this program. If not, see http://www.gnu.org/licenses/ and http://www.opensource.org/licenses/bsd-license.html.

Definition in file rgb2ind.h.

Function Documentation

int Rgb2Ind ( unsigned char *  Dest,
unsigned char *  Palette,
int  NumColors,
const unsigned char *  RgbImage,
long  NumPixels 
)

Convert a truecolor RGB image to an indexed image.

Parameters
Destwhere to store the indexed image
Palettewhere to store the palette
NumColorsmaximum number of colors to use
RgbImagethe input RGB image
NumPixelsnumber of pixels in RgbImage
Returns
1 on success, 0 on failure

This routine quantizes the colors of the input RgbImage to an indexed image Dest using at most NumColors distinct colors. RgbImage should be a contiguous array of RGB triples,

ImageRgb[3*i + 0] = Red component of the ith pixel,
ImageRgb[3*i + 1] = Green component of the ith pixel,
ImageRgb[3*i + 2] = Blue component of the ith pixel.

Dest should be an array with space for at least NumPixels elements, and Palette should have space for at least 3*NumColors elements. Dest and Palette are filled such that the quantized image is

Palette[3*Dest[i] + 0] = Red component of the ith pixel,
Palette[3*Dest[i] + 1] = Green component of the ith pixel,
Palette[3*Dest[i] + 2] = Blue component of the ith pixel.

The quantized image should approximate RgbImage.

The quantization is performed using the median cut algorithm. No dithering is performed.

Definition at line 70 of file rgb2ind.c.