0

My problem is that I have TIFF images with multiple levels (40x,20x,10x,5x) but some only have 40x level and I need all of them. My question is if there is any way to get 20x or other levels from 40x level images. I read about a library called vips but I don't understand how to use it to my specific problem.

jcupitt
  • 10,213
  • 2
  • 23
  • 39
Seakz
  • 11
  • I removed the currently irrelevant tags; if you're looking for _library suggestion_, this is the wrong place to do so as we're much more here to help with specific questions of the form "I tried X, but it did not do what I expect and instead resulted in an error!" accompanied by a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) .. however, I'm not sure that's the case: can you elaborate on your research into the TIFF format? – ti7 Feb 16 '22 at 16:01
  • I have some TIFF images which I open with the library openslide. Usually they have four levels which correspond to the augmentatios (40x,30x,20x,10x). The problem is that some of them only have one level (40x). I want to know if there is any way to obtain the other remaining levels from 40x, in order to have all the levels. If this is not the right place to ask this, I would appreciate if you tell me where to. – Seakz Feb 16 '22 at 16:08

1 Answers1

1

Yes, libvips can compute the missing levels for you. For example:

$ vips copy k2.tif x.tif[pyramid]

The [pyramid] is an option to the libvips TIFF writer to enable pyramid output. You can check the result with tiffinfo:

$ tiffinfo x.tif
TIFF Directory at offset 0x9437192 (900008)
  Image Width: 1450 Image Length: 2048
  Tile Width: 128 Tile Length: 128
  Resolution: 72.009, 72.009 pixels/inch
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: None
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Planar Configuration: single image plane
TIFF Directory at offset 0x11797866 (b4056a)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 725 Image Length: 1024
  Tile Width: 128 Tile Length: 128
  Resolution: 72.009, 72.009 pixels/inch
  Bits/Sample: 8
  Compression Scheme: None
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Planar Configuration: single image plane
TIFF Directory at offset 0x12388198 (bd0766)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 362 Image Length: 512
  Tile Width: 128 Tile Length: 128
  Resolution: 72.009, 72.009 pixels/inch
  Bits/Sample: 8
  Compression Scheme: None
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Planar Configuration: single image plane
TIFF Directory at offset 0x12585098 (c0088a)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 181 Image Length: 256
  Tile Width: 128 Tile Length: 128
  Resolution: 72.009, 72.009 pixels/inch
  Bits/Sample: 8
  Compression Scheme: None
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Planar Configuration: single image plane
TIFF Directory at offset 0x12634494 (c0c97e)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 90 Image Length: 128
  Tile Width: 128 Tile Length: 128
  Resolution: 72.009, 72.009 pixels/inch
  Bits/Sample: 8
  Compression Scheme: None
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Planar Configuration: single image plane

You can see it's written a five level pyramid, with each level being a tiled TIFF with 128 x 128 pixel tiles. That might or might not be correct for your application, you'd need to give a lot more information. For example:

$ vips copy k2.tif x.tif[pyramid,compression=jpeg,Q=85,tile-width=256,tile-height=256]

Might be better. Check the docs.

jcupitt
  • 10,213
  • 2
  • 23
  • 39