NAME

     pct_median_segment -  a  segmentation  algorithm  for  color
     images based on PCT and median_cut

SYNOPSIS

      #include "CVIPtoolkit.h"
      #include "CVIPdef.h"
      #include "CVIPsegment.h"

     Image  *pct_median_segment(Image *imgP, unsigned colors)

      <impP> - pointer to Image structure
      <colors> - desired number of colors

PATH

     $CVIPHOME/SEGMENTATION/pct_median.c

DESCRIPTION

     This function is based on the Principal Components Transform
     (PCT)  and  median_cut  algorithms.  The PCT aligns the main
     axis along the maximum variance path in  the  data  set,  so
     that  most  of  the color information lies along a principal
     axis.  Following that, the median split part  of  the  algo-
     rithm  divides  the image into the desired number of colors.
     Finally, the inverse PCT will transform the resulting  image
     back to the RGB color space.

     This algorithm applies to color image only. However, it  can
     also  be used on grayscale images through the extract_band()
     and assemble_bands() functions.

TYPES AND CONSTANTS


RETURN VALUES

     An Image pointer upon success; a NULL pointer upon failure

EXAMPLE

      #include "CVIPtoolkit.h"
      #include "CVIPdef.h"
      #include "CVIPsegment.h"

      void main()
      {
        Image  *cvipImage;
        IMAGE_FORMAT   format;
        char  *inputfile, *outputfile;
        unsigned newcolors;

        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("\nEnter the number of desired colors:");
        newcolors = getUInt_CVIP(10, 2, 1000);
        cvipImage = pct_median_segment(cvipImage, newcolors);
        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

     NONE

SEE ALSO

     libsegment, median_cut_segment, pct

AUTHOR

     Copyright (C) 1996 SIUE - by Scott Umbaugh and Yansheng Wei.