Skip to content

Commit

Permalink
fixed relative path loading, gamma correction. added a new example pr…
Browse files Browse the repository at this point in the history
…oject.
  • Loading branch information
Kaspar Schmid committed Nov 5, 2015
1 parent 8d268c9 commit 9ed2f35
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 23 deletions.
5 changes: 5 additions & 0 deletions IPL/include/IPLFileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class IPLSHARED_EXPORT IPLFileIO

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

// Naive approach:
// win: C:\... D://...
// unix: /var/...
static bool isAbsolutePath(std::string filename) { return (filename.substr(0, 1) == "/" || filename.substr(1, 1) == ":"); }

static std::string _baseDir;
};

Expand Down
49 changes: 27 additions & 22 deletions IPL/src/IPLFileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,23 @@ bool IPLFileIO::loadFile(std::string filename, IPLImage*& image, std::string& in
"COMPLEX", "RGB16", "RGBA16", "RGBF",
"RGBAF"};


std::string filePath;

// try loading relative filepaths to the _baseDir
if( (filename.find("/") == std::string::npos) && (filename.find("\\") == std::string::npos))
if(!IPLFileIO::isAbsolutePath(filename))
{
filename = IPLFileIO::_baseDir.append("/").append(filename);
filePath.append(IPLFileIO::_baseDir).append("/").append(filename);
}

FREE_IMAGE_FORMAT format = FIF_UNKNOWN;
format = FreeImage_GetFileType(filename.c_str());
format = FreeImage_GetFileType(filePath.c_str());
if(format == FIF_UNKNOWN)
{
return false;
}

FIBITMAP *dib = FreeImage_Load(format, filename.c_str());
FIBITMAP *dib = FreeImage_Load(format, filePath.c_str());
int width = FreeImage_GetWidth(dib);
int height = FreeImage_GetHeight(dib);

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

ipl_basetype value = buffer * FACTOR_TO_FLOAT;
ipl_basetype value = ((uchar) buffer) * FACTOR_TO_FLOAT;
image->plane(0)->cp(x, y) = value;

x++;
Expand All @@ -331,15 +334,15 @@ bool IPLFileIO::readRaw24BitInterleaved(int stride, IPLRawImageType format, IPLI
ipl_basetype r,g,b;
if(format == 1)
{
r = buffer[0] * FACTOR_TO_FLOAT;
g = buffer[1] * FACTOR_TO_FLOAT;
b = buffer[2] * FACTOR_TO_FLOAT;
r = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
g = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
b = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
}
else
{
b = buffer[0] * FACTOR_TO_FLOAT;
g = buffer[1] * FACTOR_TO_FLOAT;
r = buffer[2] * FACTOR_TO_FLOAT;
b = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
g = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
r = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
}

image->plane(0)->cp(x, y) = r;
Expand Down Expand Up @@ -368,17 +371,17 @@ bool IPLFileIO::readRaw32BitInterleaved(int stride, IPLRawImageType format, IPLI
ipl_basetype r,g,b,a;
if(format == 1)
{
r = buffer[0] * FACTOR_TO_FLOAT;
g = buffer[1] * FACTOR_TO_FLOAT;
b = buffer[2] * FACTOR_TO_FLOAT;
a = buffer[3] * FACTOR_TO_FLOAT;
r = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
g = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
b = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
a = ((uchar) buffer[3]) * FACTOR_TO_FLOAT;
}
else
{
a = buffer[0] * FACTOR_TO_FLOAT;
b = buffer[1] * FACTOR_TO_FLOAT;
g = buffer[2] * FACTOR_TO_FLOAT;
r = buffer[3] * FACTOR_TO_FLOAT;
a = ((uchar) buffer[0]) * FACTOR_TO_FLOAT;
b = ((uchar) buffer[1]) * FACTOR_TO_FLOAT;
g = ((uchar) buffer[2]) * FACTOR_TO_FLOAT;
r = ((uchar) buffer[3]) * FACTOR_TO_FLOAT;
}

image->plane(0)->cp(x, y) = r;
Expand Down Expand Up @@ -506,13 +509,15 @@ bool IPLFileIO::readRaw32BitPlanar(int stride, IPLRawImageType format, IPLImage
*/
bool IPLFileIO::loadRawFile(std::string filename, IPLImage *&image, int width, int height, IPLRawImageType format, bool interleaved, std::string &information)
{
std::string filePath;

// try loading relative filepaths to the _baseDir
if( filename.find("/") == std::string::npos && filename.find("\\") == std::string::npos)
if(!IPLFileIO::isAbsolutePath(filename))
{
filename = IPLFileIO::_baseDir.append("/").append(filename);
filePath.append(IPLFileIO::_baseDir).append("/").append(filename);
}

std::ifstream file(filename, std::ios::binary);
std::ifstream file(filePath, std::ios::binary);

if(!file.is_open())
{
Expand Down
2 changes: 1 addition & 1 deletion IPL/src/processes/IPLGammaCorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void IPLGammaCorrection::init()

// inputs and outputs
addInput("Image", IPL_IMAGE_COLOR);
addOutput("Gray Image", IPL_IMAGE_BW);
addOutput("Image", IPL_IMAGE_COLOR);

// properties
addProcessPropertyDouble("gamma", "Gamma", "0.0 < threshold < 1.0", _gamma, IPL_WIDGET_SLIDER, 0.1, 10.0);
Expand Down
178 changes: 178 additions & 0 deletions ImagePlay/media/examples/raw_files.ipj
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"author": "Kaspar",
"edges": [
{
"from": 2,
"indexFrom": 0,
"indexTo": 0,
"to": 3
},
{
"from": 1,
"indexFrom": 0,
"indexTo": 0,
"to": 5
},
{
"from": 5,
"indexFrom": 0,
"indexTo": 0,
"to": 4
}
],
"steps": [
{
"ID": 1,
"posX": 64,
"posY": 64,
"properties": [
{
"key": "mode",
"type": "int",
"value": "1",
"widget": "24",
"widgetName": "IPL_WIDGET_GROUP"
},
{
"key": "path",
"type": "string",
"value": "images/lena_8bit.raw",
"widget": "12",
"widgetName": "IPL_WIDGET_FILE_OPEN"
},
{
"key": "raw_format",
"type": "int",
"value": "0",
"widget": "4",
"widgetName": "IPL_WIDGET_COMBOBOX"
},
{
"key": "raw_height",
"type": "int",
"value": "512",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
},
{
"key": "raw_interleaved",
"type": "int",
"value": "0",
"widget": "4",
"widgetName": "IPL_WIDGET_COMBOBOX"
},
{
"key": "raw_width",
"type": "int",
"value": "512",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
}
],
"type": "IPLLoadImage"
},
{
"ID": 2,
"posX": 64,
"posY": 192,
"properties": [
{
"key": "mode",
"type": "int",
"value": "1",
"widget": "24",
"widgetName": "IPL_WIDGET_GROUP"
},
{
"key": "path",
"type": "string",
"value": "images/lena.raw",
"widget": "12",
"widgetName": "IPL_WIDGET_FILE_OPEN"
},
{
"key": "raw_format",
"type": "int",
"value": "1",
"widget": "4",
"widgetName": "IPL_WIDGET_COMBOBOX"
},
{
"key": "raw_height",
"type": "int",
"value": "512",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
},
{
"key": "raw_interleaved",
"type": "int",
"value": "0",
"widget": "4",
"widgetName": "IPL_WIDGET_COMBOBOX"
},
{
"key": "raw_width",
"type": "int",
"value": "512",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
}
],
"type": "IPLLoadImage"
},
{
"ID": 3,
"posX": 192,
"posY": 192,
"properties": [
{
"key": "gamma",
"type": "double",
"value": "2.34",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
}
],
"type": "IPLGammaCorrection"
},
{
"ID": 4,
"posX": 192,
"posY": 64,
"properties": [
],
"type": "IPLFalseColor"
},
{
"ID": 5,
"posX": 128,
"posY": 64,
"properties": [
{
"key": "weight_b",
"type": "double",
"value": "0.0721",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
},
{
"key": "weight_g",
"type": "double",
"value": "0.7154",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
},
{
"key": "weight_r",
"type": "double",
"value": "0.2125",
"widget": "5",
"widgetName": "IPL_WIDGET_SLIDER"
}
],
"type": "IPLConvertToGray"
}
],
"timestamp": 1446732112
}

0 comments on commit 9ed2f35

Please sign in to comment.