Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.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 用平行对角线将矩阵分块_Java_Image_Image Processing - Fatal编程技术网

Java 用平行对角线将矩阵分块

Java 用平行对角线将矩阵分块,java,image,image-processing,Java,Image,Image Processing,我有个问题。我想用(45和-45)度的平行对角线将图像分割成块。 你能帮我怎么追踪我的像素矩阵吗?” 我试着为这个方法写一些代码。我把一个宽度和高度相等的矩阵分成两个三角形。你知道(I,j)=(0,0)在图像矩阵的左上方,所以直到对角线是一个三角形,然后是另一个三角形。 这是我的密码 public static int[] getBlackNo_45Degree(int[][] pixels, int sectionNo){ int height = pixels.length;

我有个问题。我想用(45和-45)度的平行对角线将图像分割成块。 你能帮我怎么追踪我的像素矩阵吗?”

我试着为这个方法写一些代码。我把一个宽度和高度相等的矩阵分成两个三角形。你知道(I,j)=(0,0)在图像矩阵的左上方,所以直到对角线是一个三角形,然后是另一个三角形。 这是我的密码

public static int[] getBlackNo_45Degree(int[][] pixels, int sectionNo){
        int height = pixels.length;
        int width = pixels[0].length;
        System.out.println(width +" - " +height);
        int [] blackNo_Diagonal = new int[sectionNo];
        int section = (height / sectionNo )* 2;
        int temp =0, index = section, blackNo = 0, arrayIn =0;

        for(int count= 0 ; count<sectionNo/2 ; count++){
            blackNo = 0;
            for(int row = temp; row< index ; row++ ){
                int rowIndex = row ;
                for(int col= 0 ; col <= row ; col++){
            //      System.out.println("row-col :"+rowIndex +"-"+col);
                    int rgb = pixels[rowIndex --][col];

                    if(rgb == Color.BLACK.getRGB())
                        blackNo ++;

                }
            }
            blackNo_Diagonal[arrayIn++]= blackNo;
            temp += section;
            index += section;
            System.out.println(blackNo);
        }
        temp = 0;
        index = section;
        for(int count= 0 ; count<sectionNo  /2 ; count++){
            blackNo = 0;
            for(int col= temp +1 ; col <= index  ; col++){
                int colIndex = col;
                for(int row= (height -1) ; colIndex < width ; row--){
                //System.out.println("row-col :"+row +"-"+colIndex);
                    int rgb = pixels[row][colIndex++];
                    if(rgb == Color.BLACK.getRGB())
                        blackNo ++;


                } 
            }
            blackNo_Diagonal[arrayIn++]= blackNo;
            temp += section;
            index += section;
            System.out.println(blackNo);
        }
        return  blackNo_Diagonal;
    }
输出:

row-col :0-0
row-col :1-0
row-col :0-1
3
row-col :2-0
row-col :1-1
row-col :0-2
row-col :3-0
row-col :2-1
row-col :1-2
row-col :0-3
4
row-col :3-1
row-col :2-2
row-col :1-3
row-col :3-2
row-col :2-3
2
row-col :3-3
1

“您能帮助我如何跟踪像素矩阵吗?”为了更快地获得更好的帮助,请发布您的尝试(图像的热链接)。我编辑了我的问题,请重新阅读。“您能帮助我如何跟踪像素矩阵吗?”为了更快地获得更好的帮助,请发布您的尝试(图像的热链接)。我编辑了我的问题,请重新阅读。
row-col :0-0
row-col :1-0
row-col :0-1
3
row-col :2-0
row-col :1-1
row-col :0-2
row-col :3-0
row-col :2-1
row-col :1-2
row-col :0-3
4
row-col :3-1
row-col :2-2
row-col :1-3
row-col :3-2
row-col :2-3
2
row-col :3-3
1