# Accurate edge detection from noisy images

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

## Recommended Posts

Hi... As the title says i'm looking for a way to accuratelly extract edges from a noisy black and white image. Let me explain the situation. I have images which look like this one: I'm searching for a way to extract the edges of the pattern inside the image. I tried using some Photoshop techniques before start coding but i wasn't able to find something accurate. 1) I used regular edge detection filter but the black spots around the pattern didn't make it clear. 2) I tried to blur the image first, and despite it gave better results than 1, the resulted edges weren't accurate. Is there any way i can find the desired edges with one pixel accurancy? What i want to be able to do is after edge detection, to scan the image and store the edges' pixel positions in a sequential format. Say for example that the first pixel i find from the scanning is one of the shape's corners, i want to be able to form a loop by walking all the edge's pixels. Is this possible, or the image is too noisy to do it? Thanks in advance. If you need more info please ask. HellRaiZer

##### Share on other sites
Try doing some dialation followed by erosion to remove the dark spot aruond the pattern.

##### Share on other sites
Exactly as AP said. Perform a morphological sieve to eliminate the noise, then use a standard canny edge detector or a Laplacian of Guassian.

For the sieve, I suggest you try using area morphology, which is essentially the combination of all possible structuring element shapes. Note that most sieves using an open-close operation, rather than just an open as the AP mentioned. In your case, since you just want to get rid of the small dark areas, an open operation would be sufficient.

There are loads of papers on this on the IEE(E) Image Processing Group database (IEExplore).

##### Share on other sites
AP and python_regious thanks for the replies.

I thought of dillation too (not the erosion step), but i couldn't find a way to preserve the edge shapes and eliminate only the black spots.

Unfortunatelly i don't have access to IEEE papers (my university seems to have access to every electronic library except IEEE !!!). I'll try to browse their library in case to find relevant papers and then i'll try to see where i get them :) Maybe some of them are availiable through other libraries too.

And python_regious, i may not understand everything you described (my english don't help me here :)), but i have something to start searching. Thanks.

HellRaiZer

##### Share on other sites
Quote:
 Original post by HellRaiZerIs there any way i can find the desired edges with one pixel accurancy?

Quote:
 Original post by python_regiousExactly as AP said. Perform a morphological sieve to eliminate the noise, then use a standard canny edge detector or a Laplacian of Guassian.

It depends on what you mean... here is what I got when running a sobel edge detector :

But if you want one pixel accuracy with that much noise you wont be able. There is no practical way to remove the noise around the rectangles unless you're only searching for rectangles or straight lines. If you want to keep this for general edges that's the best you can hope.

With this image and the edge detection you could define easily where the rectangles are if you only want rectangles... just create the biggest rectangle in the regions found with sobel edge detection and I think you would get a good accuracy (with correct edge detection... mine was a quick one).

Another way if you know you will detect only straight lines is to actually make those noisy edges more straight :). I can't remember the algorithms to do that right now though.

JFF

##### Share on other sites
Quote:
 Original post by HellRaiZerAP and python_regious thanks for the replies.I thought of dillation too (not the erosion step), but i couldn't find a way to preserve the edge shapes and eliminate only the black spots. Unfortunatelly i don't have access to IEEE papers (my university seems to have access to every electronic library except IEEE !!!). I'll try to browse their library in case to find relevant papers and then i'll try to see where i get them :) Maybe some of them are availiable through other libraries too.And python_regious, i may not understand everything you described (my english don't help me here :)), but i have something to start searching. Thanks.HellRaiZer

You need to perform an open operation (dilation followed by erosion) to preserve elements greater than the size of the structuring element, otherwise they will be reduced in size. Remember, you only want to remove features less than the size of the structuring element, and preserve the rest.

I did find some good papers on morphological operations, but I don't think they're suiting for what you want (this was when I was researching colour granulometries). If all else fails, google is your friend [smile]

As jff_f has shown however, getting a perfect rectangle is hard (although you can use a better edge detector to join up the edge segments, Canny for instance). If you perform a series of square sieves you will reduce the edges of the rectangles to be straight, you'll have to go up to a pretty large size though, so it all depends on your processing budget.

##### Share on other sites
jff_f thanks for trying that. I must admit those edges are way better than mine (see photoshop tricks) :) The problem is that they aren't connected, and as i said in my first post i need the edges of a shape to form a loop so i can extract the shapes. Anyway this shows that it can be done. And as python_regious said, a better filter may do it. I'll have to check that tomorrow.

Quote:
 There is no practical way to remove the noise around the rectangles unless you're only searching for rectangles or straight lines. If you want to keep this for general edges that's the best you can hope.

Unfortunatelly the shapes can be complex (see, concave polygons (not just quads))

Quote:
 With this image and the edge detection you could define easily where the rectangles are if you only want rectangles... just create the biggest rectangle in the regions found with sobel edge detection and I think you would get a good accuracy (with correct edge detection... mine was a quick one).

The whole process must be automatic (for batch mode) so i don't know how practical this can be (defining the regions where shapes should exist).

python_regious:
Quote:
 As jff_f has shown however, getting a perfect rectangle is hard (although you can use a better edge detector to join up the edge segments, Canny for instance). If you perform a series of square sieves you will reduce the edges of the rectangles to be straight, you'll have to go up to a pretty large size though, so it all depends on your processing budget.

Performance isn't an issue. Of course i want it to finish in finite time :) but i don't care if it takes 5 secs or 5 mins. The problem is that the edges of the squares must stay as is. I must extract the exact edges, and if i understood what you described correctly, the edges will become smoother. This isn't good for me.

Instead of dilating the image in case to remove the black spots around the shapes, i can use dilation in a way to mimic photoshop's magic wand. I could place e.g. a red pixel inside each shape, and flood fill the shapes until the red pixels meet white. When no red pixel can be moved, then the dilation stops. If i replace all other-than-red pixels with a solid color, then edges can be extracted easily with any edge detection filter.
What do you think? Will this work?

I'll check it tommorow.

HellRaiZer

##### Share on other sites
maybe check out SUSAN? I've implemented something similar (not exactly the same) for work and it's pretty effective.

##### Share on other sites
I'm thinking a band-pass filter in the FFT domain will help in an initial step. Cancel out the frequencies of the noise and all you're left with are the shapes.

Either way I think it's a good idea to start with a noise-reduction scheme and then run the edge detection later. If you have simple noise like the image you showed it probably will be enough to cancel out a fairly narrow band of frequencies in the FFT domain (say a butterworth filter).
You could also try wiener filtering or constrained least squares filtering for that.

For that particular type of image you might try a max filter with some suitable kernel size as well. It's unlikely that you'll find, say, a 3x3 all-black area in the noisy part, so that will be all white, whereas the inside of the black areas will be all black.

##### Share on other sites
Quote:
Original post by HellRaiZer
python_regious:
Quote:
 As jff_f has shown however, getting a perfect rectangle is hard (although you can use a better edge detector to join up the edge segments, Canny for instance). If you perform a series of square sieves you will reduce the edges of the rectangles to be straight, you'll have to go up to a pretty large size though, so it all depends on your processing budget.

Performance isn't an issue. Of course i want it to finish in finite time :) but i don't care if it takes 5 secs or 5 mins. The problem is that the edges of the squares must stay as is. I must extract the exact edges, and if i understood what you described correctly, the edges will become smoother. This isn't good for me.

Instead of dilating the image in case to remove the black spots around the shapes, i can use dilation in a way to mimic photoshop's magic wand. I could place e.g. a red pixel inside each shape, and flood fill the shapes until the red pixels meet white. When no red pixel can be moved, then the dilation stops. If i replace all other-than-red pixels with a solid color, then edges can be extracted easily with any edge detection filter.
What do you think? Will this work?

You don't just dilate, that is a bad thing, as I said. Actually I was incorrect earlier, a close operatiosn would be more appropriate to what you want and is an erosion of a dilation. Sieving the image will in no way "smooth" the edges. Morphology is a non-linear operation, in as much as it doesn't introduce any new signals into the image (unlike linear operations such as the mean filter - which most certainly introduces new signals).

Your flood-fill algorithm could work, but is heavily dependant on there not being a thin route through the noise, and of course it needs human intervention [smile].

Just a bit of background incase you didn't know:

In greyscale, the dilation is simply a maximum operator, and an erosion a minimum filter. The open operation is defined as dilate( erode ) and the close is erode( dilate ). Closings are what you want to use here. You would want to use about a 7x7 structuring element to get rid of most of that noise. Larger structuring elements would straighten up the edges somewhat, though they may be shifted by a few pixels.

I could go into the definition, derivation and into more complicated morphological operations if you like, but I don't think it's necessary for what you want to do.

If you go into photoshop, filters->other->maximum - then do the minimum using the same size - that would perform a closing operation using a square structuring element of the size you input. As an example. here's the output of a (20x20 I think - "size 10" in PS anyway) close operation:

Just note that any colours or smooth edges you see is photoshop being shit.

[Edited by - python_regious on June 27, 2006 6:18:05 PM]

##### Share on other sites
Infact, just to see how good I could get it, I first converted everything to greyscale (got rid of the odd colour and smoothing property in photoshop), perform a 60x60 close operation, then did a laplacian edge detection. This is the result, which I think is ok:

##### Share on other sites
Quote:
 Original post by sebastiansylvanI'm thinking a band-pass filter in the FFT domain will help in an initial step. Cancel out the frequencies of the noise and all you're left with are the shapes.

I don't have that implemented right now... but I outputed the amplitude from FFT and this might be something interesting to try since the noise might be in the corners of this image (not 100% sure on that part, its been more than a year I didn't work with image processing :P). But this might also blur the edges since they are noisy.

JFF

##### Share on other sites
Just using a LPF (depending on it's construction of course) will create smooth edges.

##### Share on other sites
Thanks for the replies all :)

python_regious:
Quote:
 You don't just dilate, that is a bad thing, as I said. Actually I was incorrect earlier, a close operatiosn would be more appropriate to what you want and is an erosion of a dilation. Sieving the image will in no way "smooth" the edges. Morphology is a non-linear operation, in as much as it doesn't introduce any new signals into the image (unlike linear operations such as the mean filter - which most certainly introduces new signals).

Quote:
 In greyscale, the dilation is simply a maximum operator, and an erosion a minimum filter. The open operation is defined as dilate( erode ) and the close is erode( dilate ). Closings are what you want to use here. You would want to use about a 7x7 structuring element to get rid of most of that noise. Larger structuring elements would straighten up the edges somewhat, though they may be shifted by a few pixels.

(Just a note, i think the photoshop steps are reversed. You said i want a close operation which is erode( dilate ), which in photoshop means min(max) and not max(min)).

I think i start to understand the terms, and the process. Thanks for making them more clear to me. I found a book called Image Processing in C. It seems to go over all the required processes (edge detection, open/close operations, etc.) I have a lot of reading to do :)

From a quick run over the book's code, the closing operation seems to be exactly as in photoshop (max followed by a min). This means that the edges don't preserve their initial shape. It has a special_close() function inside, which i have to look.

I understood why on grayscale images, dilation can be done using a max operator, and erosion with a min operator, but i can't understand how this can be turned into a "selective" max (replace the color with the max of the neighbors, only where noise exist). I'll have to read the whole chapter on shape manipulation.

Quote:
 I could go into the definition, derivation and into more complicated morphological operations if you like, but I don't think it's necessary for what you want to do.

Thanks but it's not necessary. I have the book now :)

One note. The weird green color you saw in photoshop is actually present in my image. If you look carefully you will see it. It's a by product of the process used to generate the image. I can easily get rid of it.

lonesock:
Thanks for the link. I'll have that in mind when everything else fail. It's interesting to work with these things, so i'd prefer to learn something from it, than use a ready library. I got my feets wet know, so... :)

sebastiansylvan and jff_f:
I'll have to look at that. Noise reduction can help a lot the close operation. If most of the noise disappears, then i think i get away with a small dilation/erosion kernel.

One side note. Not all images have this noise. I mean noise can be present in bigger black spots, so the bigger those "holes" are the bigger i think the kernel must be, and as a result the smaller the accurancy of the detector. Here is another image with more/bigger noise with the same pattern (sorry for the images; i know those could kill a 56k connection).

I have even more complex shapes, with noise inside the shapes (white spots inside the rectangles this time). I'll see if i can make some of them in case to show all the possible difficulties.

Thanks for the support so far.

HellRaiZer

##### Share on other sites
Quote:
Original post by HellRaiZer
Thanks for the replies all :)

python_regious:
Quote:
 You don't just dilate, that is a bad thing, as I said. Actually I was incorrect earlier, a close operatiosn would be more appropriate to what you want and is an erosion of a dilation. Sieving the image will in no way "smooth" the edges. Morphology is a non-linear operation, in as much as it doesn't introduce any new signals into the image (unlike linear operations such as the mean filter - which most certainly introduces new signals).

Quote:
 In greyscale, the dilation is simply a maximum operator, and an erosion a minimum filter. The open operation is defined as dilate( erode ) and the close is erode( dilate ). Closings are what you want to use here. You would want to use about a 7x7 structuring element to get rid of most of that noise. Larger structuring elements would straighten up the edges somewhat, though they may be shifted by a few pixels.

(Just a note, i think the photoshop steps are reversed. You said i want a close operation which is erode( dilate ), which in photoshop means min(max) and not max(min)).

I think i start to understand the terms, and the process. Thanks for making them more clear to me. I found a book called Image Processing in C. It seems to go over all the required processes (edge detection, open/close operations, etc.) I have a lot of reading to do :)

Yeah, it was late last night. You might want to look at Gonzales & Woods, it's a great book (called something like "Image Processing" funnily enough), I've used it many a time when I've been looking at some of the simpler operations. Since what you're doing is essentially image segmentation, you might want to pick up a book or some papers on that.

Quote:
 From a quick run over the book's code, the closing operation seems to be exactly as in photoshop (max followed by a min). This means that the edges don't preserve their initial shape. It has a special_close() function inside, which i have to look.

Closing operations do preserve edge, when in relation to the shape of the structuring element. Remember that morphology is essentially pattern matching (the word actually derives from a biological term meaning the form of a cell regardless of function - or something like that), so you will see the shape of the structuring element in the filtered image. This isn't a problem if the SE is the same shape as what you're looking for (in this case, square, and it produces a nice crisp edge. If I made it star shaped or something, it wouldn't be as good).

Quote:
 I understood why on grayscale images, dilation can be done using a max operator, and erosion with a min operator, but i can't understand how this can be turned into a "selective" max (replace the color with the max of the neighbors, only where noise exist). I'll have to read the whole chapter on shape manipulation.

Quote:

Quote:
 I could go into the definition, derivation and into more complicated morphological operations if you like, but I don't think it's necessary for what you want to do.

Thanks but it's not necessary. I have the book now :)

One note. The weird green color you saw in photoshop is actually present in my image. If you look carefully you will see it. It's a by product of the process used to generate the image. I can easily get rid of it.

Well, if you're going to be processing colour images, I've developed a number of techniques to perform morphological operations on multivariate data that might come in useful..

##### Share on other sites
I just had a thought actually. (Don't laugh [smile])

You're saying that you want to use the most optimal kernel to reduce the noise adequately enough.

Well, when performing granulometry you sieve the image using progressively larger structuring elements, subtracting the resulting image from the previous as you go. From these results you can construct a size distribution, and actually calculate at what size most of the "granules" are at. You could then choose a structuring element with respect to where the majority of the noise is located, and filter the image using this. Of course, this would be far far more computationally expensive, as you'd first have to generate the granules, calculate the size distribution (which is essentially a probability density function), find the optimal size of structuring element based on the size distribution, and again filter the original image using this.

If I've captured your interest, I can tell you more...

##### Share on other sites
Why do you need this anyway?
The noisy images kinda remind me of those images containing codes that you need to type in to get an email account on yahoo, google, hotmail etc.
You're not working on circumventing those anti-spam techniques, are you? ;)

##### Share on other sites
Quote:
 Why do you need this anyway?The noisy images kinda remind me of those images containing codes that you need to type in to get an email account on yahoo, google, hotmail etc.You're not working on circumventing those anti-spam techniques, are you? ;)

You got me... No, i'm just kidding :) I thought i mentioned this in a previous post, but i might have deleted it before posting. What you see in the image (the white thing) are self-avoiding random chains inside a lattice. The patterns have been constructed by removing all chains which meet a specific criterion (is this correct?). This is the green thing you see on some chains. Every chain that has enough "greens" is removed from the lattice.

Said that, python_regious, the flood filling idea i mentioned earlier doesn't need human intervention (place the red pixels by hand), because i can know where there is a possible position for that. But as you said, it may have problems when the noise make up thin (one-pixel wide) paths, from where the red pixels can move. (My english suck btw :))

Quote:
 I just had a thought actually. (Don't laugh )You're saying that you want to use the most optimal kernel to reduce the noise adequately enough.Well, when performing granulometry you sieve the image using progressively larger structuring elements, subtracting the resulting image from the previous as you go. From these results you can construct a size distribution, and actually calculate at what size most of the "granules" are at. You could then choose a structuring element with respect to where the majority of the noise is located, and filter the image using this. Of course, this would be far far more computationally expensive, as you'd first have to generate the granules, calculate the size distribution (which is essentially a probability density function), find the optimal size of structuring element based on the size distribution, and again filter the original image using this.If I've captured your interest, I can tell you more...

Why should i laugh :) I think this is a great idea. I thought of something similar a while ago, but not by using image processing techniques. I wanted to make the distribution of free space (the black spots) inside the lattice. A distribution of the size of these black spots in pixels (or more correctly lattice cells). I tried to brute-force it with recursion (start in one cell, and call the counting function for all the neighboring cells) and it worked well when the black spots were small. When they were big, i got a stack overflow, and i was really bored to convert it to in-place recursion (using a stack instead of calling functions over and over).

So what you suggest is that i start applying the closing operator, first with a 3x3 mask, then with a 5x5, 7x7, etc. and calculate the difference between operations, until there is no difference between the two? If i already had the free volume distribution, i could be able to guess the optimal mask size.

Here is the results i got by applying dilation/erosion with a 7x7 mask on the second image i posted above (the one with the bigger black spots). The edge detector was a simple 3x3 filter :

 0 -1  0-1  4 -1 0 -1  0

Original image (same as above)
After closing (dilation/erosion)
Detected edges
Missed features

As you can see (if you compare the images) not all the edge features are present in the detected edges.
What am i doing wrong? Isn't this what you had in mind? Or this is natural because of the big mask?

HellRaiZer

##### Share on other sites
OOohh, I see. You want to keep the irregularity of the edges. Sorry, I thought that you wanted to essentially get nice neat rectangles out of it [smile].

The unfortunate side effect of using standard structuring element based morphology is you do eliminate the small details. Although, it's not really a side effect, as they're designed to do that. You might have more luck with an area morphology based approach, or you could try experimenting with different shaped structuring elements (say, a star shape or something, or a circle). I haven't got an area morphology solver in my image processing software unfortunately - certainly not a greyscale one, and since I'm not at home I can't add one in either.

One of my mates used area morphology to detect sprites to great success, (sprites are irregularly shaped, so you know), so I think it may be something you should look into.

As for the granulometry, it can be performed using area morphology too. I do have a few papers on it, but since most either came from my supervisor when I was at uni doing this stuff, or from the IEEE site, which you have to pay for, I dunno whether I'd be allowed to email it to you or something. Still, I wrote about it in my final report, so I can essentially cut and paste the details that you need to know if you like. Since the report is 179 pages and 12.8Mb, I don't want to download it from home and pull it apart here, it'll just take too long. Here is a good page on morphology and granulometry for you.

Anyway, once you have your size distribution (which is essentially a bar chart), you can perform analysis on that to obtain where the majority of the power is located in the image, and choose an area-size or structuring element size to match.

##### Share on other sites
Urgh, I hate it when this happens. Remove all cases of "size distribution" and replace with "pattern spectra". I got the two mixed up (the size distribution is just the cumulative pattern spectra).

Anyway, since I'm horribly bored at work, here's a chapter from my report on the background on granulometry. It isn't an extensive section by far (it's only a literature review really), but it should be enough. Link.

##### Share on other sites
How about using ACMs? If you can identify some points inside the shapes, you could then grow a contour from inside the shape, thus building the boundary. It's not an area I've studied a lot (did my projects on Hough transforms), but it seems it could be a could candidate in your application. There's a demo applet of ACMs here, but there's loads of info available, just search for "active contour model", or "snakes", but I'm guessing the former will give you more relevant hits ;)

##### Share on other sites
python_regious thanks for all the help, links and papers. :)

Quote:
 OOohh, I see. You want to keep the irregularity of the edges. Sorry, I thought that you wanted to essentially get nice neat rectangles out of it .

Yes i want the irregularities. That's what i'm trying to say from the beginning, but (once again) my english don't help. I have to do something for this :) (to self : learn english)

The page and the part of your report on granulometry, made the whole thing more clear (i think). When i'm going from one structurin element to the next (= bigger one), should those two differ only in size or they must differ in shape too? E.g. two different 3x3 masks can be:

1 0 01 1 00 1 1

1 1 01 1 11 0 0

Should i apply both of them, or a simple 3x3 mask with all elements 1 will be enough. I think you mentioned in a previous post that i should try a star mask or something like that, so i guess they must differ in shape too. But then the possible combinations for an 7x7 maks are endless (i think 49! (this is factorial))

I'll give it a shot and i'll post back later.

Taharez:
Quote:
 How about using ACMs? If you can identify some points inside the shapes, you could then grow a contour from inside the shape, thus building the boundary. It's not an area I've studied a lot (did my projects on Hough transforms), but it seems it could be a could candidate in your application. There's a demo applet of ACMs here, but there's loads of info available, just search for "active contour model", or "snakes", but I'm guessing the former will give you more relevant hits ;)

I think what you describe is the same thing i posted previously (the flood filling thing, but without flooding the shape). I keep that on the back of my mind for now, because i'm trying to find a way to do the same thing without knowing anything about the image. And, as python_regious pointed out, this can lead to artifacts. I don't know for sure, but i think he is right. I guess the only way to find out is by implementing it :) Anyway, thanks for the suggestion.

HellRaiZer

##### Share on other sites
Quote:
 Original post by TaharezHow about using ACMs? If you can identify some points inside the shapes, you could then grow a contour from inside the shape, thus building the boundary. It's not an area I've studied a lot (did my projects on Hough transforms), but it seems it could be a could candidate in your application. There's a demo applet of ACMs here, but there's loads of info available, just search for "active contour model", or "snakes", but I'm guessing the former will give you more relevant hits ;)

That sounds extremely similar to Hellraisers flood fill algorithm. The problem that I can see is deciding where to start. You could construct a "blob" detection algorithm, such that it detects areas of black over a certain size, then find the geometric centre and start from there. I did write a "blob" detection algorithm about 4 years ago, but it's since been lost. It's not too hard though, as it's recursive in nature.

It also all depends on how much of the noise he wants to retain at the edges, and it would still suffer from routes through the noise, although these could be eliminated using a "only count the mass which is 95% from the CoM" type algorithm. However this would start to fail once you have two connected blobs.

##### Share on other sites
Quote:
Original post by HellRaiZer
python_regious thanks for all the help, links and papers. :)

Quote:
 OOohh, I see. You want to keep the irregularity of the edges. Sorry, I thought that you wanted to essentially get nice neat rectangles out of it .

Yes i want the irregularities. That's what i'm trying to say from the beginning, but (once again) my english don't help. I have to do something for this :) (to self : learn english)

The page and the part of your report on granulometry, made the whole thing more clear (i think). When i'm going from one structurin element to the next (= bigger one), should those two differ only in size or they must differ in shape too? E.g. two different 3x3 masks can be:

1 0 01 1 00 1 1

1 1 01 1 11 0 0

Should i apply both of them, or a simple 3x3 mask with all elements 1 will be enough. I think you mentioned in a previous post that i should try a star mask or something like that, so i guess they must differ in shape too. But then the possible combinations for an 7x7 maks are endless (i think 49! (this is factorial))

I'll give it a shot and i'll post back later.

Taharez:
Quote:
 How about using ACMs? If you can identify some points inside the shapes, you could then grow a contour from inside the shape, thus building the boundary. It's not an area I've studied a lot (did my projects on Hough transforms), but it seems it could be a could candidate in your application. There's a demo applet of ACMs here, but there's loads of info available, just search for "active contour model", or "snakes", but I'm guessing the former will give you more relevant hits ;)

I think what you describe is the same thing i posted previously (the flood filling thing, but without flooding the shape). I keep that on the back of my mind for now, because i'm trying to find a way to do the same thing without knowing anything about the image. And, as python_regious pointed out, this can lead to artifacts. I don't know for sure, but i think he is right. I guess the only way to find out is by implementing it :) Anyway, thanks for the suggestion.

HellRaiZer

Oh, you keep the same shape. When I talk about a 3x3 mask, I really mean:
1 1 11 1 11 1 1

If you want to use all possible permutations of a certain structuring element size, you want to use area morphology.

##### Share on other sites
I haven't had time to read all the posts thoroughly, but I had an idea so i thought I'd quickly write it down:

For each pixel    Find adjacent pixels of similar (or matching) colour and add them to shape_list along with the original pixel.    If length of shape_list is less than some thresh hold number        Mark all pixels in shape_list with colour A (a colour not in original image)    else        Mark all pixels in shape_list with colour B (a colour not in original image)

Hopefully what you'd end up with is an image mostly in colour A with the shapes in colour B. You could then do standard edge detection on the image to find the pixel boundaries without worrying about noise.

Does that makes sense?

T