Frosty555
asked on
Determine changed pixels in a Bitmap
I hope this isn't too hard a question.
I have a Bitmap object in VB.NET which I drew to using Graphics.DrawImage() (it was a screenshot of the screen which I scaled down. I don't have to scale it down before I process it for changes... whichever way works faster)
Later on, I do the exact same process, and I have a second bitmap object.
Now I need a way to (quickly) determine the basic areas that have changed in the image. Ideally I'd like to know the exact pixels that have changed, but if I, say, could just split the bitmap into some number of conceptual "pieces" and determine if each piece has changed, that's perfect as well.
I can use GetPixel on each and compare the values all the way through the bitmap object... but I imagine it would be painfully slow. I need to do it quickly. Under 50ms preferably for a 1600x1200 size screen o.O I know that's a tall order. I considered maybe comparing every 100th pixel, or comparing down just a few columns and rows, but I don't think it would accurately tell me what areas have changed.
Is there any other way to compare two bitmap objects in VB.NET?
I have a Bitmap object in VB.NET which I drew to using Graphics.DrawImage() (it was a screenshot of the screen which I scaled down. I don't have to scale it down before I process it for changes... whichever way works faster)
Later on, I do the exact same process, and I have a second bitmap object.
Now I need a way to (quickly) determine the basic areas that have changed in the image. Ideally I'd like to know the exact pixels that have changed, but if I, say, could just split the bitmap into some number of conceptual "pieces" and determine if each piece has changed, that's perfect as well.
I can use GetPixel on each and compare the values all the way through the bitmap object... but I imagine it would be painfully slow. I need to do it quickly. Under 50ms preferably for a 1600x1200 size screen o.O I know that's a tall order. I considered maybe comparing every 100th pixel, or comparing down just a few columns and rows, but I don't think it would accurately tell me what areas have changed.
Is there any other way to compare two bitmap objects in VB.NET?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
iboutchkine: Your solution is like I described in the question, comparing every pixel using the GetPixel() function. It will be too slow to do anything productive with it.
PaulHews: I see where you're going, you're X-ORing the bits, so that a change in the bits will result in a nonzero value in the output bit (so, pixels that have changed will be not-black).
The next step is actually analyzing the final image to figure out what parts are non-black... can you think of any way to do this without resorting to GetPixel()?
What I need in the end is the coordinates of some kind of "dirty rectange" of the image. It doesn't have to be perfect. It just needs to enclose all the dirty pixels. If we could find some fast way to crop the image to the rectangle encasing all the changed pixels, that'd be perfect...
Maybe some kind of .net-based cropping that crops all the black off the outside border of the image?
PaulHews: I see where you're going, you're X-ORing the bits, so that a change in the bits will result in a nonzero value in the output bit (so, pixels that have changed will be not-black).
The next step is actually analyzing the final image to figure out what parts are non-black... can you think of any way to do this without resorting to GetPixel()?
What I need in the end is the coordinates of some kind of "dirty rectange" of the image. It doesn't have to be perfect. It just needs to enclose all the dirty pixels. If we could find some fast way to crop the image to the rectangle encasing all the changed pixels, that'd be perfect...
Maybe some kind of .net-based cropping that crops all the black off the outside border of the image?
You might find the filters used here of interest:
Motion Detection Algorithms
http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx
Motion Detection Algorithms
http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx
ASKER
Those do look pretty interesting... but all of it is in C#. Is there a way to still use it in VB?
I'm actually finding that my original program is running atrociously slow right now. I have no room for additional overhead. I might have to put this on hold while I figure out what's taking all the time elsewhere.
I'm actually finding that my original program is running atrociously slow right now. I have no room for additional overhead. I might have to put this on hold while I figure out what's taking all the time elsewhere.
ASKER
The solution works, and you can get the changed pixels this way. It's just way to slow to be used in an environment where changed pixels need to be determined several times a second. It would take longer to determine the changes pixels then it would take to just send everything down the network.
Two methods to output changed pixels to third picturebox:
Open in new window