使用LibTiff逐像素写入tif
Writing a tif pixel by pixel using LibTiff?
是否可以通过逐像素迭代并设置每个像素的RGB值来创建新的tif?
让我解释一下我试图做什么。我试图打开一个现有的tif,使用TIFFReadRGBAImage
读取它,取TIFFGetR
/TIFFGetG
/TIFFGetB
给出的RGB值,从255中减去它们,取这些新值,并用它们逐个写入每个像素。最后,我想以原始图像和一个新的"补充"图像结束,就像原始图像的负片一样。
有没有一种方法可以使用LibTiff做到这一点?我浏览了文档并在谷歌上搜索了一下,但我只看到了TIFFWriteScanline
的很短的例子,这些例子提供了太少的代码行/上下文/注释,以至于我不知道如何以我希望的方式实现它。
我对编程还很陌生,所以如果有人能给我指一个有大量解释性注释的完整例子,或者直接帮助我编写代码,我将不胜感激。谢谢你花时间阅读并帮助我学习。
到目前为止我所拥有的:
// Other unrelated code here...
//Invert color values and write to new image file
for (e = height - 1; e != -1; e--)
{
for (c = 0; c < width; c++)
{
red = TIFFGetR(raster[c]);
newRed = 255 - red;
green = TIFFGetG(raster[c]);
newGreen = 255 - green;
blue = TIFFGetB(raster[c]);
newBlue = 255 - blue;
// What to do next? Is this feasible?
}
}
// Other unrelated code here...
如果您需要完整的代码。
我返回并查看了我的旧代码。事实证明我没有使用libtiff。尽管如此,你还是走在了正确的轨道上。你想要这样的东西;
lineBuffer = (char *)malloc(width * 3) // 3 bytes per pixel
for all lines
{
ptr = lineBuffer
// modify your line code above so that you make a new line
for all pixels in line
{
*ptr++ = newRed;
*ptr++ = newGreen;
*ptr++ = newBlue
}
// write the line using libtiff scanline write
write a line here
}
记住要适当地设置标签。本例假设像素为3字节。TIFF还允许在每个平面中每个像素有1个字节的单独平面。
或者,您也可以将整个图像写入新的缓冲区,而不是一次写入一行。
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 尝试渲染像素坐标时,简单线条渲染失败
- 计算另一个图像像素满足条件的像素值的平均值
- 如何返回定义良好的内存部分?例如来自图像数据的像素的颜色值
- 在Qt-cpp中通过像素获取QString的子字符串
- 有效地计算像素到其对应核线的距离
- 使用LibTiff逐像素写入tif