Correct rendering of cat images.

This commit is contained in:
2017-10-13 13:52:31 +02:00
parent 172949eda8
commit 5df5c1c13c
2 changed files with 12 additions and 11 deletions

View File

@@ -47,17 +47,18 @@ void PNGDumper::dump(const LayerData &layerData)
void PNGDumper::dumpImageSeries(const LayerData &layer)
{
const auto& shape = layer.shape();
const auto imagePixels = shape[2] * shape[3];
const auto images = shape[0], channels = shape[1], height = shape[2], width = shape[3];
const auto imagePixels = width * height;
// Buffer for storing the current image data.
vector<DType> buffer(imagePixels);
auto data = layer.data();
png::image<png::gray_pixel> image(shape[2], shape[3]);
png::image<png::gray_pixel> image(width, height);
for (int i = 0; i < shape[0]; ++i) {
for (int j = 0; j < shape[1]; ++j) {
for (int i = 0; i < images; ++i) {
for (int j = 0; j < channels; ++j) {
memcpy(buffer.data(), data, imagePixels * sizeof(DType));
// advance the buffer;
@@ -65,9 +66,9 @@ void PNGDumper::dumpImageSeries(const LayerData &layer)
clamp(buffer.begin(), buffer.end(), 0.0, 255.0);
for (int y = 0; y < shape[2]; ++y) {
for (int x = 0; x < shape[3]; ++x) {
image[x][y] = png::gray_pixel((int) buffer[x + y * shape[3]]);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
image[y][x] = png::gray_pixel((int) buffer[x + y * width]);
}
}

View File

@@ -91,11 +91,11 @@ namespace fmri
typename std::iterator_traits<It>::value_type minimum,
typename std::iterator_traits<It>::value_type maximum)
{
const auto extremes = std::minmax(begin, end);
const auto diff = *extremes.second - *extremes.first;
const auto[minElem, maxElem] = std::minmax(begin, end);
const auto diff = *maxElem - *minElem;
const auto offset = minimum - *extremes.first;
const auto scaling = diff / (maximum - minimum);
const auto offset = minimum - *minElem;
const auto scaling = (maximum - minimum) / diff;
std::for_each(begin, end, [offset, scaling] (typename std::iterator_traits<It>::reference v) { v = (v + offset) * scaling;});
}