Java - How to write a very large (20,000x20,000 px or larger) tif image -


i working extremely large tif images composing large single image. have library created colleague of mine generates image pyramid , provides handy tool visualizing image pyramid. visualizer great taking peak @ large image , visually identifying points of interest, customers more interested in image analysis on these large images.

thus, necessary export large image single file. find troublesome considering these images can anywhere 800 mb multiple gbs in size. , task of loading single image memory challenging, particularly when image analysis being done.

i wondering, if possible in java write large tiff image in block or line-by-line fashion. application running out of memory on small (8 gb ram) machines.

the current method composing these images is:

  1. store pixel values bufferedimage using writableraster

    short[][]pixels = ... bufferedimage image = new bufferedimage(width, height, type); writableraster = image.getraster(); (int row = 0; row < height; row++) {     (int col = 0; col < width; col++)     {        raster.setsample(col, row, 0, pixel[row][col]);     } }    
  2. and write buffered image disk. part using imagej write image tif. if there better ways support 16-bit grayscale tif images, happy take look

    // bufferedimage image; above ... imageplus img = new imageplus(); img.setimage(image); filesaver fs = new filesaver(img); fs.saveastiff(file.getabsolutepath());   

the problem method has large of memory footprint 8gb of ram machine.

ideally i'd have single short[][]pixels. because need compute average blending function, memory footprint there. in future adding linear blend. short[][]pixels should take ~765 mb of ram 20k x 20k pixel data, think unavoidable, larger images example 100k x 100k pixels, hope biologists not want export image take 18gb of ram.

later modify code support exporting extremely large images 100k x 100k. okay assuming 1 piece of memory store initial pixel values.

so, method writing portions of tif image disk can support writing out of core images such 100k x 100k images.

i did see post: write tiled output of tiff, using imageio in java

but discusses tiff 6.0 spec. imageoutputstreams. tif beast though might bite bullet , encourage biologists export regions of interest.

edit: found viable solution:

writer: https://github.com/openmicroscopy/bioformats/blob/v4.4.8/components/scifio/src/loci/formats/out/tiffwriter.java

and

reader: https://github.com/openmicroscopy/bioformats/blob/v4.4.8/components/scifio/src/loci/formats/in/tiffreader.java

main group page: https://github.com/openmicroscopy/bioformats

with scifio project, generalizing bio-formats image i/o framework target scientific imaging in general, beyond microscopy , life sciences. scifio api in beta now, , includes tiff can of course read , write in tiles. feedback on api , bugs on scifio mailing list welcome!


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -