【问题标题】:ImageJ library is failing to open tiff imagesImageJ 库无法打开 tiff 图像
【发布时间】:2014-03-12 09:52:00
【问题描述】:

我写了下面的代码来打开一个 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 使用不同的压缩格式,看起来这个使用了 ImageJ 不支持的一种(可能是“不寻常的”?)。如果它只是关于单个图像,您可能希望使用任何图像处理程序打开它并使用不同的压缩方式保存它。如果是多(多)张图片,可以考虑批量转换,或者尝试寻找支持这种特定格式的 TIFF 加载器。

标签: java tiff imagej


【解决方案1】:

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"); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多