Detecting the edges of striped fabric on a chessboard

When detecting striped fabric, my solution performed poorly, resulting in fragmented and incomplete detection. Here are my steps:

  1. Grayscale conversion

  2. Opening Operation: Denoising

  3. Gaussian blur

  4. Calculate the median of the grayscale and use Canny edge detection

  5. Closing Operation

  6. Calculate the maximum edge value

I consistently fail to obtain a complete and effective fabric edge. My knowledge of edge detection is limited, and I hope to receive some insights and assistance.

This is my result; the separation is very fragmented.

bad illumination. your light sources reflect in whatever surfaces you have there.

place lights such that they don’t reflect in those surfaces.

Optimizing the lighting might be difficult at this point because the fabric is covered by glass. Are there any solutions under these conditions?

You could exploit the chessboard pattern around the piece of fabric, for a rough contour finding. Thankfully, the chessboard pattern is not suffering of specular reflections, at least not for this image you provided.

Here’s what I would try:

  1. Find all chessboard corners in the image.
  2. Fit horizontal and vertical lines to all detected corners (the image is slightly distorted due to optics, but straight line fitting is still possible, provided you tune hyperparameters right).
  3. Find where each fitted vertical and horizontal line “breaks down” due to lack of presence of corners “sustaining” that line. The location of breakdown can either be:
    1. the last detected corner in the chessboard pattern before entering the fabric surface;
    2. the last pixel along the line for which its neighbourhood suffered a jump in colour distribution
  4. After you performed step (3) for each line, simply interpolate their corresponding breakdown points to get the contour.

Another method, that could work in conjunction with the one above could be:

  1. Fit a colour distribution to the black and white squares composing the chessboard pattern
  2. For each pixel in the image, compare the colour distribution in its neighbourhood to the chessboard distribution fitted in step (1), obtaining a scalar value (you can use, for e.g., Earth Mover’s Distance function). You can map that difference value to either:
    1. a binary value, by comparing against a fixed threshold, producing a binary mask;
    2. or you could map the difference scalar value to a range, producing a mask that is close to binary, but has gradients around the true edges of the piece of fabric. This “soft” transition around the true edges of the fabric, compared to the hard transitions produced by the binary mask above, could be exploited in smarter ways to locate the true edges more accurately, perhaps.

Hope this helps. Good luck!

1 Like

and that is the trouble you might have to go to if you insist on working with the picture you have, instead of improving the pictures before they’re taken.

improving acquisition is so much easier than trying to squeeze useful information out of bad input.

Thank you all for your help. Due to the complex lighting and inconsistent fabric, semantic segmentation seems to be more suitable.

Thank you for your suggestion! I will try it.