performance - Speed up deinterleave and concatenation for TIFF -


i work in neuro-lab records pictures of mouse brains. raw files cameras record record pictures alternating cameras (picture of brain, picture of mouse head, picture of brain, etc) we're converting these files tiff, deinterleaving them, , concatenating files.

the concatenation far slow of use. i'm not yet learned enough in matlab able troubleshoot. how can improve speed of code?

%convert micam raw tiff using image j javaaddpath 'c:\program files\matlab\r2013a\java\mij.jar'; javaaddpath 'c:\program files\matlab\r2013a\java\ij.jar'; mij.start('c:\users\lee\desktop\imagej'); mij.run('install...', 'install=[c:\\users\\lee\\desktop\\imagej\\macros\\matthias\\helmchen macros modified djm.ijm]'); mij.run('run...', 'path=[c:\\users\\lee\\desktop\\imagej\\macros\\matthias\\helmchen macros modified djm.ijm]'); mij.run('convert micam raw tiff'); pause (30); %to prevent race condition, needs fixed wait input mij.exit; %prepare tiff stack folder fast myfolder = uigetdir; cd(myfolder); filepattern = fullfile(myfolder, '*.tif'); tifffiles = dir(filepattern); count = length(tifffiles); z = 1:count = tifffiles.name;   = imreadtiffstack (a, 256);  %crop tiff stack sizecrop = size(i); framenum = sizecrop(3);  cropcollector = ones([100 101 256] , 'uint16'); %preallocates matrix depositing cropped frames  k = 1:framenum     frame = i(:,:,k);     i2 = imcrop(frame,[20 0 100 100]);     cropcollector(:,:,k)=i2; %deinterleaves tiff stack sizedinlv = size(cropcollector); framenumdinlv = sizedinlv(3); oddcollector = ones([100 101 128], 'uint16'); %preallocates array odd deinterleaved frames evencollector = ones([100 101 128], 'uint16'); %preallocates array deinterleaved frames countodd = 0; counteven = 0; k2 = (1:framenumdinlv)     if mod(k2, 2)==1     framedinlv = cropcollector(:,:,k2);     countodd = countodd +1;     oddcollector(:,:,countodd)=framedinlv;     else         framedinlv = cropcollector(:,:,k2);         counteven = counteven + 1;         evencollector(:,:,counteven)=framedinlv; %concatenate                if mod (z, 2)==1;         oddhold = ones([100 101 128], 'uint16');         evenhold = ones([100 101 128], 'uint16');          oddhold = repmat(oddcollector, 1);         evenhold = repmat(evencollector, 1);          else           odd = num2str(1);           = num2str(2);           brain = ones([100 101 256], 'uint16');           mouse = ones([100 101 256], 'uint16');           % nameoddframes = strcat(a(1:10), odd);           %nameevenframes = strcat(a(1:10), even);           brain = cat(3, oddhold, oddcollector);           mouse = cat(3, evenhold, evencollector);          end       end   end   end   end %background subtraction 


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -