2012-02-07 6 views
1

im ImageJライブラリを使用して.tiffイメージファイルを読み取ります。しかし、変数Cのimage1のピクセルを読み込もうとすると、「互換性のない型:必須int、見つかったint []」というエラーが発生します。 imは静かでJavaに新しいので、この問題を回避する方法を教えてください。コードは、そうでない場合は、他の画像フォーマットで正常に動作しているimageJライブラリを使用して.tiffイメージのピクセルをスキャンする

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.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("E:\\abc.tiff"); 

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

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

        int c = img.getPixel(x,y); 
        Color color = new Color(c); 


        if (color.getRed() < 30 && color.getGreen() >= 225 && color.getBlue() >= 225) { 
         out.write("CyanPixel found at=" + x + "," + y); 
         out.newLine(); 

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

答えて

1

あなたはdocumentation for getPixel(int,int) in ImagePlusあなたはそれがなく、1つintよりintの配列を返すことがわかります見れば:。

返し

(x、y)のピクセル値を4要素配列として返します。最初の要素ではグレースケール値が再調整され、RGB値は最初の3要素。インデックス付きカラー画像の場合、RGB値は最初の3つの3要素に返され、インデックス(0〜255)は最後に返されます。

あなたはRGB画像を扱っているかのように見えますので、あなたの代わりに次の操作を行うことができるはずです..これは働いていた罰金:)

int [] colorArray = image1.getPixel(x,y); 

int redValue = colorArray[0]; 
int greenValue = colorArray[1]; 
int blueValue = colorArray[2]; 
+0

おかげで –

関連する問題