压缩 TIF 文件
我正在尝试将多页彩色 tiff 文件转换为 C# 中的 ac# CompressionCCITT3 tiff。 我意识到我需要确保所有像素都是 1 位。 我在网上没有找到有用的例子。
I'm trying to convert a multipage color tiff file to a c# CompressionCCITT3 tiff in C#. I realize that I need to make sure that all pixels are 1 bit. I have not found a useful example of this online.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议在深入编码之前首先使用 tiff 和图像实用程序尝试所需的结果。 我发现 VIPS 是一个方便的工具。 下一个选择是研究 LibTIFF 可以做什么。 我使用 C# 使用免费的 LibTiff.NET 取得了良好的效果(另请参阅 stackoverflow)。 我对 GDI tiff 功能感到非常失望,尽管您的情况可能会有所不同(我需要缺少的 16 位灰度)。
您还可以使用 LibTiff 实用程序(即参见 LibTiff 实用程序)。 org/man/tiffcp.1.html" rel="nofollow noreferrer">http://www.libtiff.org/man/tiffcp.1.html)
I suggest to experiment with the desired results first using tiff and image utilities before diving into the coding. I found VIPS to be a handy tool. The next option is to look into what LibTIFF can do. I've had good results with the free LibTiff.NET using c# (see also stackoverflow). I was very disappointed by the GDI tiff functionality, although your milage may vary (I need the missing 16-bit-grayscale).
Also you can use the LibTiff utilities (i.e. see http://www.libtiff.org/man/tiffcp.1.html)
拉皮条免责声明:我在 Atalasoft 工作,这是一家生产 .NET 成像软件的公司。
使用 dotImage,此任务变得如下所示:
Bob Powell 示例就其本身而言,它很好,但它有很多问题,其中最重要的是它使用了一个简单的阈值,如果您想要速度并且实际上并不关心您的输出是什么样子或您的结果,那么这是非常棒的输入域实际上已经几乎是黑白的——只是用颜色表示。 二值化是一个棘手的问题。 当你的任务是将可用信息减少 1/24 时,如何保留正确的信息并丢弃其余的信息是一个挑战。 DotImage 有六种不同的二值化工具 (IIRC)。 从我的角度来看,SimpleThreshold 是最底层的。
Pimping disclaimer: I work for Atalasoft, a company that makes .NET imaging software.
Using dotImage, this task becomes something like this:
The Bob Powell example is good, as far as it goes, but it has a number of problems, not the least of which is that it's using a simple threshold, which is terrific if you want speed and don't actually care what your output looks like or your input domain is such that really is pretty much black and white already - just represented in color. Binarization is a tricky problem. When your task is to reduce available information by 1/24th, how to keep the right information and throw away the rest is a challenge. DotImage has six different tools (IIRC) for binarization. SimpleThreshold is bottom of the barrel, from my point of view.
我看到上面的代码,看起来它正在用手动逻辑转换每个像素。
这对你有用吗?
Imports System.Drawing.Imaging
'获取颜色 tif 文件
Dim bmpColorTIF As New Bitmap("C:\color.tif")
'选择 tif 的一个区域(将抓取所有帧)
Dim rectColorTIF As New Rectangle(0, 0 , bmpColorTIF.Width, bmpColorTIF.Height )
'将矩形克隆为 1 位颜色 tif
Dim bmpBlackWhiteTIF As Bitmap = bmpColorTIF.Clone(rectColorTIF, PixelFormat.Format1bppIndexed)
'使用新位图执行您想要的操作(保存等)
..注意
:有大量的像素格式可供选择。
I saw the above code, and it looked like it was converting every pixel with manual logic.
Would this work for you?
Imports System.Drawing.Imaging
'get the color tif file
Dim bmpColorTIF As New Bitmap("C:\color.tif")
'select the an area of the tif (will grab all frames)
Dim rectColorTIF As New Rectangle(0, 0, bmpColorTIF.Width, bmpColorTIF.Height )
'clone the rectangle as 1-bit color tif
Dim bmpBlackWhiteTIF As Bitmap = bmpColorTIF.Clone(rectColorTIF, PixelFormat.Format1bppIndexed)
'do what you want with the new bitmap (save, etc)
...
Note: there are a ton of pixelformats to choose from.
您需要进行此转换,因为 CCITT3 和 CCITT4 不支持颜色(如果我没记错的话)。
You need this conversion as CCITT3 and CCITT4 don't support color (if I remember right).