I have 256 binary matrices B(x,y) and I try to pool them in the group of 8 matrices. Considering a single pixel at a particular position (x,y), a set of binary values from matrices in the pool consisting of 8 matrices can be used to construct a binary code of 8 bits. The following formula illustrates that : see the formula
The pool of 256 matrices in the group of 8 matrices will result in 32 matrices. I wrote the code in java and the code run properly, but I want to reduce the time complexity, where it takes about 30 seconds to get the result! The size of each matrix is 300 X 100,what I can change or use to get the same result with much less time??
//index-Strat
int start = 0;
//index-end
int end = 7;
//pool evey eghit matrices togather, and produces 32 matrices
for (int j = 0; j < 32; j++)
{
//call the pooling function
Mat bit - 8 = new Mat();
bit - 8 = pool(start, end);
//add 8-bit matrix to pool array
p.add(bit - 8);
//increamt the indexs to pool the next 8 matrix
start = end + 1;
end = start + 7;
}
//---------------------------
Mat pool(int s, int e)
{
Mat bit - 8 = new Mat(binary.get(0).size(), binary.get(0).type());
//apply the Bit Plane
for (int i = 0; i < bit - 8. rows(); i++)
{
for (int j = 0; j < bit - 8. cols(); j++)
{
double[] sum = new double[1];
for (int k = 0; k < 8; k++)
{
double[] v = new double[1];
v = binary.get(s + k).get(i, j);
double new_value = v[0] * Math.pow(2, k);
sum[0] = sum[0] + new_value;
}
bit - 8. put(i, j, sum);
}
return bit - 8
}