java常用的几个图片处理工具对Tiff文件的支持

ImageMagick

官网 https://imagemagick.org/, 支持多种格式。命令行工具很适合调试。功能很强大. 还有一款工具GraphicsMagick 是从ImageMagick的基础上研发出来的。

OpenCV

官网 https://opencv.org/ , github地址https://github.com/opencv/opencv,非常活跃的一个开源工具,原来免费的教程,现在已经开始包装成视频,进行收费了,我买了教程,看了下,和以前官网看过的文字版教程没多大差别。github关注已经达到了72.3k。

ImageJ

官网 https://imagej.net/ij/

ImageJ is open source software for processing and analyzing scientific images.

基于ImageJ已经又研发了ImageJ2(目前github关注量1k)和Fiji的产品。

java 复制代码
// Open the TIFF image
ImagePlus imagePlus = new ImagePlus(f);

// Get the image processor
ImageProcessor imageProcessor = imagePlus.getProcessor();

// Add text to the image
int x = 0; // X-coordinate of text
int y = 0; // Y-coordinate of text

String   textToAdd = "These three lines of\ntext will be overlayed on\nthe current image";

Font font = new Font("SansSerif", Font.PLAIN, 56);
imageProcessor.setFont(font);
imageProcessor.setColor(Color.RED);
imageProcessor.drawString(textToAdd, x, y); // Draw the text

// Display the modified image (optional)
//        imagePlus.show();

// Save the modified image
ImagePlus outputImage = new ImagePlus("Modified Image", imageProcessor);
IJ.saveAs(outputImage,"jpeg", f31);
IJ.saveAsTiff(outputImage, f41);
final ImagePlus imagePlus1 = IJ.openImage(f41);
IJ.save(imagePlus1, fpng);

commons-imaging

Apache维护的产品,目前github关注量381

java 复制代码
final File file = new File(f);
final BufferedImage overlay = Imaging.getBufferedImage(file);
// Add text to the image
int x = 0; // X-coordinate of text
int y = 0; // Y-coordinate of text

Font font = new Font("SansSerif", Font.PLAIN, 56);
String   textToAdd = "These three lines of\ntext will be overlayed on\nthe current image";
addTextToImage(overlay, textToAdd, x, y, Color.RED, font);

ImageIO.write(overlay, "JPEG", new File(fa1));
//        ImageIO.write(overlay, "TIFF", new File(fa2));
saveImageWithText(overlay, fa2);
Imaging.writeImage(overlay, Files.newOutputStream(Paths.get(fa4png)), ImageFormats.PNG);
java 复制代码
    // Method to add text to the image
    private static void addTextToImage(BufferedImage image, String text, int x, int y, Color color, Font font) {
        Graphics2D g2d = image.createGraphics();
        g2d.setColor(color);
        g2d.setFont(font);
//        g2d.drawString(text, x, y);
        drawString(g2d, text, x, y);
        g2d.dispose();
    }
   private static void drawString(Graphics g, String text, int x, int y) {
        for (String line : text.split("\n"))
            g.drawString(line, x, y += g.getFontMetrics().getHeight());
    }

//    // Method to save the modified image with text using Common Imaging
    private static void saveImageWithText(BufferedImage image, String outputPath) throws IOException, ImageWriteException {
        // Create a new instance of ImageWriteParam for TIFF format
        final TiffImagingParameters params = new TiffImagingParameters();
        params.setCompression(TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED);

        // Write the BufferedImage with text to a TIFF file
//        Imaging.writeImage(image, new File(outputPath), ImageFormat.IMAGE_FORMAT_TIFF, params);
         new TiffImageParser().writeImage(image, Files.newOutputStream(Paths.get(outputPath)), params);
    }

TwelveMonkeys

目前github关注量1.7k

JDeli 是一个付费软件

如下是测试结果

photoshop可以看到通道增加了专色通道。

ImageMagick opencv imagej commons-imaging TwelveMonkeys JDeli(付费软件)
带有2 个专色通道的tiff图片 不支持 不支持 支持 支持 不支持 支持
将文字写入到图片中 / / 支持 支持
文字写入保存为jpg格式 / / 写入红色的字体变成了黑红 写入红色的字体变成了黑红
文字写入保存为tiff格式 / / 写入红色的字体正常 写入红色的字体正常 写入红色的字体正常
支持Tiff 格式alpha通道 / / 不支持 不支持 不支持 不支持
相关推荐
shoufeipin90hou2 小时前
光选机的“除尘与风选“配套边界:分选精度上不去,可能问题不在相机
数码相机·计算机视觉
tuanxiang4 小时前
实现文本AI检测免费自建方案,绕开接口调用收费坑
人工智能·计算机视觉
原子延迟4 小时前
红色的字压成JPEG就发糊,查到最后是色度抽样
图像处理·人工智能·计算机视觉
`流年づ6 小时前
卷积核与反卷积知识补充
人工智能·深度学习·计算机视觉
YOLO_DATA6 小时前
YOLO27防震锤缺陷检测数据集 防震锤数据集 1000张 防震锤 带标注 voc yolo 2 类 目标检测
人工智能·深度学习·yolo·目标检测·计算机视觉·数据集·无人机
I Am a robert girl7 小时前
从一张图到碎裂瞬间:FracGen 如何用物理信号“导演“物体撕裂
人工智能·深度学习·计算机视觉·生成模型·视频生成·物理仿真·断裂模拟
pride.li9 小时前
ISP标定-AWB标定(Auto White Balance,自动白平衡校准)
图像处理·计算机视觉·isp
小蒋观天下1 天前
两轮车检测AI摄像头:场景分化下的行业竞争与卡位机遇
人工智能·安全·计算机视觉·语音识别·ai大模型
YOLO数据集集合1 天前
电力设备目标检测数据集 | 电力设备 变电站巡检 部件识别 目标检测 YOLO格式 9127期
人工智能·yolo·目标检测·计算机视觉·目标跟踪·电力设备
硅谷秋水1 天前
WLA³:面向语义、动力学与运动学的世界潜动作建模
人工智能·机器学习·计算机视觉·语言模型·机器人