目录
一:TIFF读图工具
1.QuaPath:https://github.com/qupath
2.ASAP:https://github.com/computationalpathologygroup/ASAP
二: TIFF 格式限制
TIFF格式限制了其文件只能存储最大4G,超出4个G无法存储,打破该限制的方法为使用本系列所推荐的方法编译最新的4.1版本,然后将文件存储为bigtiff
如何存储为bigTIFF?
只需要在TIFFOpen函数的参数里面增加一个选项即可
//w 代表写文件,8 代表bigtiff ,4 代表标准tiff,默认为4
TIFFOpen(pcPath, "w8");
三:存储tile 图像
bool SaveTile(const uchar *pucTile, uchar *pucJpeg, const int nL, const int nT,
const int nR, const int nB, const int nLayer, const int nFocus)
{
LOG_E("left = %d,top = %d,bottom = %d,right = %d, nLayer=%d,nFocus=%d", nL, nT, nB, nR,nLayer,nFocus);
LAYER_S &stLayer = m_pD->stTmap.stLayers[nLayer];
const int nWidth = nR - nL;
const int nHeight = nB - nT;
int nLength = 0;
try
{
TIFFSetDirectory(m_pD->pfFile, nLayer);
TIFFSetField(m_pD->pfFile, TIFFTAG_IMAGEWIDTH, stLayer.nWidth);
TIFFSetField(m_pD->pfFile, TIFFTAG_IMAGELENGTH, stLayer.nHeight);
TIFFSetField(m_pD->pfFile, TIFFTAG_ROWSPERSTRIP, stLayer.nHeight);
TIFFSetField(m_pD->pfFile, TIFFTAG_TILEWIDTH, m_pD->nTileW);
TIFFSetField(m_pD->pfFile, TIFFTAG_TILELENGTH, m_pD->nTileH);
TIFFSetField(m_pD->pfFile, TIFFTAG_SUBFILETYPE, FILETYPE_REDUCEDIMAGE);
TIFFSetField(m_pD->pfFile, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(m_pD->pfFile, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(m_pD->pfFile, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(m_pD->pfFile, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);
TIFFSetField(m_pD->pfFile, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
/*int nJpegQuality = 60;
TIFFSetField(m_pD->pfFile, TIFFTAG_JPEGQUALITY, nJpegQuality);*/
if (nLayer == 0)
{
float fPixelSize = 0.0f;
int nScale = 0;
GetScanScale(nScale);
GetPixelSize(fPixelSize);
fPixelSize = fPixelSize * 100 / max(1, nScale);
TIFFSetField(m_pD->pfFile, TIFFTAG_XRESOLUTION, 1.0 / (fPixelSize / 10));
TIFFSetField(m_pD->pfFile, TIFFTAG_YRESOLUTION, 1.0 / (fPixelSize / 10));
TIFFSetField(m_pD->pfFile, TIFFTAG_RESOLUTIONUNIT, 3);
}
// save tile information
const int nTileRow = nT / m_pD->nTileH;
const int nTileCol = nL / m_pD->nTileW;
int tiffIndex = nTileRow * (stLayer.nWidth / m_pD->nTileW) + nTileCol;
TIFFWriteEncodedTile(m_pD->pfFile, tiffIndex, (void *)pucTile, m_pD->nTileW * m_pD->nTileH * 3);
TIFFWriteDirectory(m_pD->pfFile);
}