Finding the best fit slope of a Bitmap surface

Hey, forum. I was wondering if anyone knows of a way to isolate the pixels that are adjacent to a certain color pixel in a BitmapData. For example, if there was a BitmapData that looked something like this:

X O O O O O
X X O O O O
X X X O O O
X X X X O O
X X X X X O
X X X X X X (where “X”'s are black pixels and “O”'s are white pixels)

You would want to isolate the following pixels:

D O O O O O
X D O O O O
X X D O O O
X X X D O O
X X X X D O
X X X X X D (where “D”'s are isolated pixels)

I was wondering if there was a proven and efficient way of doing this, because I am trying to make a collision engine of sorts that can give me the collision normal of the best fit slope of a given bitmap image. In the scenario of the last example, the slope would be 1/1, or -45 degrees. The way I have it now, I am isolating the adjacent pixels by blurring the entire image, looping through all of the pixels, and storing the gray ones in an array. from there I can determine the best fit slope of the surface of the image. The only thing is that this seems like a lot of work for the CPU. Is there a better way to isolate the black pixels adjacent to white ones than blurring the image and looping through every pixel? I’ve heard of “Potrace,” but that also seems like overkill for what I’m trying to do. I’m thinking this would make sprite collision response in an art based environment a lot easier to deal with.