私はヒストグラム均等化メソッドをビジネスにしています。私はthis questionを基礎として構築しました。しかし、私はこのコードを実行することはできませんし、Googleは私が問題を見つける手助けにあまり役に立たない。私はJPG BufferedImageオブジェクトを渡します。私は最初に画像を表示して、私が作業しているものを見てから処理します。しかし、それは常に行int valueBefore=img.getRaster().getPixel(x, y,iarray)[0];
で失敗し、私はなぜわからない。私が得るエラーはException in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
ですが、私はが表示されませんなぜこのエラーが出て、画像があり、ピクセルで満たされています!Javaヒストグラム均等化 - イメージラスタからピクセルを取得できません
public BufferedImage hisrogramNormatlisation(BufferedImage img) {
// To view image we're working on
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JLabel(new ImageIcon(img)));
frame.pack();
frame.setVisible(true);
int width =img.getWidth();
int height =img.getHeight();
int anzpixel= width*height;
int[] histogram = new int[255];
int[] iarray = new int[1];
int i =0;
// Create histogram
for (int x = 50; x < width; x++) {
for (int y = 50; y < height; y++) {
int valueBefore=img.getRaster().getPixel(x, y,iarray)[0];
histogram[valueBefore]++;
System.out.println("here");
}
}
int sum = 0;
float[] lut = new float[anzpixel];
for (i=0; i < 255; ++i)
{
sum += histogram[i];
lut[i] = sum * 255/anzpixel;
}
i=0;
for (int x = 1; x < width; x++) {
for (int y = 1; y < height; y++) {
int valueBefore=img.getRaster().getPixel(x, y,iarray)[0];
int valueAfter= (int) lut[valueBefore];
iarray[0]=valueAfter;
img.getRaster().setPixel(x, y, iarray);
i=i+1;
}
}
return img;
}
エラーの説明:あなたが投稿
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at java.awt.image.ComponentSampleModel.getPixel(ComponentSampleModel.java:n)
at java.awt.image.Raster.getPixel(Raster.java:n)
at MainApp.hisrogramNormatlisation(MainApp.java: * line described *)
at MainApp.picture(MainApp.java:n)
at MainApp.<init>(Main.java:n)
at MainApp.main(Main.java:n)