Advertisement Jump to content
Sign in to follow this  

Bitmap graphics pixels scanning

This topic is 1418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



I have a simple algorithm in mind for this game:- activate "x" animation or gameplay when letter "y" is recognised by the scanning phone camera image (all done in code)

So what you play varies and depends on what letter the camera scans. This sort of thing (in different forms) is common in augmented reality games 


But my first step to doing this ran into a problem that i can't explain 


To start with, i started with a simple enough test algorithm:


 scan Bitmap pixel by pixel (image of A4 paper - which has pen marks on it),

 if a pixel's color is black paint it red otherwise put white colour on the pixel


My cut-off for black is flexible and changeable. I experimented a lot 

I came up with a form of grey :  int colorConst2  = ((Color.GRAY +  Color.GRAY +  Color.GRAY + Color.GRAY)/4)  +  700000;


This is so that a dim lighting or mild shadows don't get translated as a black


But whatever the cut-off  i choose there are lots of pixels on the outer edges that get coloured red (for black pixels) even though they are white (see images)

If i lower the cut-off so those rouge pixels don't get picked up, then some of the real black marks on the inside begin to fade off (not picked as black)


While human still recognised the letters, the rouge pixels messes up the program's letter recognition algorithm for variable animation and gameplay


Initially I thought it was the phone camera settings, after trying all settings available, i came to the conclusions it is a graphics algorithm issue

Probably something i need to take into account while checking the pixels


I am mystified, hoping someone knows what it is


Share this post

Link to post
Share on other sites

dammit, wrote you a long reply and accidentally closed the tab and lost it :(


in summary you made a good start but with a flawed approach, hard coded values won't work well given the unpredictability of the users lighting conditions.


You are better of using a edge/feature detection type solution. The idea being to compare each pixel against its surroundings and extract its contrast from that.

i.e sample some neighbouring pixels and compare luminance against those.


Take a look at some common convolution filters for some ideas.

Here is an example I made where I run them on the gpu:

Share this post

Link to post
Share on other sites

Thanks for the hint.


I have been looking at the link, and how to use AGAL helper library and the learning curve seem huge


I know you mention AGAL.convolve(output, sample, texture, uv, offset, matrix)+ 


but struggling to see how to use it to achieve the aim directly. 


Obviously you used in C++, Can it the library be used in Java environment?


Share this post

Link to post
Share on other sites

Ah it was more for an example of the result not really the implementation, there is much more going on there than you need to be interested in.

Take a look here:

or here:

and choose the convolution filter and plug in the numbers from the first link

or here for some code in js you can easily port to java:

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!