Ask Your Question
-1

how to get Mod 256 of image using opencv in java

asked 2018-06-24 07:33:54 -0600

vishalsira gravatar image

I am completely new user about opencv can anyone please suggest me how to take mod 256 of image using opencv in java

edit retag flag offensive close merge delete

Comments

what are you trying to achieve ? what do you need it for ?

berak gravatar imageberak ( 2018-06-24 08:32:47 -0600 )edit

i'm trying to encrypt image using some specific algorithm so i need to find out mod 256 of image

vishalsira gravatar imagevishalsira ( 2018-06-24 08:37:19 -0600 )edit

are you sure, that opencv is the right library for you ?

and it's still unclear, what exactly you're trying to do. do you have a formula, or similar ?

berak gravatar imageberak ( 2018-06-24 08:38:53 -0600 )edit

yes, i think opencv is more better for me

vishalsira gravatar imagevishalsira ( 2018-06-24 08:42:14 -0600 )edit

again, please try to explain what your assigment is about in more detail, else we cannot help you.

( mod 256 of image ) on it's own does not make any sense.

berak gravatar imageberak ( 2018-06-24 08:46:17 -0600 )edit

i want to generate shares of image using additive modulo

vishalsira gravatar imagevishalsira ( 2018-06-24 09:21:53 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-06-24 09:25:28 -0600

berak gravatar image

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.

edit flag offensive delete link more

Comments

why you declare variable B ?

vishalsira gravatar imagevishalsira ( 2018-06-24 13:15:22 -0600 )edit

i'm just guessing that. again,you failed to tell us, where that would be coming from

berak gravatar imageberak ( 2018-06-24 13:17:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-24 07:33:54 -0600

Seen: 336 times

Last updated: Jun 24 '18