File: write_feature_descs.c

package info (click to toggle)
gnuift 0.1.14%2Bds-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,632 kB
  • ctags: 2,973
  • sloc: cpp: 15,867; sh: 8,281; ansic: 1,812; perl: 1,007; php: 651; makefile: 483; lisp: 344
file content (76 lines) | stat: -rw-r--r-- 1,672 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <ppm.h>

//#include "extract_features.proto"

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

	FILE *ppm_file;
	PPM *im_hsv, *im_quant;
	int *colmap, colmap_size;
	enum file_types ppm_type;
	enum ppm_error the_error;
	int numH, numS, numV, numGrey;
 
	switch(argc) {
	case 5:
		numH = atoi(argv[1]);
		numS = atoi(argv[2]);
		numV = atoi(argv[3]);
		numGrey = atoi(argv[4]);
		break;
	case 1:
		numH = 18;
		numS = 3;
		numV = 3;
		numGrey = 4;
		break;
	default:
		fprintf(stderr, "Usage: %s [numH, numS, numV, numGrey] < ppm_file \n\n", argv[0]);
		exit(1);
		break;
	}

	ppm_file = stdin;

	/* read the hsv image from we are going to extract features */
	switch(ppm_type = read_magic_no(ppm_file)) {
	case PGM_ASC: case PPM_ASC: case PGM_RAW: case PPM_RAW:
		if ((the_error = read_ppm(ppm_file, &im_hsv, ppm_type)) != PPM_OK) {
			ppm_handle_error(the_error);
			exit(1);
		}
		break;
	default:
		fprintf(stderr, "Unrecognized file type.\n");
		exit(1);
		break;
	}

	/* quantize the image */
	colmap_size = numH*numS*numV + numGrey;
	if ((the_error = hsv_quantize_ppm(im_hsv, &im_quant, &colmap, numH, numS, numV, numGrey)) != PPM_OK) {
		ppm_handle_error(the_error);
		exit(1);
	}

	/* initialise the variables required for the feature extraction */
	init_feature_variables(colmap_size);

	/* write them to the file */
	if ((the_error = write_feature_descriptions(stdout, colmap, colmap_size)) != PPM_OK) {
		ppm_handle_error(the_error);
		exit(1);
	}
	
	/* everything is OK */
	destroy_ppm(&im_hsv);
	destroy_ppm(&im_quant);
	free(colmap);
	exit(0);
}