diff --git a/main.m b/main.m index 397b850..8a788e2 100644 --- a/main.m +++ b/main.m @@ -19,7 +19,7 @@ save(fn, 'data_g', 'data_r', '-v7.3'); %% load files %if you haven't used the shiftCorrection you have to load the already processed files -fn_green = 'processedData.mat'; +fn= 'processedData.mat'; load(fn); %% 1. PCA %calculate PCAs diff --git a/readTif.m b/readTif.m new file mode 100644 index 0000000..2e5e45a --- /dev/null +++ b/readTif.m @@ -0,0 +1,28 @@ +function out = readTif(fName) +% Function for speed-optimized reading of tif files, ignoring all meta-data +% and dimension sorting + +ww = imfinfo(fName); % Tif file information +nCol = ww(1).SamplesPerPixel; % Number of color channels (NOT TESTED!) +nImg = numel(ww); % Number of frames +if ww(1).BitsPerSample(1) <= 16 + out = zeros(ww(1).Height, ww(1).Width,nCol, nImg,'uint16'); +else + out = zeros(ww(1).Height, ww(1).Width, nCol, nImg); +end +readLength = [ww(1).Width ww(1).Height]; % order has to be reversed for correct reading of data (don't know why) +gl_fid = fopen (fName, 'r', 'l'); +for j=1:nImg + for col=1:nCol + fseek(gl_fid, ww(j).StripOffsets(col) , 'bof'); + if ww(j).BitsPerSample(col) <=8 + out(:,:,col,j) = uint16(fread(gl_fid,readLength, '*uint8'))'; + elseif ww(j).BitsPerSample(col) <=16 + out(:,:,col,j) = fread(gl_fid, readLength, '*uint16')'; + else ww(j).BitsPerSample(col) + out(:,:,col,j) = fread(gl_fid,readLength, 'uint32')'; + end + end +end +fclose(gl_fid); +out = squeeze(out); \ No newline at end of file