edit Aperio metadata

Derek Magee D.R.Magee at leeds.ac.uk
Thu Aug 17 14:42:45 EDT 2017


P.S. Be careful changing the image description tag, it may contain vital information used by openslide (and possibly other software) to read the file.

From: Derek Magee
Sent: 17 August 2017 19:40
To: 'Sharma, Ashish'
Cc: openslide-users at lists.andrew.cmu.edu
Subject: RE: edit Aperio metadata

Ashish,

You can use libtif to decode and re-save/re-compress* an svs file (jpeg only). This will get rid of all tags except the ones you copy across (I think). I found the following in my experimental folder from when I was trying to understand this format. I’ve not checked it still works, but it will give you an idea of where to start.

HTH

Derek

* Obviously recompression is undesirable, it’s probably worth modifying to extract the uncompressed data and just saving that back. From memory libtiff supports that, and would have the added benefit of allowing you to process jpeg2000 encoded files (which will probably cause the program below to crash as libtiff can’t natively decompress jpeg2000 by default).

#include "tiffio.h"
#include <stdio.h>

int main(int argc, char* argv[])
{

    uint16 compression ;
    uint16 bitspersample ;
    uint16 samplesperpixel ;
    uint16 planar ;
    uint16 datatype ;
    uint16 photometric ;
    uint16 format ;
    uint32 idepth ;
    uint32 itype ;
    uint16 ycbcr[2] ;
    char *desc ;
    TIFF* tif = TIFFOpen(argv[1], "r");
    TIFF* tifout = TIFFOpen(argv[2], "w");

    if (tif) {
        int dircount = 0;
        do {
                printf("Image # %d\n================\n",dircount) ;

                TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression);
                TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);
                TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
                TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planar);
                TIFFGetField(tif, TIFFTAG_IMAGEDESCRIPTION, &desc);
                TIFFGetField(tif, TIFFTAG_IMAGEDEPTH, &idepth);
                TIFFGetField(tif, TIFFTAG_DATATYPE, &datatype);
                TIFFGetField(tif, TIFFTAG_SUBFILETYPE, &itype);
                TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric);
                TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &format);
                TIFFGetField(tif,TIFFTAG_YCBCRSUBSAMPLING, &(ycbcr[0]), &(ycbcr[1]));


                TIFFSetField(tifout, TIFFTAG_COMPRESSION, compression);
                TIFFSetField(tifout, TIFFTAG_BITSPERSAMPLE,bitspersample);
                TIFFSetField(tifout, TIFFTAG_SAMPLESPERPIXEL, samplesperpixel);
                TIFFSetField(tifout, TIFFTAG_PLANARCONFIG, planar);
                TIFFSetField(tifout, TIFFTAG_IMAGEDESCRIPTION, desc);

                TIFFSetField(tifout, TIFFTAG_IMAGEDEPTH, idepth);
                //TIFFSetField(tifout, TIFFTAG_DATATYPE, datatype);
                TIFFSetField(tifout, TIFFTAG_SUBFILETYPE, itype);
                TIFFSetField(tifout, TIFFTAG_PHOTOMETRIC, photometric);
                //TIFFSetField(tifout, TIFFTAG_SAMPLEFORMAT, format);
                TIFFSetField(tifout,TIFFTAG_YCBCRSUBSAMPLING, ycbcr[0],ycbcr[1]);

                if(TIFFIsTiled(tif)){
                // Tiled
                    uint32 w, h;
                    uint32 tileWidth, tileLength;
                    uint32 x, y;


                    tdata_t buf;
                    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
                    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
                    TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tileWidth);
                    TIFFGetField(tif, TIFFTAG_TILELENGTH, &tileLength);


                    TIFFSetField(tifout, TIFFTAG_IMAGEWIDTH, w);
                    TIFFSetField(tifout, TIFFTAG_IMAGELENGTH, h);
                    TIFFSetField(tifout, TIFFTAG_TILEWIDTH, tileWidth);
                    TIFFSetField(tifout, TIFFTAG_TILELENGTH, tileLength);


                    printf("Description: \n%s\n",desc) ;
                    printf("Size %d,%d (%d,%d)\n",w,h,tileWidth,tileLength) ;
                    buf = _TIFFmalloc(TIFFTileSize(tif));
                    printf("Buffer size: %d\n",TIFFTileSize(tif)) ;
                    for (y = 0; y < h; y += tileLength){
                        for (x = 0; x < w; x += tileWidth){
                            TIFFReadTile(tif, buf, x, y, 0,0);
                            TIFFWriteTile(tifout, buf, x, y, 0,0);
                        }
                    }
                    _TIFFfree(buf);

                    TIFFWriteDirectory(tifout) ;
                }
                else{
                    uint32 rowsPerStrip;
                    uint32 w, h;
                    tdata_t buf;
                    tstrip_t strip;
                    printf("Image is striped\n") ;
                    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
                    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
                   TIFFGetField(tif,TIFFTAG_ROWSPERSTRIP, &rowsPerStrip);


                    TIFFSetField(tifout, TIFFTAG_IMAGEWIDTH, w);
                    TIFFSetField(tifout, TIFFTAG_IMAGELENGTH, h);
                    TIFFSetField(tifout, TIFFTAG_ROWSPERSTRIP, rowsPerStrip);


                    printf("Description: \n%s\n",desc) ;
                    printf("Size %d,%d (%d)\n",w,h,rowsPerStrip) ;



                    buf = _TIFFmalloc(TIFFStripSize(tif));
                    for (strip = 0; strip < TIFFNumberOfStrips(tif); strip++){
                        TIFFReadEncodedStrip(tif, strip, buf, (tsize_t) -1);
                        TIFFWriteEncodedStrip(tifout, strip, buf, TIFFStripSize(tif));
                    }
                    _TIFFfree(buf);
                    TIFFWriteDirectory(tifout) ;
                }



            dircount++;
        } while (TIFFReadDirectory(tif));
        printf("%d directories in %s\n", dircount, argv[1]);
        TIFFClose(tif);
        TIFFClose(tifout);
    }
    else{
        printf("Failed to open %s\n",argv[1]) ;
    }


}




From: openslide-users [mailto:openslide-users-bounces+d.r.magee=leeds.ac.uk at lists.andrew.cmu.edu] On Behalf Of Sharma, Ashish
Sent: 17 August 2017 19:24
To: openslide-users at lists.andrew.cmu.edu<mailto:openslide-users at lists.andrew.cmu.edu>
Subject: edit Aperio metadata

Has anyone written an OpenSlide or TIFF based utility that allows one to edit header attributes, possibly as part of some anonymization script?
Or alternatively, scrub a specific tag like “Image-Description” or Comment in Aperio.

-Thanks
Ashish

————————————————————————————————————
Ashish Sharma, PhD
Assistant Professor
Department of Biomedical Informatics
Emory University

Woodruff Memorial Research Building
101 Woodruff Circle, #4105
Atlanta, GA 30322

Ph: (404) 654-0124
ashish.sharma at emory.edu<mailto:ashish.sharma at emory.edu>

________________________________

This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.andrew.cmu.edu/pipermail/openslide-users/attachments/20170817/e5b70671/attachment-0001.html>


More information about the openslide-users mailing list