I need help with pixel neighborhood operations

4 vues (au cours des 30 derniers jours)
Matheus Sponton
Matheus Sponton le 13 Juin 2021
Modifié(e) : DGM le 13 Juin 2021
Hello everyone,
My goal is to find the defects in the fabric of the image, I'm trying to do this with neighboring pixel, but I don't know how to use neighboring pixels in this case.
Could you help me with this? My idea was to go through the matrix analyzing the neighboring pixels, and if many neighboring pixels are equal, white in this case "Binarized image", I copy it in black to a new image, highlighting the defects.
Thanks

Réponse acceptée

DGM
DGM le 13 Juin 2021
Modifié(e) : DGM le 13 Juin 2021
If you have Image Processing Toolbox, you likely don't need to resort to any sort of pointwise looping code. Most such operations can be done with bwmorph() among others. Even if there's something you want to do that bwmorph can't do, resorting to pointwise evaluation can usually be avoided.
That said, I don't know that neighborhood-based ops are really needed, but at the same time, I'm not sure of a single robust technique for the task. In a real application, fabric orientation, color, pattern, and defect types would vary. Defects in fabric woven from a single color would need a different technique, etc.
Given the possible depth of the problem, I'll start with a very simple approach. It's probably not very robust, since the threshold value depends on the fabric color and thread contrast, but it's a start.
inpict = rgb2gray(imread('denim.bmp'));
% find some threshold which emphasizes the defects
% and breaks up the background into non-contiguous blobs
wpict = inpict>128;
% get rid of all blobs with area <30px
wpict = bwareaopen(wpict,30);
  2 commentaires
Matheus Sponton
Matheus Sponton le 13 Juin 2021
Thanks !!!! Can you explain to me in more detail what this does?
wpict = inpict>128;
DGM
DGM le 13 Juin 2021
Modifié(e) : DGM le 13 Juin 2021
That's a very rudimentary thresholding operation used to convert the grayscale image to a binary black/white image. Since the image is class uint8, the data ranges from 0 to 255. Everything above 50% gray is now white; everything else is black. This is the result:
There are other, more complicated, but potentially more robust ways to binarize an image. See imbinarize().
Once it's a binary image, any sort of morphological operations can be performed. Note that the selected threshold reduces the background to small discontiguous dots that can easily be segregated from the defects based on their size. If I chose a lower threshold (e.g. 100), I'd get this:
Which would obviously not be suited to the same strategy. You should be able to see now why such a simple technique would be sensitive to changes in thread color/contrast or illumination.
EDIT:
Bingo. Image Analyst just posted a very relevant and useful resource for more practical approaches to this sort of thing.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 13 Juin 2021
Looks like you've accepted an answer that works (via intensity thresholding) for the image you uploaded. If you want a more robust method, find one here:
19.6.3.6 Inspection -- Textiles, Fabrics, Fibers
There are all kinds of methods there, using Gabor filters (of which there is a MATLAB function for), Neyman-Pearson Detector, neural networks, wavelets, etc.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by