diff --git a/matlab/stimImageStack.m b/matlab/stimImageStack.m deleted file mode 100644 index fecae35..0000000 --- a/matlab/stimImageStack.m +++ /dev/null @@ -1,21 +0,0 @@ -function S = stimImageStack(filemask) - files = dir(filemask); - - %figure out the file size - I = imread([files(1).folder '/' files(1).name]); - X = size(I, 1); - Y = size(I, 2); - Z = length(files); - - S = zeros(X, Y, Z, 'uint8'); - - h = waitbar(0, ['Loading ' num2str(Z) ' images...']); - for i = 1:Z - I = rgb2gray(imread([files(1).folder '/' files(1).name])); - S(:, :, i) = I; - waitbar(i/Z, h); - end - close(h); -end - - diff --git a/matlab/stim_images2matrix.m b/matlab/stim_images2matrix.m new file mode 100644 index 0000000..edb3a33 --- /dev/null +++ b/matlab/stim_images2matrix.m @@ -0,0 +1,31 @@ +function S = stim_images2matrix(filemask) +%This function loads a set of images as a 3D matrix. Color images are +%converted to grayscale when loaded, so the resulting matrix is always 3D +%with size X x Y x Z, where: +% X is the size of the images along the X axis +% Y is the size of the images along the Y axis +% Z is the number of images +% +% all images are assumed to be the same size (though they do not have to +% be the same file format or number of bits per pixel + + files = dir(filemask); + + %figure out the file size + I = imread([files(1).folder '/' files(1).name]); + X = size(I, 1); + Y = size(I, 2); + Z = length(files); + + S = zeros(X, Y, Z, 'uint8'); + + h = waitbar(0, ['Loading ' num2str(Z) ' images...']); + for i = 1:Z + I = rgb2gray(imread([files(1).folder '/' files(1).name])); + S(:, :, i) = I; + waitbar(i/Z, h); + end + close(h); +end + + diff --git a/stim/image/image.h b/stim/image/image.h index b001232..97a15dd 100644 --- a/stim/image/image.h +++ b/stim/image/image.h @@ -53,6 +53,10 @@ class image{ void allocate(){ unalloc(); img = (T*) malloc( sizeof(T) * R[0] * R[1] * R[2] ); //allocate memory + if (img == NULL) { + std::cout << "stim::image ERROR - failed to allocate memory for image" << std::endl; + exit(1); + } } void allocate(size_t x, size_t y, size_t c){ //allocate memory based on the resolution @@ -228,6 +232,14 @@ public: } } #endif + //Copy N data points from source to dest, casting while doing so + template + void type_copy(S* source, D* dest, size_t N) { + if (typeid(S) == typeid(D)) //if both types are the same + memcpy(dest, source, N * sizeof(S)); //just use a memcpy + for (size_t n = 0; n < N; n++) //otherwise, iterate through each element + dest[n] = (D)source[n]; //copy and cast + } /// Load an image from a file void load(std::string filename){ #ifdef USING_OPENCV @@ -236,13 +248,15 @@ public: std::cout<<"ERROR stim::image::load() - unable to find image "<(cv_ptr, img, size()); if(C() == 3) //if this is a 3-color image, OpenCV uses BGR interleaving from_opencv(cv_ptr, X(), Y()); #else -- libgit2 0.21.4