2014-03-12 165 views
2

我已经编写了下面的代码来打开一个tiff图像。其实我试图在java应用程序中使用imageJ(ImagePlus)库。但它给错误信息。ImageJ库无法打开tiff图像

“的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(); 
     } 
    } 
} 
+0

TIFF使用不同的压缩格式,它似乎像这样使用一个(也许是“不寻常”的一个?)不是由ImageJ的支持。如果只是一张图像,您可能想要用任何图像处理程序打开它,并用不同的压缩方式保存。如果是关于多个(许多)图像,则可以考虑批量转换,或尝试查找支持此特定格式的TIFF加载程序。 – Marco13

回答