hsv_quantize_median_filter.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <ppm.h>
#include "hsv_quantize_median_filter.proto"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 11 of file hsv_quantize_median_filter.c.

References colmap2rgb_ppm(), destroy_ppm(), hsv_quantize_ppm(), median_filter_pgm(), numGrey, numH, numS, numV, PGM_ASC, PGM_RAW, PPM_ASC, ppm_handle_error(), PPM_OK, PPM_RAW, read_magic_no(), read_ppm(), and write_ppm().

00011                                  {
00012   
00013   FILE *ppm_file;
00014   PPM *im_hsv, *im_quant, *im_filtered, *im_output;
00015   int *colmap;
00016   enum file_types ppm_type;
00017   enum ppm_error the_error;
00018   int numH, numS, numV, numGrey;
00019 
00020   switch(argc) {
00021   case 5:
00022     numH = atoi(argv[1]);
00023     numS = atoi(argv[2]);
00024     numV = atoi(argv[3]);
00025     numGrey = atoi(argv[4]);
00026     break;
00027   default:
00028     fprintf(stderr, "Usage: %s numH, numS, numV, numGrey\n\n", argv[0]);
00029     exit(1);
00030     break;
00031   }
00032 
00033   ppm_file = stdin;
00034 
00035   /* read the image we are going to quantize */
00036   switch(ppm_type = read_magic_no(ppm_file)) {
00037   case PGM_ASC: case PPM_ASC: case PGM_RAW: case PPM_RAW:
00038     if ((the_error = read_ppm(ppm_file, &im_hsv, ppm_type)) != PPM_OK) 
00039     {
00040       ppm_handle_error(the_error);
00041       exit(1);
00042     }
00043     break;
00044   default:
00045     fprintf(stderr, "Unrecognized file type.\n");
00046     exit(1);
00047     break;
00048   }
00049 
00050   /* quantize it */
00051   if ((the_error = hsv_quantize_ppm(im_hsv, &im_quant, &colmap, numH, numS, numV, numGrey)) != PPM_OK) {
00052     ppm_handle_error(the_error);
00053     exit(1);
00054   }
00055 
00056   /* median filter the quantized image */
00057   if ((the_error = median_filter_pgm(im_quant, &im_filtered)) != PPM_OK) {
00058     ppm_handle_error(the_error);
00059     exit(1);
00060   }
00061 
00062   /* convert the PGM and colour map to an "RGB" image */
00063   if ((the_error = colmap2rgb_ppm(im_filtered, colmap, numH*numS*numV + numGrey, &im_output)) != PPM_OK) {
00064     ppm_handle_error(the_error);
00065     exit(1);
00066   }
00067 
00068   /* write this "RGB" image to stdout */
00069   if ((the_error = write_ppm(stdout, im_output, PPM_RAW)) != PPM_OK) {
00070     ppm_handle_error(the_error);
00071     exit(1);
00072   }
00073 
00074   destroy_ppm(&im_output);
00075   destroy_ppm(&im_filtered);
00076   destroy_ppm(&im_quant);
00077   destroy_ppm(&im_hsv);
00078   exit(0);
00079 }


Generated on Wed Jan 7 00:30:50 2009 for Gift by  doxygen 1.5.6