diff --git a/stim/envi/bil.h b/stim/envi/bil.h index 826bf05..591c44c 100644 --- a/stim/envi/bil.h +++ b/stim/envi/bil.h @@ -884,7 +884,7 @@ public: /// using the following indexing: i = p*B + b /// @param matrix is the destination for the pixel data /// @param mask is the mask - bool sift(T* matrix, unsigned char* mask = NULL){ + bool sift(T* matrix, unsigned char* mask = NULL, bool PROGRESS = false){ size_t Lbytes = sizeof(T) * X(); T* line = (T*) malloc( Lbytes ); //allocate space for a line @@ -903,6 +903,7 @@ public: pl++; //increment the pixel pointer } } + if(PROGRESS) progress = (double)( (y+1)*Z() + 1) / (double)(Y() * Z()) * 100; } p += pl; //add the line increment to the running pixel index } diff --git a/stim/envi/bip.h b/stim/envi/bip.h index 648e925..b9e56db 100644 --- a/stim/envi/bip.h +++ b/stim/envi/bip.h @@ -817,7 +817,7 @@ public: /// using the following indexing: i = p*B + b /// @param matrix is the destination for the pixel data /// @param mask is the mask - bool sift(T* matrix, unsigned char* mask = NULL){ + bool sift(T* matrix, unsigned char* mask = NULL, bool PROGRESS = false){ size_t Bbytes = sizeof(T) * Z(); size_t XY = X() * Y(); T* band = (T*) malloc( Bbytes ); //allocate space for a line @@ -836,6 +836,7 @@ public: } else file.seekg(Bbytes, std::ios::cur); //otherwise skip this band + if(PROGRESS) progress = (double)(xy+1) / (double)XY * 100; } return true; } diff --git a/stim/envi/bsq.h b/stim/envi/bsq.h index 840906f..b2c116c 100644 --- a/stim/envi/bsq.h +++ b/stim/envi/bsq.h @@ -809,7 +809,7 @@ public: /// using the following indexing: i = p*B + b /// @param matrix is the destination for the pixel data /// @param mask is the mask - bool sift(T* matrix, unsigned char* mask = NULL){ + bool sift(T* matrix, unsigned char* mask = NULL, bool PROGRESS = false){ unsigned long long XY = X() * Y(); //Number of XY pixels unsigned long long L = XY * sizeof(T); //size of XY plane (in bytes) @@ -827,9 +827,8 @@ public: if(mask == NULL || mask[xy] != 0){ //if the pixel is valid matrix[i*Z() + b] = band_image[xy]; //copy it to the appropriate point in the values[] array i++; - //std::cout<*)file)->sift((float*)matrix, p); + return ((bsq*)file)->sift((float*)matrix, p, PROGRESS); else if (header.data_type == envi_header::float64) - return ((bsq*)file)->sift((double*)matrix, p); + return ((bsq*)file)->sift((double*)matrix, p, PROGRESS); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); @@ -685,9 +685,9 @@ public: if (header.interleave == envi_header::BIP){ if (header.data_type == envi_header::float32) - return ((bip*)file)->sift((float*)matrix, p); + return ((bip*)file)->sift((float*)matrix, p, PROGRESS); else if (header.data_type == envi_header::float64) - return ((bip*)file)->sift((double*)matrix, p); + return ((bip*)file)->sift((double*)matrix, p, PROGRESS); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); @@ -695,9 +695,9 @@ public: } if (header.interleave == envi_header::BIL){ if (header.data_type == envi_header::float32) - return ((bil*)file)->sift((float*)matrix, p); + return ((bil*)file)->sift((float*)matrix, p, PROGRESS); else if (header.data_type == envi_header::float64) - return ((bil*)file)->sift((double*)matrix, p); + return ((bil*)file)->sift((double*)matrix, p, PROGRESS); else{ std::cout << "ERROR: unidentified data type" << std::endl; exit(1); diff --git a/stim/image/image.h b/stim/image/image.h index d8e8b6f..02f7dc1 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -6,7 +6,6 @@ #include #include #include -#include namespace stim{ /// This static class provides the STIM interface for loading, saving, and storing 2D images. @@ -25,8 +24,6 @@ class image{ size_t Y() const { return R[2]; } size_t C() const { return R[0]; } - size_t bytes(){ return size() * sizeof(T); } - void init(){ //initializes all variables, assumes no memory is allocated memset(R, 0, sizeof(size_t) * 3); //set the resolution and number of channels to zero img = NULL; @@ -34,7 +31,6 @@ class image{ void unalloc(){ //frees any resources associated with the image if(img) free(img); //if memory has been allocated, free it - img=NULL; } @@ -45,16 +41,15 @@ class image{ void allocate(){ unalloc(); - img = (T*) malloc( bytes() ); //allocate memory - memset(img, 0, bytes()); + img = (T*) malloc( sizeof(T) * R[0] * R[1] * R[2] ); //allocate memory } void allocate(size_t x, size_t y, size_t c){ //allocate memory based on the resolution - unalloc(); R[0] = c; R[1] = x; R[2] = y; //set the resolution allocate(); //allocate memory } + size_t bytes(){ return size() * sizeof(T); } size_t idx(size_t x, size_t y, size_t c = 0){ return y * C() * X() + x * C() + c; @@ -62,23 +57,13 @@ class image{ int cv_type(){ - // The following is C++ 11 code, but causes problems on some compilers (ex. nvcc). Below is my best approximation to a solution - - //if(std::is_same::value) return CV_MAKETYPE(CV_8U, (int)C()); - //if(std::is_same::value) return CV_MAKETYPE(CV_8S, (int)C()); - //if(std::is_same::value) return CV_MAKETYPE(CV_16U, (int)C()); - //if(std::is_same::value) return CV_MAKETYPE(CV_16S, (int)C()); - //if(std::is_same::value) return CV_MAKETYPE(CV_32S, (int)C()); - //if(std::is_same::value) return CV_MAKETYPE(CV_32F, (int)C()); - //if(std::is_same::value) return CV_MAKETYPE(CV_64F, (int)C()); - - if(typeid(T) == typeid(unsigned char)) return CV_MAKETYPE(CV_8U, (int)C()); - if(typeid(T) == typeid(char)) return CV_MAKETYPE(CV_8S, (int)C()); - if(typeid(T) == typeid(unsigned short)) return CV_MAKETYPE(CV_16U, (int)C()); - if(typeid(T) == typeid(short)) return CV_MAKETYPE(CV_16S, (int)C()); - if(typeid(T) == typeid(int)) return CV_MAKETYPE(CV_32S, (int)C()); - if(typeid(T) == typeid(float)) return CV_MAKETYPE(CV_32F, (int)C()); - if(typeid(T) == typeid(double)) return CV_MAKETYPE(CV_64F, (int)C()); + if(std::is_same::value) return CV_MAKETYPE(CV_8U, (int)C()); + if(std::is_same::value) return CV_MAKETYPE(CV_8S, (int)C()); + if(std::is_same::value) return CV_MAKETYPE(CV_16U, (int)C()); + if(std::is_same::value) return CV_MAKETYPE(CV_16S, (int)C()); + if(std::is_same::value) return CV_MAKETYPE(CV_32S, (int)C()); + if(std::is_same::value) return CV_MAKETYPE(CV_32F, (int)C()); + if(std::is_same::value) return CV_MAKETYPE(CV_64F, (int)C()); std::cout<<"ERROR in stim::image::cv_type - no valid data type found"<::value) return UCHAR_MAX; - //if(std::is_same::value) return SHRT_MAX; - //if(std::is_same::value) return UINT_MAX; - //if(std::is_same::value) return ULONG_MAX; - //if(std::is_same::value) return ULLONG_MAX; - //if(std::is_same::value) return 1.0f; - //if(std::is_same::value) return 1.0; - - if(typeid(T) == typeid(unsigned char)) return UCHAR_MAX; - if(typeid(T) == typeid(unsigned short)) return SHRT_MAX; - if(typeid(T) == typeid(unsigned)) return UINT_MAX; - if(typeid(T) == typeid(unsigned long)) return ULONG_MAX; - if(typeid(T) == typeid(unsigned long long)) return ULLONG_MAX; - if(typeid(T) == typeid(float)) return 1.0f; - if(typeid(T) == typeid(double)) return 1.0; + if(std::is_same::value) return UCHAR_MAX; + if(std::is_same::value) return SHRT_MAX; + if(std::is_same::value) return UINT_MAX; + if(std::is_same::value) return ULONG_MAX; + if(std::is_same::value) return ULLONG_MAX; + if(std::is_same::value) return 1.0f; + if(std::is_same::value) return 1.0; std::cout<<"ERROR in stim::image::white - no white value known for this data type"< &I){ + image(const stim::image& I){ init(); allocate(I.X(), I.Y(), I.C()); memcpy(img, I.img, bytes()); @@ -147,7 +120,16 @@ public: free(img); } + /*stim::image operator=(const stim::image& I){ + if(&I == this) //handle self-assignment + return *this; + allocate(I.X(), I.Y(), I.C()); + memcpy(img, I.img, bytes()); + return *this; + }*/ + stim::image& operator=(const stim::image& I){ + init(); if(&I == this) //handle self-assignment return *this; allocate(I.X(), I.Y(), I.C()); @@ -160,22 +142,15 @@ public: cv::Mat cvImage = cv::imread(filename, CV_LOAD_IMAGE_UNCHANGED); //use OpenCV to open the image file if(!cvImage.data){ - std::cout<<"ERROR stim::image::load() - unable to find image "< invert(){ - size_t N = size(); //calculate the total number of values in the image - image r(X(), Y(), C()); //allocate space for the resulting image - T white_val = maxv(); - for(size_t n = 0; n < N; n++) - r.img[n] = white_val - img[n]; //perform the inversion - - return r; //return the inverted image - } - - ///crops the image from x1 to x0 and y1 to y0 and returns a new (smaller) image. - image crop(int x0, int x1, int y0, int y1) - { - - image ret(x1-x0, y1-y0, C()); - int newWidth = x1-x0; - int destidx, srcidx; - ///for each row, cut what amount of data from the original and put it into the new copy. - for(int i = 0; i < (y1-y0); i++) - { - destidx = i*newWidth*C(); ///destination index one per each row - srcidx = ((i+(y0))*X()+x0)*C(); ///source index, one per each row. - memcpy(&ret.img[destidx], &img[srcidx], sizeof(T)*newWidth*C()); - } - return ret; - } image srgb2lab(){ std::cout<<"ERROR stim::image::srgb2lab - function has been broken, re-implement."<