Commit 18695b7b authored by Davis King's avatar Davis King

Made the default input layer automatically normalize unsigned char pixel values

to the range [0,1].
parent 09564840
...@@ -58,6 +58,8 @@ namespace dlib ...@@ -58,6 +58,8 @@ namespace dlib
// initialize data to the right size to contain the stuff in the iterator range. // initialize data to the right size to contain the stuff in the iterator range.
data.set_size(std::distance(ibegin,iend), pixel_traits<T>::num, nr, nc); data.set_size(std::distance(ibegin,iend), pixel_traits<T>::num, nr, nc);
typedef typename pixel_traits<T>::basic_pixel_type bptype;
const size_t offset = nr*nc; const size_t offset = nr*nc;
auto ptr = data.host(); auto ptr = data.host();
for (auto i = ibegin; i != iend; ++i) for (auto i = ibegin; i != iend; ++i)
...@@ -70,7 +72,10 @@ namespace dlib ...@@ -70,7 +72,10 @@ namespace dlib
auto p = ptr++; auto p = ptr++;
for (long j = 0; j < temp.size(); ++j) for (long j = 0; j < temp.size(); ++j)
{ {
*p = temp(j); if (is_same_type<bptype,unsigned char>::value)
*p = temp(j)/256.0;
else
*p = temp(j);
p += offset; p += offset;
} }
} }
...@@ -130,6 +135,7 @@ namespace dlib ...@@ -130,6 +135,7 @@ namespace dlib
// initialize data to the right size to contain the stuff in the iterator range. // initialize data to the right size to contain the stuff in the iterator range.
data.set_size(std::distance(ibegin,iend), pixel_traits<T>::num, nr, nc); data.set_size(std::distance(ibegin,iend), pixel_traits<T>::num, nr, nc);
typedef typename pixel_traits<T>::basic_pixel_type bptype;
const size_t offset = nr*nc; const size_t offset = nr*nc;
auto ptr = data.host(); auto ptr = data.host();
...@@ -143,7 +149,10 @@ namespace dlib ...@@ -143,7 +149,10 @@ namespace dlib
auto p = ptr++; auto p = ptr++;
for (long j = 0; j < temp.size(); ++j) for (long j = 0; j < temp.size(); ++j)
{ {
*p = temp(j); if (is_same_type<bptype,unsigned char>::value)
*p = temp(j)/256.0;
else
*p = temp(j);
p += offset; p += offset;
} }
} }
......
...@@ -135,6 +135,10 @@ namespace dlib ...@@ -135,6 +135,10 @@ namespace dlib
For example, a matrix<float,3,3> would turn into a tensor with 3 rows, 3 For example, a matrix<float,3,3> would turn into a tensor with 3 rows, 3
columns, and k()==1. Or a matrix<rgb_pixel,4,5> would turn into a tensor columns, and k()==1. Or a matrix<rgb_pixel,4,5> would turn into a tensor
with 4 rows, 5 columns, and k()==3 (since rgb_pixels have 3 channels). with 4 rows, 5 columns, and k()==3 (since rgb_pixels have 3 channels).
- If the input data contains pixels of type unsigned char, rgb_pixel, or
other pixel types with a basic_pixel_type of unsigned char then each
value written to the output tensor is first divided by 256.0 so that the
resulting outputs are all in the range [0,1].
!*/ !*/
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment