Last active
May 12, 2017 17:36
-
-
Save f-ilic/0238a48bd0eb6b2ddac15ba40ba716fa 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
| using Pixel = vector<float>; | |
| class Patch { | |
| Patch(int x, int y, float* img, int img_width, int patchsize); | |
| Pixel at(int x, int y) { | |
| return getRow(y)[x]; | |
| } | |
| vector<Pixel> getRow(int row_idx) { | |
| if(row_idx < size){ | |
| return pixels[row_idx]; | |
| } else { | |
| cout << "FUCKED UP YOUR INDEXING! ABORT" << endl; | |
| } | |
| } | |
| private: | |
| vector<vector<Pixel>> pixels; | |
| int size; | |
| }; | |
| Patch::Patch(int x, int y, float* img, int img_width, int patch_size) { | |
| int patch_idx = 0; | |
| int xy_coord_idx = 0; | |
| for(int idx_y = y-patch_size; idx_y < y; idx_y++){ | |
| vector<Pixel> row; | |
| for(int idx_x = x-patch_size; idx_x < x; idx_x++){ | |
| xy_coord_idx = (idx_x*3)+(idx_y * img_width); | |
| Pixel p; | |
| p.push_back(img[xy_coord_idx+0]); // r | |
| p.push_back(img[xy_coord_idx+1]); // g | |
| p.push_back(img[xy_coord_idx+2]); // b | |
| patch_idx += 3; //index for position in unidimensional patch array | |
| row.push_back(p); | |
| } | |
| pixels.push_back(row); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment