提交 23b35c70 编写于 作者: S superjom

add image check

上级 23a4be30
......@@ -119,7 +119,11 @@ void Image::SetSample(int index,
for (int i = 0; i < data.size(); i++) {
data_str[i] = data[i];
}
entry.SetRaw(std::string(data_str.begin(), data_str.end()));
Uint8Image image(shape[2], shape[0] * shape[1]);
NormalizeImage(&image, &data[0], shape[0] * shape[1], shape[2]);
// entry.SetRaw(std::string(data_str.begin(), data_str.end()));
entry.SetRaw(
std::string(image.data(), image.data() + image.rows() * image.cols()));
static_assert(
!is_same_type<value_t, shape_t>::value,
......
......@@ -42,7 +42,7 @@ class StorageTest(unittest.TestCase):
for pass_ in xrange(num_passes):
image_writer.start_sampling()
for ins in xrange(num_samples):
index = image_writer.is_sample_taken()
index = image_writer.is_sample_taken()
if index != -1:
data = np.random.random(shape) * 256
data = np.ndarray.flatten(data)
......@@ -89,19 +89,14 @@ class StorageTest(unittest.TestCase):
data = image_record.data()
shape = image_record.shape()
PIL_image_shape = (shape[0]*shape[1], shape[2])
PIL_image_shape = (shape[0] * shape[1], shape[2])
data = np.array(data, dtype='uint8').reshape(PIL_image_shape)
print 'origin', origin_data.flatten()
print 'data', data.flatten()
image = Image.fromarray(data.reshape(shape))
self.assertTrue(np.equal(origin_data.reshape(PIL_image_shape), data).all())
self.assertTrue(
np.equal(origin_data.reshape(PIL_image_shape), data).all())
if __name__ == '__main__':
......
......@@ -13,7 +13,8 @@ using uint8_t = unsigned char;
* 2: height*width, channel
*/
template <typename T>
using ImageDT = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
using ImageDT =
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
using Uint8Image = ImageDT<uint8_t>;
/*
......@@ -21,10 +22,13 @@ using Uint8Image = ImageDT<uint8_t>;
* depth: number of channels
*/
static void NormalizeImage(Uint8Image* image,
float* buffer,
const float* buffer,
int hw,
int depth) {
Eigen::Map<Eigen::MatrixXf> values(buffer, depth, hw);
// Both image and buffer should be used in row major.
Eigen::Map<const Eigen::
Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
values(buffer, depth, hw);
CHECK_EQ(image->size(), hw * depth);
CHECK_EQ(image->row(0).size(), hw);
......@@ -60,11 +64,12 @@ static void NormalizeImage(Uint8Image* image,
float max_val = std::max(std::abs(image_min), image_max);
scale = (max_val < kZeroThreshold ? 0.0f : 127.0f) / max_val;
} else {
scale =
(image_max < image_max < kZeroThreshold ? 0.0f : 255.0f) / image_max;
scale = (image_max < kZeroThreshold ? 0.0f : 255.0f) / image_max;
offset = 0.0f;
}
LOG(INFO) << "scale " << scale;
// Transform image, turning nonfinite values to bad_color
for (int i = 0; i < depth; i++) {
auto tmp = scale * values.row(i).array() + offset;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册