Detect a change in color?

Blitz3D Forums/Blitz3D Programming/Detect a change in color?

CopperCircle(Posted 2006) [#1]
How can I detect a strong change in color on an image so that I can mark it as an edge? For example a red ball on a blue background, I need to find the edges of the ball.

Thanks.


tonyg(Posted 2006) [#2]
Lock the image, read a pixel, check whether the different between that colour and previous colour using ReadPixelFast (either default or previous pixel), move on to the next pixel.


big10p(Posted 2006) [#3]
You still trying to work out this 'mean filter' thingie, CopperCircle?

As I mentioned in the other thread, I did have a quick play with an idea I had, but it proved pretty pants - as I warned it might. :)

The problem comes down to the fact that detecting if two given colours are the same (irrespective of brightness, etc), or not, is difficult.

In case you're interested, the idea I was playing with was to use a 'flood search' to identify areas of an image that have the same, or similar, 'colour'. This flood search worked on the same principle as a flood fill, so that it identified all connected pixels of the 'same colour', starting from a given x,y point in the image. I then tried setting all the pixels identified by the search to the average colour of all those found.

I had some limited success with this method, but didn't have time to develop it any further. I'm not convinced it can be made to work any better, anyway. Results obtained from using filters in standard image editing software seemed to do a better job, too. :/


Shifty Geezer(Posted 2006) [#4]
To select by colour you'd need to convert to a colourspace you're happy working with, such as HSL and detecting by Hue.

http://www.cs.rit.edu/~ncs/color/t_convert.html

However there's no simple select by colour process, such as if Hue Difference is > delta. I don't know of any good algorithm for this.


big10p(Posted 2006) [#5]
Yeah, I tried using HSL, but it didn't help much. The trouble with the HSL colour model is that it doesn't have the resolution of the RGB colour model. For example, how do you find the Hue of a pure grey?


Shifty Geezer(Posted 2006) [#6]
Traditional HSL pegs it at H=0, but it really needs a per case consideration depending on what you're trying to do. It's down to the user to decide if grey is a change from Hue = 100 or not.


CopperCircle(Posted 2006) [#7]
I have tried posterising the image by anding each color with %11000000 and also comparing the brightness of each pixel to find edges. But neither give the required effect, I know the basic mean shift algorithm will break an image into seperate color sections but I have not been able to find a good source of how to write the mean shift filter.

Once the image reduced to basic color patches I could smooth it and then define the edges.

I am trying to get the look used in "A Scanner Darkly"

big10p I would love to see what you have done?

Cheers.


Shifty Geezer(Posted 2006) [#8]
That Mean Shift did a good job, but I've no idea of the algorithm :(


big10p(Posted 2006) [#9]
big10p I would love to see what you have done?
Yikes! I was afraid you were going to ask that. :P The code is pretty rough and unoptimized (i.e. slow) as I just wanted to slap something together quickly, to see if the principle worked. However, I'll try and post it up here, later on.

[edit]
OK, here's the code I was playing with. In it's current state, it doesn't work too well at all, TBH, and is very slow, but you can probably work out the method I was going for, from it.



CopperCircle(Posted 2006) [#10]
It kind of works, I see what you are trying to do.

Thanks.


big10p(Posted 2006) [#11]
I was going to develop it further by first creating a greyscale version of the image. This would (I think) help to identify areas of similar colour because there are only 256 greys (even in 32bit images). Then, I was going to use this greyscale image to perform the fill search on the real image.

Still not convinced it would have worked any better, but I didn't have time to try it, anyway. :)