Fwd: OpenSlide library inquiry

Benjamin Gilbert bgilbert at cs.cmu.edu
Fri Jun 29 14:29:08 EDT 2012


On 06/27/2012 02:58 PM, David Gutman wrote:
> The files are being written out as YCbCr.... but one of the programs I
> am using to view these (IIPIMAGE) seems to want RGB images.. Wasn't
> sure if you knew of a way to transcode to RGB directly--- or if I have
> to first use VIPS/Openslide to convert it to an LZW/TIFF single layer
> file then convert it to a "pyramid" for visualization in RGB format..

It looks as though libvips always uses YCbCr subsampling when writing an 
RGB image to a JPEG-compressed TIFF.

 From write_tiff_header() in vips2tiff.c:  (Irrelevant details removed)

switch( tw->im->Bands ) {
[...]
case 3:
	if( tw->im->Type == VIPS_INTERPRETATION_LAB ||
		tw->im->Type == VIPS_INTERPRETATION_LABS )
		photometric = PHOTOMETRIC_CIELAB;
	else if( tw->im->Type == VIPS_INTERPRETATION_CMYK ) {
		photometric = PHOTOMETRIC_SEPARATED;
		TIFFSetField( tif,
			TIFFTAG_INKSET, INKSET_CMYK );
	}
	else if( tw->compression == COMPRESSION_JPEG &&
		tw->im->Bands == 3 )
		/* This signals to libjpeg that it can do
		 * YCbCr chrominance subsampling from RGB, not
		 * that we will supply the image as YCbCr.
		 */
		photometric = PHOTOMETRIC_YCBCR;
	else
		photometric = PHOTOMETRIC_RGB;

	break;
[...]
}
TIFFSetField( tif, TIFFTAG_PHOTOMETRIC, photometric );

So if you generate your pyramidal TIFF using LZW instead of JPEG, you'll 
get an RGB photometric interpretation.  Of course you'll also get a huge 
file.  Or, as you said, you might be able to write a single-layer LZW 
TIFF and then use a different tool to generate the pyramidal file.

--Benjamin Gilbert


More information about the openslide-users mailing list