Commit e702aa4e80b1581933484362c93261803fbd051d
1 parent
f5d34304
implemented array cropping
Showing
1 changed file
with
13 additions
and
0 deletions
Show diff stats
stim/image/image.h
... | ... | @@ -521,6 +521,19 @@ public: |
521 | 521 | return result; |
522 | 522 | } |
523 | 523 | |
524 | + //crop regions given by an array of 1D index values | |
525 | + std::vector<image<T>> crop_idx(size_t w, size_t h, std::vector<size_t> idx) { | |
526 | + std::vector<image<T>> result(idx.size()); //create an array of image files to return | |
527 | + for (size_t i = 0; i < idx.size(); i++) { //for each specified index point | |
528 | + size_t y = idx[i] / X(); //calculate the y coordinate from the 1D index (center of ROI) | |
529 | + size_t x = idx[i] - y * X(); //calculate the x coordinate (center of ROI) | |
530 | + y -= w / 2; //update x and y values to reflect the lower corner of the ROI | |
531 | + x -= h / 2; | |
532 | + result[i] = crop(x, y, w, h); //get the cropped image and store it in the result array | |
533 | + } | |
534 | + return result; | |
535 | + } | |
536 | + | |
524 | 537 | image<T> srgb2lab(){ |
525 | 538 | std::cout<<"ERROR stim::image::srgb2lab - function has been broken, re-implement."<<std::endl; |
526 | 539 | exit(1); | ... | ... |