# Python detect defects scratch

**URL:** <https://forum.opencv.org/t/python-detect-defects-scratch/3325>\
**Category:** Python\
**Tags:** detect\
**Created:** [May 13, 2021, 7:57pm UTC](https://forum.opencv.org/t/python-detect-defects-scratch/3325 "2021-05-13T19:57:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rambo123](https://avatars.discourse-cdn.com/v4/letter/r/dc4da7/32.png) [@rambo123](https://forum.opencv.org/u/rambo123)\
**Post date:** [May 13, 2021, 7:57pm UTC](https://forum.opencv.org/t/python-detect-defects-scratch/3325/1 "2021-05-13T19:57:23Z")

</div>

Hello, I have these two images and I need to detect the white scratch using python and opencv. I have tried computing a simple difference and using a mask but it didn’t detect the scratch. Could you please help? thanks

 ![185834352_10223203432846845_3010827711055890903_n](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d9dc17e6062aabfbcb5d8f8fed04461f09cc7e9f.jpeg)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [May 13, 2021, 8:05pm UTC](https://forum.opencv.org/t/python-detect-defects-scratch/3325/2 "2021-05-13T20:05:39Z")

</div>

> [@rambo123](#):
>
> I have tried computing a simple difference

even without “the scratch”, your 2 images are not “the same”

---

<div class="post-metadata">

**Author:** ![Alejandro\_Silvestri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alejandro_silvestri/32/357_2.png) [@Alejandro\_Silvestri](https://forum.opencv.org/u/Alejandro_Silvestri)\
**Post date:** [May 13, 2021, 9:32pm UTC](https://forum.opencv.org/t/python-detect-defects-scratch/3325/3 "2021-05-13T21:32:15Z")

</div>

About simple ways to detect scratch:

They are highly contextual. They depend on how you define scratch in visual and computable terms.

From the images you provided, the scratch is lighter, may be you can segment it with threshold.

An easier way is to look for scratches on the plain region.

You can use the reference image to align the test one. Then you look for scratches in ROIs, in designated areas where they are easier to detect.
