Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

please avoid to useget() or set() on a per-pixel basis in general (far too slow.) instead:

// get *all* pixels  at once:
float [] pixels = new float[w*h];
mapx.get(0,0, pixels);
// manipulate pixels:
pixel[y*w+x] = 17;
// write them back:
mapx.put(0,0, pixels);

if using java, please avoid to useget() or set() on a per-pixel basis in general (far too slow.) instead:

// get *all* pixels  at once:
float [] pixels = new float[w*h];
mapx.get(0,0, pixels);
// manipulate pixels:
pixel[y*w+x] = 17;
// write them back:
mapx.put(0,0, pixels);

if using java, please avoid to useget() or set() on a per-pixel basis in general (far too slow.) instead:

// get *all* pixels  at once:
float [] pixels = new float[w*h];
mapx.get(0,0, pixels);
// manipulate pixels:
pixel[y*w+x] pixels[y*w+x] = 17;
// write them back:
mapx.put(0,0, pixels);

if using java, please avoid to useget() or set() on a per-pixel basis in general (far too slow.) instead:

// get *all* pixels  at once:
float [] pixels = new float[w*h];
mapx.get(0,0, pixels);
// manipulate pixels:
pixels[y*w+x] = 17;
// write them back:
mapx.put(0,0, pixels);

[edit]

(it seems, you misunderstood the all pixels part):

int rows = inMat.rows();
int cols = inMat.cols();

float[] pixelsX = new float[rows * cols];
float[] pixelsY = new float[rows * cols];
for (int j = 0; j < rows; j++) {
  for (int i = 0; i < cols; i++) {
        if (i > cols * 0.25 && i < cols * 0.75 && j > rows * 0.25 && j < rows * 0.75) {
          pixelsX[j * cols + i] = (float) (2 * (i - cols * 0.25) + 0.5);
          pixelsY[j * cols + i] = (float) (2 * (i - rows * 0.25) + 0.5);
        }
        // hmm, how does java handle uninitialized memory here ?
        // you might need an "else" clause, since above code leaves "holes" in the map.
   }
}

Mat mapX = new Mat(rows, cols, CvType.CV_32FC1);
Mat mapY = new Mat(rows, cols, CvType.CV_32FC1);
mapX.put(0,0, pixelsX);
mapY.put(0,0, pixelsY);

if using java, please avoid to useget() or set() on a per-pixel basis in general (far too slow.) instead:

// get *all* pixels  at once:
float [] pixels = new float[w*h];
mapx.get(0,0, pixels);
// manipulate pixels:
pixels[y*w+x] = 17;
// write them back:
mapx.put(0,0, pixels);

[edit]

(it seems, you misunderstood i was not clear enough about the all pixels part):

int rows = inMat.rows();
int cols = inMat.cols();

float[] pixelsX = new float[rows * cols];
float[] pixelsY = new float[rows * cols];
for (int j = 0; j < rows; j++) {
  for (int i = 0; i < cols; i++) {
        if (i > cols * 0.25 && i < cols * 0.75 && j > rows * 0.25 && j < rows * 0.75) {
          pixelsX[j * cols + i] = (float) (2 * (i - cols * 0.25) + 0.5);
          pixelsY[j * cols + i] = (float) (2 * (i - rows * 0.25) + 0.5);
        }
        // hmm, how does java handle uninitialized memory here ?
        // you might need an "else" clause, since above code leaves "holes" in the map.
   }
}

Mat mapX = new Mat(rows, cols, CvType.CV_32FC1);
Mat mapY = new Mat(rows, cols, CvType.CV_32FC1);
mapX.put(0,0, pixelsX);
mapY.put(0,0, pixelsY);