enter image description here

I wish to extract long thin scratches from the noisy background image.I have tried several ways such as stacking smoothed image with input image to remove some of the noisy background patch before applying blob detection filtering on those images to get the long thin scratch. However, overkill will happen due to the noisy background patches.

Any good suggestion or guidance on other things to try?


2 Answers 2


I tried PHOT (suggested by @applesoup) using the unofficial implementation given under https://github.com/thinkng but it did not work for these image sets. Maybe one needs to further investigate or tweak the algorithm a bit.

First, if you have sufficient amount of data, I do not believe that one could easily outperform a good deep architecture in the task of texture defect classification. The literature is full of these data driven methods. Some examples are here: [1], [2], [3], [4], [5].

However, due to limited amount of data, I tried a classical approach which seems to output somewhat acceptable results. In essence, the method involves:

  1. Compute the multi-scale difference of Gaussian (DoG) image. Call this $D=\{D_i\}$, where $D_i$ is a single DoG: $$ D_i = I * g_i^1 - I*g_i^2 $$ where $I$ is a single channel input image and $g_i^1$ and $g_i^2$ are two Gaussian kernels with $\sigma_2>\sigma_1$. $*$ denotes convolution. As your defects are line-like, such edge enhancement should ease the job of any subsequent analysis. The resulting DoG images look like:

enter image description here

You could already see that the defective areas are a bit emphasized. I show here only one of the scales, whereas multi-scale convolutions form a scale pyramid (see scale-space theory). That is what $D$ is.

  1. Perform a curve (line) detection on this DoG pyramid $D$ by using the algorithms provided in one of my previous responses. The raw response of such a subpixel line detector on a single level of the hierarchy:

enter image description here

Even though the images are messy and cluttered by many false positives, the lines we are looking for seem to be there. I avoid showing all the detected lines as this would severely harm the perception.

  1. The final stage is to filter these curvilinear structures to arrive at the desired scratches. While many filtering techniques can be used, I just let the lines that are long enough survive. The output after all these stages looks like:

enter image description here

This is not ideal, but probably close to what you have been looking for. I also did not spend much time to tune the parameters.

Note that this approach is solely based upon a geometric modeling of the problem. For different types of scratches these assumptions won't hold. Nevertheless, I thought it might be a good starting point.


One approach would be to compute the Phase Only Transform (PHOT) of your image, i.e., set the magnitude of the discrete Fourier transform (DFT) to unity [1].

It is computed as follows. First compute the DFT of the input image: $$ A(x,\,y) = \text{DFT}\left\{x,\,y\right\}=\sum_{j=0}^{N-1}\sum_{k=0}^{N-1}a(j,\,k)\cdot \text{exp}\left(\frac{-i2\pi}{N}\cdot(uj+vk)\right), $$

then compute the amplitude-normalized DFT: $$ A_\text{PHOT}(x,\,y) = \frac{A(x,\,y)}{\left|A(x,\,y)\right|},\qquad(2) $$

and compute the inverse DFT: $$ a_\text{PHOT}(x,\,y) = \sum_{j=0}^{N-1}\sum_{k=0}^{N-1}a_\text{PHOT}(j,\,k)\cdot \text{exp}\left(\frac{i2\pi}{N}\cdot(uj+vk)\right). $$

As described in [1], the process of normalizing the DFT magnitude in Eq. (2) removes regularities from the input image and makes sudden changes stand out. Basically, this is an alternative to the computation of the prediction error of an autoregressive (AR) model. By thresholding the PHOT, it may be possible to detect the desired artifacts in your images.

For me, the PHOT performed much better than computing the AR prediction error - however, your results may vary as my field of application was audio signal processing.


[1] D. Aiger, H. Talbot, The Phase Only Transform for Unsupervised Surface Defect Detection, IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 13-18 June 2019, San Francisco, CA, USA, DOI: 10.1109/CVPR.2010.5540198.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.