Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

there is no such builtin operation. (opencv will rather saturate pixels for builtin additions/subtractions and such.)

so (assuming a single channel uchar image) you'll have to:

// 1. get to the pixels:
byte bytes = new bytes[img.total()];
img.get(0,0,bytes); // copy.

// 2. java's byte type is *signed*, [-127,+127]
// so you have to cast every single one to an integer, before you can do maths on it
// ex.
int A = 0x7f + (int)bytes[i]; // to [0..255] range
int B = 200; // some number from your algorithm
int C = (A + B) % 256; // here's the modulo !
byte result = (byte)(C - 0x7f); // convert back
bytes[i] = result;

// 3. write back the pixels:
img.put(0,0,bytes);

as you can see, it's all very clumsy. neither opencv, nor java are a good choice for this.