我在神经实验室工作,记录小鼠大脑的图片。相机记录的原始文件记录来自交替相机的图片(大脑图片,鼠标图片,大脑图片等)我们将这些文件转换为TIFF,对它们进行解交织,然后连接文件。
连接速度太慢,无法使用。我还没有在Matlab中学到足够的知识来解决问题。我们如何才能提高此代码的速度?
%convert micam raw to 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 to TIFF');
pause (30); %to prevent race condition, needs to be fixed to wait for input
MIJ.exit;
%prepare tiff stack folder fast
myFolder = uigetdir;
cd(myFolder);
filePattern = fullfile(myFolder, '*.tif');
tifffiles = dir(filePattern);
count = length(tifffiles);
for z = 1:count
A = tifffiles.name;
I = imreadtiffstack (A, 256);
%crop tiff stack
sizecrop = size(I);
framenum = sizecrop(3);
cropcollector = ones([100 101 256] , 'uint16'); %preallocates matrix for depositing cropped frames
for 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 for odd deinterleaved frames
evencollector = ones([100 101 128], 'uint16'); %preallocates array for even deinterleaved frames
countodd = 0;
counteven = 0;
for 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);
even = 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