【TIFF】五. 几点TIFF的说明

目录

 

一:TIFF读图工具

二: TIFF 格式限制

三:存储tile 图像


一: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);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值