Created
March 6, 2019 07:09
-
-
Save marty1885/3090ac0dc393656ff9b176eba5063bff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline xt::xarray<uint16_t> load_image(std::string path) | |
{ | |
std::ifstream in(path); | |
xt::xarray<int> arr = xt::load_csv<int>(in); | |
in.close(); | |
//Image padding | |
xt::xarray<int> resized_image = xt::zeros<int>({arr.shape()[0]+2, arr.shape()[1]+1}); | |
xt::view(resized_image, xt::range(1, arr.shape()[0]+1), xt::range(1, arr.shape()[1]+1)) = arr; | |
//Handle tile padding | |
size_t paded_height = up_rounding(resized_image.shape()[0], 4); | |
size_t paded_width = up_rounding(resized_image.shape()[1], 6); | |
size_t x_tiles = paded_width/6; | |
size_t y_tiles = ((paded_height-6)/4+1)*2; | |
xt::xarray<uint16_t> res = xt::zeros<uint16_t>({(int)(x_tiles*y_tiles), 18}); | |
for(size_t x=0;x<x_tiles;x++) { | |
for(size_t y=0;y<y_tiles;y++) { | |
xt::xarray<uint16_t> tile = xt::zeros<uint16_t>({18}); | |
size_t y_start = y*3 - (y/2)*2; | |
size_t x_start = x*6; | |
xt::xarray<uint16_t> v = xt::view(resized_image, xt::range(y_start, std::min(y_start+3, resized_image.shape()[0])) | |
, xt::range(x_start, std::min(x_start+6, resized_image.shape()[1]))); | |
v = xt::transpose(v); | |
xt::xarray<uint16_t> f = xt::flatten(v); | |
std::cerr << f << std::endl; | |
for(size_t i=0;i<f.size();i++) | |
tile[i] = f[i]; | |
xt::view(res, x*y_tiles+y) = tile; | |
} | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment