Page 1 of 1

Matlab writes to two channels instead of one

PostPosted: Mon Jul 01, 2013 10:16 am
by michel
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();

Re: Matlab writes to two channels instead of one

PostPosted: Mon Jul 01, 2013 1:43 pm
by mlinkert
I would suggest first changing the 'path1', 'path2', and 'path3' variables such that the file extension is ".ome.tiff" instead of ".tif". Using the ".tif" extension means that plain TIFF files will be written (instead of OME-TIFF files), which means that all of the metadata that is set will not be written to the files.

If using the ".ome.tiff" extension does not solve the problem, please let us know.

-Melissa

Re: Matlab writes to two channels instead of one

PostPosted: Mon Jul 01, 2013 1:51 pm
by michel
Melisaa,
I read tiff files , which are the output of Andor microscope .Thus the path shown is the path of the files to be read. I want to convert them to ome.tiff to be read by Endrov. The output is in omi.tiff file

Re: Matlab writes to two channels instead of one

PostPosted: Thu Jul 04, 2013 12:24 am
by mlinkert
Sorry, my mistake. Could you then please upload a Zip file with all three original TIFF files to:

http://qa.openmicroscopy.org.uk/qa/upload/

I don't see anything obviously wrong with your code, but if the original plane dimensions don't exactly match what is set in the Matlab script, then that could cause this problem.

You may also want to consider using Bio-Formats to read the original files, as that could greatly simplify your code. The bfopen.m script (documented here: http://www.openmicroscopy.org/site/supp ... b-dev.html) reads images and the metadata necessary for initializing an ImageWriter.