diplib icon indicating copy to clipboard operation
diplib copied to clipboard

DIPjavaio to handle files with multiple images

Open crisluengo opened this issue 2 months ago • 7 comments

In Bio-Formats, reader.getSeriesCount() will return the number of images in the file, and reader.setSeries(i) will configure the reader to start reading the image number i.

We could add a parameter to dip::ImageReadJavaIO():

FileInformation ImageReadJavaIO(
      Image& out,
      String const& filename,
      String const& interface = bioformatsInterface,
      dip::uint imageNumber = 0
);

to indicate which image to read, and with a default value of 0. It being at the end is ugly but won't break code that currently uses this function.

dip::ImageReadTIFF() actually has a dip::Range parameter for the image number, and will concatenate all the images read. I'm not sure this is useful in the generic case of ImageReadJavaIO, which can deal with so many different file types. I'd rather write a new function that populates a std::vector of images. Right now I'm dealing with a CIF file that contains 50k tiny images, several Gb all together, I don't think it's a good idea to try to read that in one go. But on the other hand, some of these multi-image file formats don't have an index that points to each image, and the reader has to pass through all images before the one you want to read (see for example TIFF). So calling a reader function for each image is terrible. For these cases, you really want to initialize the reader, and return an iterator over images. But then the API starts to become quite complex...

Oh, OK, setSeries() should be fast. If so, opening the file could be slow? It's probably still more efficient to read many images in one go than calling dip::ImageReadJavaIO() for each image in a large file.

crisluengo avatar May 02 '24 18:05 crisluengo