Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java pgm图像的中值滤波_Java_Arrays_Median_Pgm - Fatal编程技术网

Java pgm图像的中值滤波

Java pgm图像的中值滤波,java,arrays,median,pgm,Java,Arrays,Median,Pgm,我必须编写一个程序,用每个像素及其8个相邻像素的中值替换每个像素。我所拥有的将被编译,但当我试图创建一个新的图像时,我得到了多个错误。谢谢你的帮助 这是stacktrace: Exception in thread "main" java.lang.ClassCastException: [I cannot be cast to java.lang.Comparable at java.util.ComparableTimSort.countRunAndMakeAscending(Compara

我必须编写一个程序,用每个像素及其8个相邻像素的中值替换每个像素。我所拥有的将被编译,但当我试图创建一个新的图像时,我得到了多个错误。谢谢你的帮助

这是stacktrace:

Exception in thread "main" java.lang.ClassCastException: [I cannot be cast to java.lang.Comparable
at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:290)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:171)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
at java.util.Arrays.sort(Arrays.java:472)
at ImageProcessing.median(ImageProcessing.java:25
这是我的代码:

public static int [] [] median(int [] [] image) {
    int height = image.length;
    int width = image[0].length;
    int [] [] result = new int [height] [width];

    for (int col = 0 ; col < image.length ; col++) {
        result[0][col] = image[0][col];
        result[height - 1][col] = image[height - 1][col];
    }

    for (int row = 0 ; row < image[0].length ; row++) {
        result[row][0] = image[row][0];
        result[row][width - 1] = image[row][width - 1];
    }

    for (int row = 1 ; row < height - 1 ; row++) {
        for (int col = 1 ; col < width - 1 ; col++) {
            Arrays.sort(image);
            result[row][col] = image[row][col] / 2;
        }
    }
    return result;
}
公共静态int[][]中值(int[][]图像){
int height=image.length;
int width=图像[0]。长度;
int[][]结果=新的int[高度][宽度];
for(int col=0;col
您遇到的错误是因为在最后一对循环中,您对
Arrays.sort(image)
的调用试图对图像的行进行排序


您需要建立一个包含九个要查看的像素值(像素本身及其八个相邻像素)的列表,而不是调用
Arrays.sort(image)
。然后对其排序,并将中值写入
result

请公布您遇到的错误。我该如何建立一个列表?我的意思是“建立一个列表”这几个字:您可以实例化一个及其值,或者实例化一个九元素
int[]
数组并填充它。这取决于你。