30 #define DISPLAY_SCALING 255
33 #define JPEGQUALITY 95
36 #define IMAGEIO_NUM (IMAGEIO_SINGLE)
38 #define IMAGEIO_NUM (IMAGEIO_DOUBLE)
59 "Total variation regularized inpainting IPOL demo, P. Getreuer, 2012\n\n"
60 "Syntax: tvinpaint <D> <lambda> <input> <inpainted>\n");
61 puts(
"where <D>, <input>, and <inpainted> are "
64 " tvinpaint mountains-D.bmp 1e3 mountains-f.bmp inpainted.bmp\n");
69 void ThresholdD(
image D, num Lambda);
73 int main(
int argc,
char **argv)
75 const char *InputFile, *DomainFile, *OutputFile;
76 image f = {NULL, 0, 0, 0}, u = {NULL, 0, 0, 0}, D = {NULL, 0, 0, 0};
88 Lambda = (num)atof(argv[2]);
94 IMAGEIO_RGB | IMAGEIO_PLANAR | IMAGEIO_NUM)) ||
95 !(D.Data = (num *)
ReadImage(&D.Width, &D.Height, DomainFile,
96 IMAGEIO_RGB | IMAGEIO_PLANAR | IMAGEIO_NUM)))
100 fprintf(stderr,
"Size mismatch: D is %dx%d but f is %dx%d\n",
109 if(!(u.Data = (num *)
Malloc(
sizeof(num) * ((
size_t)f.
Width)
112 fprintf(stderr,
"Memory allocation failed.\n");
118 fprintf(stderr,
"Failure!\n");
123 if(!
WriteImage(u.Data, u.Width, u.Height, OutputFile,
124 ((u.NumChannels == 1) ? IMAGEIO_GRAYSCALE : IMAGEIO_RGB)
126 fprintf(stderr,
"Error writing to \"%s\".\n", OutputFile);
154 const long NumPixels = ((long)f.
Width) * ((long)f.
Height);
156 num *Green = D.
Data + NumPixels;
157 num *Blue = D.
Data + 2*NumPixels;
163 fprintf(stderr,
"Memory allocation failed\n");
170 for(n = 0; n < NumPixels; n++)
171 if(0.299*Red[n] + 0.587*Green[n] + 0.114*Blue[n] > 0.5)
177 u.
Data[n + k*NumPixels] = 0.5;
189 fprintf(stderr,
"Error in computation.\n");
203 const long NumPixels = ((long)f.
Width) * ((long)f.
Height);
204 const num *Red = f.
Data;
205 const num *Green = f.
Data + NumPixels;
206 const num *Blue = f.
Data + 2*NumPixels;
209 for(n = 0; n < NumPixels; n++)
210 if(Red[n] != Green[n] || Red[n] != Blue[n])