Automated Threshold & Edge Detection
It's a tiny bit late maybe, but here are two image processing techniques that deal with automated thresholding and edge detection that I showed in my "2d or not 2d" talk in 2007 and in "The Pixel Whisperer" in 2008.
I've had a look at my presentation demos and repackaged their code into a single class called ThresholdBitmap. This is a BitmapData class with a few extras that help you if you plan to extract blobs or edges from a camera stream or some other bitmap.
The general problem when you do camera based experiments is that you have unnown lighting conditions. Using a simple fixed threshold might work at your development machine but might fail completely on a user's computer that has a different camera model or a different backdrop.
In image processing there are several automated thresholding methods, that are supposed to help with this problem, by looking at an image's histogram and adjusting the threshold to a level that separates the foreground from the background in an optimum way: Moment-Preservation, Maximum Entropy, Discriminant and Otsu. Those are quite capable in finding the optimum threshold level if you have relatively uniform lighting over the whole scene.
As an (better) alternative I included an adaptive threshold method which is implemented in PixelBender and which works very well also with uneven lighting, especially if you try to detect QR codes or other markers.
Furthermore the class includes a very fast edge detection (based on the thresholded image) which gives you nice 1 pixel wide edges in most cases.
Here is a demo that allows you to play around (you'll need a webcam)
Sourceview and code can be found here
Credits: the demo uses the super useful Minimal Components by Keith Peters and the Hi.RES! Stats by Mr. Doob.
Posted at July 01, 2009 08:27 PM | Further reading
Thanks for the hint. Strange - I can see the google link just fine - maybe one has to be logged in. I will think of a different way to link to it.
What FLARToolKit demo are you referring to? The rectangle tracking demo I showed in my talk was my own creation and did not use any external libraries. Yes you are right, I should post that stuff as well.
Hi Mario,
this looks quite cool, and performs really nice. I did not had the time to look at the code yet, but could this be used for blob detection as well? Other blob detection methods i have seen so far are really a cpu killer..
greetz
Balazs
Indeed I have used the threshold method as a base for my "floodFill + getColorBoundsRect" blob detection method. Another one of those things I've only showed during my talks but never published here.
Hi Mario,
thanks for this great article! As you already mentioned these techniques are very important for marker detection. Saqoosha (author of FLARToolKit) also did some experimental stuff http://blog.jactionscripters.com/2009/05/18/adaptive-thresholding-experiment/ and since there are many problems with AR at low illuminated webcam images this will be a great extension to the library.
I'm blown away by this performance and the quality of the threshholding. You continue to amaze Mario.
Hi there.
I get the source code and everything works fine, except the adaptative threshold, that gives me a very different output compared to the demo in the link.
Any ideia of what could go wrong?
Thank you.
Really nice work. Congratulations.
Did you try to change the parameters? The default settings might not be the right ones for your use case.
Thank you for your fast reply.
The problem is that i can get very nice values in demo that in the link that you release, but when running in flash, i get an error with the following output :
ArgumentError: Error #2164: The Shader input src1 is missing or an unsupported type.
at flash.display::BitmapData/applyFilter()
at com.quasimondo.bitmapdata::ThresholdBitmap/render()
at MultiExhibit/render()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.quasimondo.bitmapdata::CameraBitmap/paint()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
I think that the problem is the .pbj or .pbk files formats.
I'm running it on mac. I'm giving you all this information, maybe it can help you to help me :)
Thank you.
BR,
Ok.
I found what was going on. I updated my CS4 Flash Player to the lastest version and voilá, its working with adaptative threshold.
Yeh.
BR,
Ah, great that you could find it yourself and thanks for posting the solution here!
No problem. Is the less i can do.
Can you update the source code with the blobs detection?
Ok, maybe i'm asking to much. :)
BR,
Very nice article. I thought to let you know that you website isn't getting displayed properly on opera mini browser on my pda.
I wish that increasingly number of webmasters would consider the fact that there is an ever growing number of users browsing webpages on the mobile.
cheers
Can anyone provide guidance on how to get this demo working in Flash Builder 4 beta 2? I can successfully import, compile, and run the code in Flex Builder 3 (Eclipse plug-in version), but when I follow the same steps in Flash Builder 4 (Eclipse plug-in version) I get runtime errors telling me it can't find built-in player classes like flash.filters::ShaderFilter. My project is pointing to a valid FP 10 playerglobal.swc so I'm stumped.
Found my answer...changing the project's "Flex SDK version" setting from Flex 3.4 to Flex 4.0 fixed the runtime problems.