Matlab writes to two channels instead of one
Posted: Mon Jul 01, 2013 10:16 am
i am trying to read from three DIC channels and write them consequently in one channel, in Matlab. The first stack should be from the first channel then the first stack from the second channel is read and then the first stack from the third channel is read and so on.
Although my code should write to one channel only , i have found that it writes to a complete new channel with the same size as the one i am writing to. I use the loci java library as shown in the code below.
%program to read and write on the fly and put the images in the right order
%sticthing of 990= 33 stacks*60 time point:
clear;
clc;
tic;
%autoloadBioFormats = 1;
%%%%%%%%%input
%autoloadBioFormats = 1;
prompt1 = 'What is the number of timepoints ? ';
timepoints = input(prompt1);
prompt2 = 'What is the number of z planes? ';
nzplanes = input(prompt2);
%status = bfCheckJavaPath(autoloadBioFormats);
writer = loci.formats.ImageWriter();
writer.setWriteSequentially(true);
metadata = loci.formats.MetadataTools.createOMEXMLMetadata();
toInt = @(x) ome.xml.model.primitives.PositiveInteger(java.lang.Integer(x));
metadata = loci.formats.MetadataTools.createOMEXMLMetadata();
metadata.createRoot();
metadata.setImageID('Image:0', 0);
metadata.setPixelsID('Pixels:0', 0);
%%%%%%%%%%%%%%%%%
%%%%%%%%%%%
metadata.setPixelsBinDataBigEndian(java.lang.Boolean.TRUE, 0, 0);
metadata.setPixelsDimensionOrder(ome.xml.model.enums.DimensionOrder.XYZTC, 0);
metadata.setPixelsType(ome.xml.model.enums.PixelType.UINT16, 0);
imageWidth = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(512));
imageHeight = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(512));
numZSections = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(nzplanes));
numTimepoints = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(timepoints));
numChannels = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(1));
samplesPerPixel = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(1));
metadata.setPixelsSizeX(imageWidth, 0);
metadata.setPixelsSizeY(imageHeight, 0);
metadata.setPixelsSizeZ(numZSections, 0);
metadata.setPixelsSizeT(numTimepoints, 0);
metadata.setPixelsSizeC(numChannels, 0);
metadata.setChannelID('Channel:0:0', 0, 0);
metadata.setChannelSamplesPerPixel(samplesPerPixel, 0, 0);
writer.setMetadataRetrieve(metadata);
writer.getWriter('marimina_shaf3tik350.ome.tiff').setBigTiff(true);
writer.setId('marimina_shaf3tik351.ome.tiff');
getBytes = @(x) loci.common.DataTools.intsToBytes(x(:), 0);
%%%%%%the input module%%%%%%%%%%%%%%%%%%%
%autoloadBioFormats = 1;
%timepoints = 120;
%nzplanes = 33;
%nimages=nzplanes*timepoints;
%%%%%%%%%the Java module %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%nzplanes=33;
GG=[];
KK=[];
LL=[];
pp=[];
a=[1 : nzplanes];
b=[(nzplanes+1):2*nzplanes];
c=[(2*nzplanes+1):3*nzplanes];
pp=[1:nzplanes*timepoints];
pp2=reshape(pp,nzplanes,timepoints)';
for i=1:(timepoints/3)
GG(i,:)=a;
KK(i,:)=b;
LL(i,:)=c;
a=a+3*nzplanes;
b=b+3*nzplanes;
c=c+3*nzplanes;
end
for index=1:timepoints*nzplanes
for mndex=1:nzplanes
for kndex=1:(timepoints/3)
if(GG(kndex,mndex)==index)
path1='/Users/tbudev3/Documents/MATLAB/DIC0_t0000.tif';
pndex=pp2(kndex,mndex);
[plane1,map] = imread(path1,pndex);
writer.saveBytes(index-1, getBytes(plane1));
end
if(KK(kndex,mndex)==index)
path2='/Users/tbudev3/Documents/MATLAB/DIC1_t0000.tif';
pndex=pp2(kndex,mndex);
[plane2,map] = imread(path2,pndex);
writer.saveBytes(index-1, getBytes(plane2));
end
if(LL(kndex,mndex)==index)
path3='/Users/tbudev3/Documents/MATLAB/DIC2_t0000.tif';
pndex=pp2(kndex,mndex);
[plane3,map] = imread(path3,pndex);
writer.saveBytes(index-1, getBytes(plane3));
end
end
end
end
writer.close();
Although my code should write to one channel only , i have found that it writes to a complete new channel with the same size as the one i am writing to. I use the loci java library as shown in the code below.
%program to read and write on the fly and put the images in the right order
%sticthing of 990= 33 stacks*60 time point:
clear;
clc;
tic;
%autoloadBioFormats = 1;
%%%%%%%%%input
%autoloadBioFormats = 1;
prompt1 = 'What is the number of timepoints ? ';
timepoints = input(prompt1);
prompt2 = 'What is the number of z planes? ';
nzplanes = input(prompt2);
%status = bfCheckJavaPath(autoloadBioFormats);
writer = loci.formats.ImageWriter();
writer.setWriteSequentially(true);
metadata = loci.formats.MetadataTools.createOMEXMLMetadata();
toInt = @(x) ome.xml.model.primitives.PositiveInteger(java.lang.Integer(x));
metadata = loci.formats.MetadataTools.createOMEXMLMetadata();
metadata.createRoot();
metadata.setImageID('Image:0', 0);
metadata.setPixelsID('Pixels:0', 0);
%%%%%%%%%%%%%%%%%
%%%%%%%%%%%
metadata.setPixelsBinDataBigEndian(java.lang.Boolean.TRUE, 0, 0);
metadata.setPixelsDimensionOrder(ome.xml.model.enums.DimensionOrder.XYZTC, 0);
metadata.setPixelsType(ome.xml.model.enums.PixelType.UINT16, 0);
imageWidth = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(512));
imageHeight = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(512));
numZSections = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(nzplanes));
numTimepoints = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(timepoints));
numChannels = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(1));
samplesPerPixel = ome.xml.model.primitives.PositiveInteger(java.lang.Integer(1));
metadata.setPixelsSizeX(imageWidth, 0);
metadata.setPixelsSizeY(imageHeight, 0);
metadata.setPixelsSizeZ(numZSections, 0);
metadata.setPixelsSizeT(numTimepoints, 0);
metadata.setPixelsSizeC(numChannels, 0);
metadata.setChannelID('Channel:0:0', 0, 0);
metadata.setChannelSamplesPerPixel(samplesPerPixel, 0, 0);
writer.setMetadataRetrieve(metadata);
writer.getWriter('marimina_shaf3tik350.ome.tiff').setBigTiff(true);
writer.setId('marimina_shaf3tik351.ome.tiff');
getBytes = @(x) loci.common.DataTools.intsToBytes(x(:), 0);
%%%%%%the input module%%%%%%%%%%%%%%%%%%%
%autoloadBioFormats = 1;
%timepoints = 120;
%nzplanes = 33;
%nimages=nzplanes*timepoints;
%%%%%%%%%the Java module %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%nzplanes=33;
GG=[];
KK=[];
LL=[];
pp=[];
a=[1 : nzplanes];
b=[(nzplanes+1):2*nzplanes];
c=[(2*nzplanes+1):3*nzplanes];
pp=[1:nzplanes*timepoints];
pp2=reshape(pp,nzplanes,timepoints)';
for i=1:(timepoints/3)
GG(i,:)=a;
KK(i,:)=b;
LL(i,:)=c;
a=a+3*nzplanes;
b=b+3*nzplanes;
c=c+3*nzplanes;
end
for index=1:timepoints*nzplanes
for mndex=1:nzplanes
for kndex=1:(timepoints/3)
if(GG(kndex,mndex)==index)
path1='/Users/tbudev3/Documents/MATLAB/DIC0_t0000.tif';
pndex=pp2(kndex,mndex);
[plane1,map] = imread(path1,pndex);
writer.saveBytes(index-1, getBytes(plane1));
end
if(KK(kndex,mndex)==index)
path2='/Users/tbudev3/Documents/MATLAB/DIC1_t0000.tif';
pndex=pp2(kndex,mndex);
[plane2,map] = imread(path2,pndex);
writer.saveBytes(index-1, getBytes(plane2));
end
if(LL(kndex,mndex)==index)
path3='/Users/tbudev3/Documents/MATLAB/DIC2_t0000.tif';
pndex=pp2(kndex,mndex);
[plane3,map] = imread(path3,pndex);
writer.saveBytes(index-1, getBytes(plane3));
end
end
end
end
writer.close();