Ask Your Question
0

Are there any inbuild function similar to bitrevorder in opencv?

asked 2018-04-26 04:30:53 -0600

Ann162 gravatar image

updated 2018-04-26 09:15:45 -0600

berak gravatar image

I want to reverse the bits of grayscale images using opencv,is there any inbuilt function which can be used

edit retag flag offensive close merge delete

Comments

no, there isn't. what exactly would you need it for ?

do you really want to reverse the order of bits, or their value ?

berak gravatar imageberak ( 2018-04-26 05:06:53 -0600 )edit
1

i wish to reverse the bits of all the pixels of the image.for eg if the pixel value is 14 then then its binary would be 00001110 ,the reverse of this would be 01110000 .So for every pixel this function should be performed .

Ann162 gravatar imageAnn162 ( 2018-04-26 05:20:16 -0600 )edit

so again, opencv does not have it.

what would be the context of that operation ? what would it be useful for ? (noone else needed this before)

berak gravatar imageberak ( 2018-04-26 05:24:05 -0600 )edit
1

i am trying to encrypt an image and it is the part of an algorithm that i am using.

Ann162 gravatar imageAnn162 ( 2018-04-26 05:28:16 -0600 )edit

hmmm, opencv might not be the best library, and java not the best language for this.

you'll have to roll your own algorithm here, sorry.

berak gravatar imageberak ( 2018-04-26 05:38:26 -0600 )edit

ok will look into it thank you.

Ann162 gravatar imageAnn162 ( 2018-04-26 05:43:13 -0600 )edit

oh, wait, you could build a lookup table and use LUT

berak gravatar imageberak ( 2018-04-26 05:48:20 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-04-26 09:06:52 -0600

berak gravatar image

it isn't straightforward, but you could use a lookup table, generated like this:

for (unsigned n = 0; n<256; n++) {
    unsigned n2=0;
    for (int i=0; i<8; i++) {
        unsigned b = ((n >>(i)&1)>0);  
        n2 |= b<<(7-i);
    }
    cout << int((char)(n2))<< ",";
    if (n%16==15) cout << endl;
}

and use that later, in your java code:

byte [] rev = { // jikes, java's bytes are *signed*
    0,-128,64,-64,32,-96,96,-32,16,-112,80,-48,48,-80,112,-16,
    8,-120,72,-56,40,-88,104,-24,24,-104,88,-40,56,-72,120,-8,
    4,-124,68,-60,36,-92,100,-28,20,-108,84,-44,52,-76,116,-12,
    12,-116,76,-52,44,-84,108,-20,28,-100,92,-36,60,-68,124,-4,
    2,-126,66,-62,34,-94,98,-30,18,-110,82,-46,50,-78,114,-14,
    10,-118,74,-54,42,-86,106,-22,26,-102,90,-38,58,-70,122,-6,
    6,-122,70,-58,38,-90,102,-26,22,-106,86,-42,54,-74,118,-10,
    14,-114,78,-50,46,-82,110,-18,30,-98,94,-34,62,-66,126,-2,
    1,-127,65,-63,33,-95,97,-31,17,-111,81,-47,49,-79,113,-15,
    9,-119,73,-55,41,-87,105,-23,25,-103,89,-39,57,-71,121,-7,
    5,-123,69,-59,37,-91,101,-27,21,-107,85,-43,53,-75,117,-11,
    13,-115,77,-51,45,-83,109,-19,29,-99,93,-35,61,-67,125,-3,
    3,-125,67,-61,35,-93,99,-29,19,-109,83,-45,51,-77,115,-13,
    11,-117,75,-53,43,-85,107,-21,27,-101,91,-37,59,-69,123,-5,
    7,-121,71,-57,39,-89,103,-25,23,-105,87,-41,55,-73,119,-9,
    15,-113,79,-49,47,-81,111,-17,31,-97,95,-33,63,-65,127,-1
};

Mat lut = new Mat(1,256, CvType.CV_8U);
lut.put(0,0,rev);

Mat dst = new Mat();
Core.LUT(src, lut, dst);
edit flag offensive delete link more

Comments

1

thank you working as required

Ann162 gravatar imageAnn162 ( 2018-04-26 09:44:08 -0600 )edit

yea, also had fun doing that ;)

berak gravatar imageberak ( 2018-04-26 09:45:27 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-04-26 04:30:53 -0600

Seen: 134 times

Last updated: Apr 26 '18