Skip to content

Commit 9ed2f35

Browse files
author
Kaspar Schmid
committed
fixed relative path loading, gamma correction. added a new example project.
1 parent 8d268c9 commit 9ed2f35

File tree

4 files changed

+211
-23
lines changed

4 files changed

+211
-23
lines changed

IPL/include/IPLFileIO.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class IPLSHARED_EXPORT IPLFileIO
4949

5050
static void setBasedir(std::string dir) { _baseDir = dir; }
5151

52+
// Naive approach:
53+
// win: C:\... D://...
54+
// unix: /var/...
55+
static bool isAbsolutePath(std::string filename) { return (filename.substr(0, 1) == "/" || filename.substr(1, 1) == ":"); }
56+
5257
static std::string _baseDir;
5358
};
5459

IPL/src/IPLFileIO.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ bool IPLFileIO::loadFile(std::string filename, IPLImage*& image, std::string& in
4545
"COMPLEX", "RGB16", "RGBA16", "RGBF",
4646
"RGBAF"};
4747

48+
49+
std::string filePath;
50+
4851
// try loading relative filepaths to the _baseDir
49-
if( (filename.find("/") == std::string::npos) && (filename.find("\\") == std::string::npos))
52+
if(!IPLFileIO::isAbsolutePath(filename))
5053
{
51-
filename = IPLFileIO::_baseDir.append("/").append(filename);
54+
filePath.append(IPLFileIO::_baseDir).append("/").append(filename);
5255
}
5356

5457
FREE_IMAGE_FORMAT format = FIF_UNKNOWN;
55-
format = FreeImage_GetFileType(filename.c_str());
58+
format = FreeImage_GetFileType(filePath.c_str());
5659
if(format == FIF_UNKNOWN)
5760
{
5861
return false;
5962
}
6063

61-
FIBITMAP *dib = FreeImage_Load(format, filename.c_str());
64+
FIBITMAP *dib = FreeImage_Load(format, filePath.c_str());
6265
int width = FreeImage_GetWidth(dib);
6366
int height = FreeImage_GetHeight(dib);
6467

@@ -306,7 +309,7 @@ bool IPLFileIO::readRaw8bit(int stride, IPLImage *&image, std::ifstream &file)
306309
{
307310
file.read(&buffer, 1);
308311

309-
ipl_basetype value = buffer * FACTOR_TO_FLOAT;
312+
ipl_basetype value = ((uchar) buffer) * FACTOR_TO_FLOAT;
310313
image->plane(0)->cp(x, y) = value;
311314

312315
x++;
@@ -331,15 +334,15 @@ bool IPLFileIO::readRaw24BitInterleaved(int stride, IPLRawImageType format, IPLI
331334
ipl_basetype r,g,b;
332335
if(format == 1)
333336
{
334-
r = buffer[0] * FACTOR_TO_FLOAT;
335-
g = buffer[1] * FACTOR_TO_FLOAT;
336-
b = buffer[2] * FACTOR_TO_FLOAT;
337+
r = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
338+
g = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
339+
b = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
337340
}
338341
else
339342
{
340-
b = buffer[0] * FACTOR_TO_FLOAT;
341-
g = buffer[1] * FACTOR_TO_FLOAT;
342-
r = buffer[2] * FACTOR_TO_FLOAT;
343+
b = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
344+
g = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
345+
r = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
343346
}
344347

345348
image->plane(0)->cp(x, y) = r;
@@ -368,17 +371,17 @@ bool IPLFileIO::readRaw32BitInterleaved(int stride, IPLRawImageType format, IPLI
368371
ipl_basetype r,g,b,a;
369372
if(format == 1)
370373
{
371-
r = buffer[0] * FACTOR_TO_FLOAT;
372-
g = buffer[1] * FACTOR_TO_FLOAT;
373-
b = buffer[2] * FACTOR_TO_FLOAT;
374-
a = buffer[3] * FACTOR_TO_FLOAT;
374+
r = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
375+
g = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
376+
b = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
377+
a = ((uchar) buffer[3]) * FACTOR_TO_FLOAT;
375378
}
376379
else
377380
{
378-
a = buffer[0] * FACTOR_TO_FLOAT;
379-
b = buffer[1] * FACTOR_TO_FLOAT;
380-
g = buffer[2] * FACTOR_TO_FLOAT;
381-
r = buffer[3] * FACTOR_TO_FLOAT;
381+
a = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
382+
b = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
383+
g = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
384+
r = ((uchar) buffer[3]) * FACTOR_TO_FLOAT;
382385
}
383386

384387
image->plane(0)->cp(x, y) = r;
@@ -506,13 +509,15 @@ bool IPLFileIO::readRaw32BitPlanar(int stride, IPLRawImageType format, IPLImage
506509
*/
507510
bool IPLFileIO::loadRawFile(std::string filename, IPLImage *&image, int width, int height, IPLRawImageType format, bool interleaved, std::string &information)
508511
{
512+
std::string filePath;
513+
509514
// try loading relative filepaths to the _baseDir
510-
if( filename.find("/") == std::string::npos && filename.find("\\") == std::string::npos)
515+
if(!IPLFileIO::isAbsolutePath(filename))
511516
{
512-
filename = IPLFileIO::_baseDir.append("/").append(filename);
517+
filePath.append(IPLFileIO::_baseDir).append("/").append(filename);
513518
}
514519

515-
std::ifstream file(filename, std::ios::binary);
520+
std::ifstream file(filePath, std::ios::binary);
516521

517522
if(!file.is_open())
518523
{

IPL/src/processes/IPLGammaCorrection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void IPLGammaCorrection::init()
3232

3333
// inputs and outputs
3434
addInput("Image", IPL_IMAGE_COLOR);
35-
addOutput("Gray Image", IPL_IMAGE_BW);
35+
addOutput("Image", IPL_IMAGE_COLOR);
3636

3737
// properties
3838
addProcessPropertyDouble("gamma", "Gamma", "0.0 < threshold < 1.0", _gamma, IPL_WIDGET_SLIDER, 0.1, 10.0);
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
{
2+
"author": "Kaspar",
3+
"edges": [
4+
{
5+
"from": 2,
6+
"indexFrom": 0,
7+
"indexTo": 0,
8+
"to": 3
9+
},
10+
{
11+
"from": 1,
12+
"indexFrom": 0,
13+
"indexTo": 0,
14+
"to": 5
15+
},
16+
{
17+
"from": 5,
18+
"indexFrom": 0,
19+
"indexTo": 0,
20+
"to": 4
21+
}
22+
],
23+
"steps": [
24+
{
25+
"ID": 1,
26+
"posX": 64,
27+
"posY": 64,
28+
"properties": [
29+
{
30+
"key": "mode",
31+
"type": "int",
32+
"value": "1",
33+
"widget": "24",
34+
"widgetName": "IPL_WIDGET_GROUP"
35+
},
36+
{
37+
"key": "path",
38+
"type": "string",
39+
"value": "images/lena_8bit.raw",
40+
"widget": "12",
41+
"widgetName": "IPL_WIDGET_FILE_OPEN"
42+
},
43+
{
44+
"key": "raw_format",
45+
"type": "int",
46+
"value": "0",
47+
"widget": "4",
48+
"widgetName": "IPL_WIDGET_COMBOBOX"
49+
},
50+
{
51+
"key": "raw_height",
52+
"type": "int",
53+
"value": "512",
54+
"widget": "5",
55+
"widgetName": "IPL_WIDGET_SLIDER"
56+
},
57+
{
58+
"key": "raw_interleaved",
59+
"type": "int",
60+
"value": "0",
61+
"widget": "4",
62+
"widgetName": "IPL_WIDGET_COMBOBOX"
63+
},
64+
{
65+
"key": "raw_width",
66+
"type": "int",
67+
"value": "512",
68+
"widget": "5",
69+
"widgetName": "IPL_WIDGET_SLIDER"
70+
}
71+
],
72+
"type": "IPLLoadImage"
73+
},
74+
{
75+
"ID": 2,
76+
"posX": 64,
77+
"posY": 192,
78+
"properties": [
79+
{
80+
"key": "mode",
81+
"type": "int",
82+
"value": "1",
83+
"widget": "24",
84+
"widgetName": "IPL_WIDGET_GROUP"
85+
},
86+
{
87+
"key": "path",
88+
"type": "string",
89+
"value": "images/lena.raw",
90+
"widget": "12",
91+
"widgetName": "IPL_WIDGET_FILE_OPEN"
92+
},
93+
{
94+
"key": "raw_format",
95+
"type": "int",
96+
"value": "1",
97+
"widget": "4",
98+
"widgetName": "IPL_WIDGET_COMBOBOX"
99+
},
100+
{
101+
"key": "raw_height",
102+
"type": "int",
103+
"value": "512",
104+
"widget": "5",
105+
"widgetName": "IPL_WIDGET_SLIDER"
106+
},
107+
{
108+
"key": "raw_interleaved",
109+
"type": "int",
110+
"value": "0",
111+
"widget": "4",
112+
"widgetName": "IPL_WIDGET_COMBOBOX"
113+
},
114+
{
115+
"key": "raw_width",
116+
"type": "int",
117+
"value": "512",
118+
"widget": "5",
119+
"widgetName": "IPL_WIDGET_SLIDER"
120+
}
121+
],
122+
"type": "IPLLoadImage"
123+
},
124+
{
125+
"ID": 3,
126+
"posX": 192,
127+
"posY": 192,
128+
"properties": [
129+
{
130+
"key": "gamma",
131+
"type": "double",
132+
"value": "2.34",
133+
"widget": "5",
134+
"widgetName": "IPL_WIDGET_SLIDER"
135+
}
136+
],
137+
"type": "IPLGammaCorrection"
138+
},
139+
{
140+
"ID": 4,
141+
"posX": 192,
142+
"posY": 64,
143+
"properties": [
144+
],
145+
"type": "IPLFalseColor"
146+
},
147+
{
148+
"ID": 5,
149+
"posX": 128,
150+
"posY": 64,
151+
"properties": [
152+
{
153+
"key": "weight_b",
154+
"type": "double",
155+
"value": "0.0721",
156+
"widget": "5",
157+
"widgetName": "IPL_WIDGET_SLIDER"
158+
},
159+
{
160+
"key": "weight_g",
161+
"type": "double",
162+
"value": "0.7154",
163+
"widget": "5",
164+
"widgetName": "IPL_WIDGET_SLIDER"
165+
},
166+
{
167+
"key": "weight_r",
168+
"type": "double",
169+
"value": "0.2125",
170+
"widget": "5",
171+
"widgetName": "IPL_WIDGET_SLIDER"
172+
}
173+
],
174+
"type": "IPLConvertToGray"
175+
}
176+
],
177+
"timestamp": 1446732112
178+
}

0 commit comments

Comments
 (0)