Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int[] getFeature3(int[] pixels, int width, int height, int bWidth, int bHeight) {

        int[] feature = null;
        if (height % bHeight == 0 && width % bWidth == 0) {
            int numBlockH = height / bHeight;
            int numBlockW = width / bWidth;
            int totalBlocks = numBlockH * numBlockW;
            feature = new int[totalBlocks];
            for (int k = 0; k < numBlockH; k++) {
                for (int r = 0; r < numBlockW; r++) {
                    int value = 0;
                    for (int i = 0; i < bHeight; i++) {
                        for (int j = 0; j < bWidth; j++) {
                            int index = i * width + j + r * bWidth + k * width * bHeight;
                            value += pixels[index];
                        }
                    }
                    feature[k * numBlockW + r] = Math.round((float) value / (bWidth * bHeight));
                }
            }
        } else {
            System.out.println("errore");
        }

        return feature;
    }
}