Commit 3c17c706b8a5cb848fa080306df03ff87d1b3a88
1 parent
e3b53161
added a crop function to stim::image
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
stim/envi/agilent_binary.h
stim/image/image.h
... | ... | @@ -480,7 +480,6 @@ public: |
480 | 480 | max_val = img[n]; |
481 | 481 | } |
482 | 482 | } |
483 | - | |
484 | 483 | return max_val; |
485 | 484 | } |
486 | 485 | |
... | ... | @@ -508,6 +507,20 @@ public: |
508 | 507 | return r; //return the inverted image |
509 | 508 | } |
510 | 509 | |
510 | + image<T> crop(size_t x0, size_t y0, size_t w, size_t h){ | |
511 | + image<T> result(w, h, C()); //create the output cropped image | |
512 | + | |
513 | + size_t srci; | |
514 | + size_t dsti; | |
515 | + size_t line_bytes = w * C(); //calculate the number of bytes in a line | |
516 | + for (size_t yi = 0; yi < h; yi++) { //for each row in the cropped image | |
517 | + srci = (y0 + yi) * X() * C() + x0 * C(); //calculate the source index | |
518 | + dsti = yi * w * C(); //calculate the destination index | |
519 | + memcpy(&result.img[dsti], &img[srci], line_bytes); //copy the data | |
520 | + } | |
521 | + return result; | |
522 | + } | |
523 | + | |
511 | 524 | image<T> srgb2lab(){ |
512 | 525 | std::cout<<"ERROR stim::image::srgb2lab - function has been broken, re-implement."<<std::endl; |
513 | 526 | exit(1); | ... | ... |