Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <string.h>
00039
00040 #include "retinex_pde_lib.h"
00041 #include "io_png.h"
00042 #include "norm.h"
00043
00047 int main(int argc, char *const *argv)
00048 {
00049 float t;
00050 size_t nx, ny, nc;
00051 size_t channel, nc_non_alpha;
00052 float *data, *data_rtnx;
00053
00054
00055 if (2 <= argc && 0 == strcmp("-v", argv[1])) {
00056 fprintf(stdout, "%s version " __DATE__ "\n", argv[0]);
00057 return EXIT_SUCCESS;
00058 }
00059
00060 if (4 != argc) {
00061 fprintf(stderr, "usage : %s T in.png rtnx.png\n", argv[0]);
00062 fprintf(stderr, " T retinex threshold [0...255]\n");
00063 return EXIT_FAILURE;
00064 }
00065
00066
00067 t = atof(argv[1]);
00068 if (0. > t || 255. < t) {
00069 fprintf(stderr, "the retinex threshold must be in [0..255]\n");
00070 return EXIT_FAILURE;
00071 }
00072
00073
00074 if (NULL == (data = read_png_f32(argv[2], &nx, &ny, &nc))) {
00075 fprintf(stderr, "the image could not be properly read\n");
00076 return EXIT_FAILURE;
00077 }
00078
00079
00080 if (NULL == (data_rtnx = (float *) malloc(nc * nx * ny * sizeof(float)))) {
00081 fprintf(stderr, "allocation error\n");
00082 free(data);
00083 return EXIT_FAILURE;
00084 }
00085 memcpy(data_rtnx, data, nc * nx * ny * sizeof(float));
00086
00087
00088 if (3 <= nc)
00089 nc_non_alpha = 3;
00090 else
00091 nc_non_alpha = 1;
00092
00093
00094
00095
00096
00097 for (channel = 0; channel < nc_non_alpha; channel++) {
00098 if (NULL == retinex_pde(data_rtnx + channel * nx * ny, nx, ny, t)) {
00099 fprintf(stderr, "the retinex PDE failed\n");
00100 free(data_rtnx);
00101 free(data);
00102 return EXIT_FAILURE;
00103 }
00104 normalize_mean_dt(data_rtnx + channel * nx * ny,
00105 data + channel * nx * ny, nx * ny);
00106 }
00107 write_png_f32(argv[3], data_rtnx, nx, ny, nc);
00108 free(data_rtnx);
00109 free(data);
00110
00111 return EXIT_SUCCESS;
00112 }