We're Hiring!

How to make deep copy of a bio-formats reader in Matlab

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

How to make deep copy of a bio-formats reader in Matlab

Postby Ajaxel » Wed Aug 15, 2018 2:46 pm

Hello,
I have the following example, where I would like to make a copy of a bio-format reader. Unfortunately, Matlab copies only the handle and does not allow me to make a deep copy of the reader.
Is there a way to duplicate the reader somehow, so that the code works?

Code: Select all
reader1 = bfGetReader('myfile.ext');     % get a reader
reader2 = reader1;             % duplicate the reader;
                                         % the 'copy' function does not work on
                                         % loci.formats.ChannelSeparator class
plane1 = bfGetPlane(reader1, 1);         % get a plane
plane2 = bfGetPlane(reader2, 1);        % get a plane
reader1.close();                                 % close the first reader
plane2 = bfGetPlane(reader2, 1);        % does not work


Thanks!
Ajaxel
 
Posts: 14
Joined: Mon Apr 22, 2013 8:33 pm

Re: How to make deep copy of a bio-formats reader in Matlab

Postby sbesson » Thu Aug 16, 2018 8:25 am

Hi,

At the moment, there is no easy way to deep copy a reader as you said but you should be able to create and initialize multiple readers against the same file. It might useful to know what you would like to achieve with the copy of the readers.

In the case of creating multiple readers, if the initialization time is the major issue, you should be able to use the memoization API to store the state of an initialized reader to disk and reuse this cache file for initializing new readers. See https://docs.openmicroscopy.org/bio-for ... erformance for an example of doing so.

Best,
Sebastien
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm

Re: How to make deep copy of a bio-formats reader in Matlab

Postby Ajaxel » Thu Aug 16, 2018 9:24 am

Hi Sebastien,
Thank you for suggestion!
I was just hoping that there is an easy way to duplicate the reader but otherwise the following codes seems to work

WITH MEMORIZER
Code: Select all
pathToFile = 'd:\myfile.tmp';
seriesNumber = 1;
% Construct a Bio-Formats reader decorated with the Memoizer wrapper
reader1 = loci.formats.Memoizer(bfGetReader(), 0);
% Initialize the reader with an input file to cache the reader
reader1.setId(pathToFile);
reader1.setSeries(seriesNumber-1);
% get a plane
plane1 = bfGetPlane(reader1, 1);       
% Initialize a new reader
reader2 = javaObject('loci.formats.Memoizer', bfGetReader(), 0);
% Initialization should use the memo file
reader2.setId(pathToFile);
reader2.setSeries(seriesNumber-1);
% Close reader 1
reader1.close();
plane2 = bfGetPlane(reader2, 1);         % get a plane
% Close reader 2
reader2.close();


WITHOUT MEMORIZER
Code: Select all
pathToFile = 'd:\myfile.tmp';
seriesNumber = 1;
% Construct a Bio-Formats reader
reader1 = bfGetReader(pathToFile);
reader1.setSeries(seriesNumber-1);
% get a plane
plane1 = bfGetPlane(reader1, 1);       
% Initialize a new reader
reader2 = bfGetReader(pathToFile);
reader2.setSeries(seriesNumber-1);
% Close reader 1
reader1.close();
plane2 = bfGetPlane(reader2, 1);         % get a plane
% Close reader 2
reader2.close();


Thanks!
Ajaxel
 
Posts: 14
Joined: Mon Apr 22, 2013 8:33 pm


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest

cron