This code demonstrates how to create an image view in memory and write data into it to create a checkerboard pattern.
This code demonstrates how to create an image view in memory and write data into it to create a checkerboard pattern.The code creates a 2D image of given size and fills it pixel by pixel.
#include <chrono>
#include <iostream>
#include <vector>
#include <iolink/view/ImageViewFactory.h>
std::shared_ptr<ImageView>
checkerBoard(const size_t sideLength)
{
auto image = ImageViewFactory::allocate(shape, dt);
const size_t tileCount = 10;
uint8_t blackValue = 0;
uint8_t whiteValue = 255;
size_t tileSizeInPixel = static_cast<size_t>(shape[0] / tileCount);
for (size_t i = 0; i < shape[0]; ++i)
{
for (size_t j = 0; j < shape[1]; ++j)
{
size_t tileIndexX = i / tileSizeInPixel;
size_t tileIndexY = j / tileSizeInPixel;
if ((tileIndexX + tileIndexY) % 2 == 0)
image->write({i, j}, &blackValue);
else
image->write({i, j}, &whiteValue);
}
}
return image;
}
int
main(int argc, char** argv)
{
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
auto image = checkerBoard(1000);
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << "Checkerboard generated in "
<< std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << " microseconds"
<< std::endl;
std::cout << "Generated ImageView: " << image->toString() << std::endl;
return EXIT_SUCCESS;
}
Stores information about a data type.
Definition DataType.h:162
A dynamically sized arithmetic vector.
Definition VectorX.h:18
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8