From 3c17c706b8a5cb848fa080306df03ff87d1b3a88 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 31 Jan 2017 14:28:15 -0600 Subject: [PATCH] added a crop function to stim::image --- stim/envi/agilent_binary.h | 2 +- stim/image/image.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/stim/envi/agilent_binary.h b/stim/envi/agilent_binary.h index b30cb2a..14aa524 100644 --- a/stim/envi/agilent_binary.h +++ b/stim/envi/agilent_binary.h @@ -125,7 +125,7 @@ public: infile.read((char*)ptr, bytes()); //read the data infile.close(); Z[0] = 1; - Z[1] = R[2]; + Z[1] = (double)R[2]; } void save(std::string filename){ diff --git a/stim/image/image.h b/stim/image/image.h index 38da7ec..b6713ac 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -480,7 +480,6 @@ public: max_val = img[n]; } } - return max_val; } @@ -508,6 +507,20 @@ public: return r; //return the inverted image } + image crop(size_t x0, size_t y0, size_t w, size_t h){ + image result(w, h, C()); //create the output cropped image + + size_t srci; + size_t dsti; + size_t line_bytes = w * C(); //calculate the number of bytes in a line + for (size_t yi = 0; yi < h; yi++) { //for each row in the cropped image + srci = (y0 + yi) * X() * C() + x0 * C(); //calculate the source index + dsti = yi * w * C(); //calculate the destination index + memcpy(&result.img[dsti], &img[srci], line_bytes); //copy the data + } + return result; + } + image srgb2lab(){ std::cout<<"ERROR stim::image::srgb2lab - function has been broken, re-implement."<