00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042 #include <string.h>
00043
00044
00045 #include "libcartoon.h"
00046 #include "io_png.h"
00047
00048
00049
00050 int main(int argc, char **argv)
00051 {
00052
00053
00054 if (argc < 5)
00055 {
00056 printf("usage: cartoonIpol image sigma cartoon texture \n");
00057 return EXIT_FAILURE;
00058 }
00059
00060
00061
00062
00063
00064 size_t nx,ny,nc;
00065 float *d_v = NULL;
00066 d_v = io_png_read_f32(argv[1], &nx, &ny, &nc);
00067 if (!d_v)
00068 {
00069 printf("error :: %s not found or not a correct png image \n",
00070 argv[1]);
00071 return EXIT_FAILURE;
00072 }
00073
00074
00075
00076
00077
00078 int d_w = (int) nx;
00079 int d_h = (int) ny;
00080 int d_c = (int) nc;
00081 if (d_c == 2) { d_c = 1; }
00082 if (d_c > 3) { d_c = 3; }
00083
00084 int d_wh = d_w * d_h;
00085 int d_whc = d_c * d_w * d_h;
00086
00087
00088
00089
00090
00091 float fSigma = atof(argv[2]);
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 float *cartoon_v = new float[d_c * d_wh];
00103
00104 if (d_c == 1)
00105 {
00106 non_linear_cartoon(d_v, cartoon_v, fSigma, d_w, d_h);
00107
00108 } else if (d_c == 3)
00109 {
00110 non_linear_cartoon(d_v, &d_v[d_wh], &d_v[2*d_wh],
00111 cartoon_v, &cartoon_v[d_wh], &cartoon_v[2*d_wh],
00112 fSigma, d_w, d_h);
00113
00114 }
00115
00116
00117
00118
00119 float vLim = 20;
00120 float *dif_v = new float[d_c * d_wh];
00121 for (int ii=0; ii < d_whc; ii++)
00122 {
00123
00124 float fValue = d_v[ii] - cartoon_v[ii];
00125 fValue = (fValue + vLim) * 255.0f / (2.0f * vLim);
00126
00127 if (fValue < 0.0) fValue = 0.0f;
00128 if (fValue > 255.0) fValue = 255.0f;
00129
00130
00131 dif_v[ii] = fValue;
00132 }
00133
00134
00135
00136
00137 if (io_png_write_f32(argv[3], cartoon_v, (size_t) d_w, (size_t) d_h,
00138 (size_t) d_c) != 0)
00139 {
00140 printf("... failed to save png image %s", argv[3]);
00141 }
00142
00143 if (io_png_write_f32(argv[4], dif_v, (size_t) d_w, (size_t) d_h,
00144 (size_t) d_c) != 0)
00145 {
00146 printf("... failed to save png image %s", argv[4]);
00147 }
00148
00149
00150 delete[] cartoon_v;
00151 delete[] dif_v;
00152
00153 return EXIT_SUCCESS;
00154
00155 }