我试图得到一些不同的直方图,以显示比较原始图像和卷积后的输出图像。它显示了图像和源直方图,但当我调用dst直方图时,它出错并且不显示。如果有人能帮忙,我们将不胜感激!
错误代码-
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 853
at iptoolkit.Histogram.<init>(Histogram.java:15)
at assignment2.main(assignment2.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 0
public static void main(String[] args) throws Exception
{
MainWindow mw = new MainWindow();
mw.println("Testing...");
IntImage src = new IntImage("C:\\Users\\scott_000\\Documents\\Digital Imaging\\Digital Imaging\\Images\\Baboon.bmp");
int nRows = src.getRows();
int nCols = src.getCols();
IntImage dst = new IntImage(nRows, nCols);
IntImage dst1 = new IntImage(nRows, nCols);
src.displayImage(400, 300);
int [][] mask = new int[][] { {-1, -2, -1}, {0, 0, 0}, {1, 2, 1} };
int [][] meanMask = new int[3][3];
meanMask[0][0] = 1;
meanMask[0][1] = 1;
meanMask[0][2] = 1;
meanMask[1][0] = 1;
meanMask[1][1] = 1;
meanMask[1][2] = 1;
meanMask[2][0] = 1;
meanMask[2][1] = 1;
meanMask[2][2] = 1;
int [][] mask5x5 = new int[5][5];
mask5x5[0][0] = 1;
mask5x5[0][1] = 1;
mask5x5[0][2] = 1;
mask5x5[0][3] = 1;
mask5x5[0][4] = 1;
mask5x5[1][0] = 1;
mask5x5[1][1] = 1;
mask5x5[1][2] = 1;
mask5x5[1][3] = 1;
mask5x5[1][4] = 1;
mask5x5[2][0] = 1;
mask5x5[2][1] = 1;
mask5x5[2][2] = 1;
mask5x5[2][3] = 1;
mask5x5[2][4] = 1;
mask5x5[3][0] = 1;
mask5x5[3][1] = 1;
mask5x5[3][2] = 1;
mask5x5[3][3] = 1;
mask5x5[3][4] = 1;
mask5x5[4][0] = 1;
mask5x5[4][1] = 1;
mask5x5[4][2] = 1;
mask5x5[4][3] = 1;
mask5x5[4][4] = 1;
convolve(src, mask5x5, dst);
dst.setScaling(true);
dst.displayImage();
convolve(src, meanMask, dst1);
dst1.setScaling(true);
dst1.displayImage();
Histogram h = new Histogram(src);
IntImage histImage;
histImage = h.makeImage();
histImage.displayImage();
Histogram y = new Histogram(dst1);
IntImage histImage1;
histImage1 = y.makeImage();
histImage1.displayImage();
}
static IntImage convolve(IntImage in, int[][] template, IntImage out)
{
int nRows = in.getRows();
int nCols = in.getCols();
int nMaskRows = template.length;
int nMaskCols = template[0].length;
int rBoarder = nMaskRows / 2;
int cBoarder = nMaskCols / 2;
int sum;
for (int r = 0; r < (nRows - nMaskRows + 1); r++)
{
for (int c = 0; c < (nCols - nMaskCols + 1); c++)
{
sum = 0;
for (int mr = 0; mr < nMaskRows; mr++)
{
for (int mc = 0; mc < nMaskCols; mc++)
{
sum += in.pixels[r + mr][c + mc] * template[mr][mc];
}
}
out.pixels[r + rBoarder][c + cBoarder] = sum;
}
}
return out;
}
}