2

I have written below code to open one tiff image. Actually I am trying to use imageJ (ImagePlus) library in one of out java application. But it is giving error message.

"ImageJ cannot open TIFF files compressed in this fashion (4)"

Any help would be greatly appreciated.

package 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();
        }
    }
}
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
user3409976
  • 31
  • 1
  • 4
  • TIFF uses different compression formats, and it seems like this one uses one (maybe an "unusual" one?) that is not supported by ImageJ. If it is only about a single image, you might want to open it with any image manipulation program and save it with a different compression. If it is about multiple (many) images, you may either consider a batch conversion, or try to look for a TIFF loader that supports this particular format. – Marco13 Mar 12 '14 at 10:01

1 Answers1

2

TIFF images can be compressed in various ways. ImageJ can only open some of them (see also the source code). Try opening the file using the Bio-Formats library and its helper class BF:

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

/* ... */

ImagePlus imp = BF.openImagePlus("path/to/your/image.tiff"); 
Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51