我写了下面的代码来打开一个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();
}
}
}
答案 0 :(得分:2)
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");