## NAME

         median_cut_segment  -  function  to  map   24-bits-per-pixel
         images to 2-bits-per-pixel

## SYNOPSIS

          #include "CVIPtoolkit.h"
          #include "CVIPdef.h"
          #include "median_cut.h"

         Image   *median_cut_segment(Image  *imgP,   int   newcolors,
         CVIP_BOOLEAN is_bg, Color bg)

          <impP> - pointer to Image structure
          <newcolors> - desired number of colors
          <is_bg> - is background color?
          <bg> - background color

## PATH

         $CVIPHOME/SEGMENTATION/median_cut.c

## DESCRIPTION

         This function is usually used in conjunction with the  Prin-
         cipal Components Transform (PCT) in segmenting color images.
         It performs data compression from 24  bits-per-pixel  to  an
         average  of  2 bits-per-pixel. Median cut attempts to make a
         histogram of the  original  image  without  clustering.  New
         colormaps  are generated iteratively until at most 15 colors
         have been chosen.  When is_bg is  CVIP_YES,  the  background
         color  specified in "bg" is not considered in the median_cut
         process.

## TYPES AND CONSTANTS

## RETURN VALUES

         An Image pointer upon success; a NULL pointer upon failure

## EXAMPLE

          #include "CVIPtoolkit.h"
          #include "CVIPconvert.h"
          #include "CVIPcolor.h"
          #include "CVIPdef.h"
          #include "median_cut.h"

          void main()
          {
          Image  *cvipImage;
          IMAGE_FORMAT   format;
          char  *inputfile, *outputfile;
          unsigned newcolors;
          Color bg = {0, 0, 0};

          setDisplay_Image("picture", "Default");

          print_CVIP("\n\t\tEnter the Input File Name:  ");
          inputfile =(char *) getString_CVIP();
          format = getFormat_CVIP(inputfile);
          cvipImage = read_Image(inputfile, 1);
          view_Image(cvipImage, inputfile);
          print_CVIP("0lease enter the number of desired colors: ");
          newcolors = getUInt_CVIP(10, 2, 1000);
          cvipImage   =   median_cut_segment(cvipImage,    newcolors,
         CVIP_NO, bg);
          print_CVIP("\n\t\tEnter the Output File Name:  ");
          outputfile = getString_CVIP();
          view_Image(cvipImage, outputfile);
          write_Image(cvipImage,outputfile,CVIP_NO,CVIP_NO,format,1);
          free(inputfile);
          free(outputfile);
          }

## BUGS

         Sometimes the function does't  work  properly  when  the  bg
         color is specified.

## SEE ALSO

         libsegment

## AUTHOR

         Copyright (C) 1995 SIUE - by Scott Umbaugh and Greg Hance.