Go Down

Topic: translating shifts from Java (Processing) to C++ (arduino) (Read 2 times) previous topic - next topic

robtillaart

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Quote
have to tune it as it is too dark, even with the most correct translation function you provided

the reason is that the values of R, G, and B are not 0..255 which is assumed in the gray formulas.

Code: [Select]

int r = (lsb >> 3) & 0x1F;
int g = ((lsb & 0x07) << 3) | ((msb >> 5) & 0x07) ;
int b = (msb & 0x1f);

r = r << 3;  // as r is only 5 bit we must shift it to the left 3 positions
g = g << 2; // g has 6 bits
b = b << 3;  // ....

and now gray = (r + g + b )/3; or the more sophisticated formulas.

// and for some fun you could add some noise which will have a smoothing effect.

r = r << 3 + random(8); // fills up the 3 zero bits with some noise
g = g << 2 + random(4);
b = b << 3 + random(8);



Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

@Robert
1) if this work is done you should post a link to the HarcoCam group so others may use it to.
2) the work is only really done if you make a separate command for downloading grayscale pictures that exists besides the rgb pictures.
    we now patched the dl command maybe create a dg (download gray) command?


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robvoi

#8
Jan 08, 2013, 09:00 am Last Edit: Jan 08, 2013, 01:47 pm by robvoi Reason: 1
Hi robtillaart,

1) I am already in contact with them. They got the link to the discussions right when I created them. So far there is little response. But their website states that they are on vacation until the 13th.
2) Updating the library and the Hub sketch was the plan anyway. I will try another thing (see 3) and than start cleaning up the code and do the library/sketch updating. Maybe the hacrocam guys want to kick in once they are back. :-) Otehrwise I'll provide them the updated code. Gettingthe serial transmition times of the cam down will extend the pissiblities for robotics use (where I want to use it for). This together with the low price tag ... I hope more people will buy the cam and a comunity starts to build up.
3) Once the grayscale bought down the transmition time for the picture to half of the rgb time, I will now try to go to 4 bit grayscale. Should reduce it again by 50%. First step is to dig into the bit shifting and masking thing to combine the two times four bit to one byte.
4) With the alpha correction code you provided....
Code: [Select]
r = r << 3;  // as r is only 5 bit we must shift it to the left 3 positions
g = g << 2; // g has 6 bits
b = b << 3;  // ....

.... I get an image with many black arreas (I think in the most bright areas of the picture). Using the bit shift here and take only green as gray, I get a nearly complete black picture.

Shifting one bit less ...
Code: [Select]
r = r << 2;
g = g << 1;
b = b << 2;

... gives a brighter image without the black areas.


BTW. I am surprised how well only taking the green chanel works. Almost no visible difference to the calculated values.

Thanks
Robert

robtillaart

1) OK
2) OK
3) OK, had the same idea see other thread => you will get colour banding
4)
Quote
I get an image with many black areas

As I have no HW to check things some advices are just based upon the code ;)

Quote
I am surprised how well only taking the green chanel works. Almost no visible difference to the calculated values.

In the formulas green is ~60% of the info. that's why. 

Q: Is it possible to post images ? RGB / gray (printscreen)



Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up