java - ImageJ 库无法打开 tiff 图像

标签 java tiff imagej

我编写了下面的代码来打开一张 tiff 图像。实际上我正在尝试在一个java应用程序中使用imageJ(ImagePlus)库。但它给出了错误消息。

“ImageJ 无法打开以这种方式压缩的 TIFF 文件 (4)”

任何帮助将不胜感激。

com.csc 包

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.imageio.*;
//import javax.imageio.ImageIO;
import ij.ImagePlus;

public class GetPixelCoordinates {

//int y, x, tofind, col;
/**
 * @param args the command line arguments
 * @throws IOException  
 */
    public static void main(String args[]) throws IOException {
        try {
            //read image file

            ImagePlus img = new ImagePlus("C:\\javaCode\\TestIJ\\check_1.tiff");

            //write file
            FileWriter fstream = new FileWriter("C:\\javaCode\\TestIJ\\log.txt");
            BufferedWriter out = new BufferedWriter(fstream);

            //find cyan pixels
            for (int y = 0; y < img.getHeight(); y++) {
                for (int x = 0; x < img.getWidth(); x++) {

                    int c[] = img.getPixel(x,y);

                  //  Color color = new Color()
                    int redValue = c[0];
                    int greenValue = c[1];
                    int blueValue = c[2];


                     if (redValue < 30 &&greenValue >= 225 && blueValue >= 225) {
                         out.write("CyanPixel found at=" + x + "," + y);
                         out.newLine();

                     }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

最佳答案

TIFF 图像可以是 compressed in various ways 。 ImageJ只能打开some of them (另请参阅 source code )。尝试使用 Bio-Formats library 打开文件及其辅助类 BF :

import ij.ImagePlus;
import loci.plugins.BF;

/* ... */

ImagePlus imp = BF.openImagePlus("path/to/your/image.tiff"); 

关于java - ImageJ 库无法打开 tiff 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22347636/

相关文章:

java - ImageJ 叠加 ROI 缩放

image - 查找嘈杂图像中的点数

java - Netty 简单 channel 处理程序断开连接被阻止

java - Java 中的 AWS DynamoDbMapper FilterExpression 分页

pdf - Ghostscript:如何决定将多页 PDF 转换为多个 TIFF 的输出分辨率

java - 如何在Java中将TIFF转换为JPEG/PNG

java - 用破折号替换前导零直到小数点

java - 选择选项后无法创建输入文本框

python - 将 Excel 转换为 TIFF 文件

javascript - ImageJ 宏路径问题