Skip to main content

A package for detecting and analysing defects/pores in concrete, steel or similar surfaces.

Project description

SurfaceDefects Python Package

A simple but powerful Python package capable of

  1. detecting pores in concrete, steel and similar surafaces, or the fabrication errors for that matter.
  2. determining the area of each pore.
  3. calculating equivalent diameter of each pore. Equivalent diameter is the diameter of a circle whose area equals that of a pore. More on it later...
  4. calculating surface porosity i.e., the ratio of area covered by pores to the total area.
  5. plotting circles over pores once the equivalent diameters are determined.
  6. assigning length scale to image.

It works on the spirit of Computer Vision and segmentation. The Python package SurfaceDefects classifies surfaces based on the difference in their pixel values. It can also generally be used for detecting contours in 2D images of any type provided they are suitable for the intended purpose.

Better images lead to better results!

The concept will develop as we go down the documentation.

1. Install SurfaceDefects

~ pip install SurfaceDefects

2. Import into the project alongwith matplotlib.pyplot

import SurfaceDefects as sdf
import matplotlib.pyplot as plt

3. Load image using LoadImage() function

img = sdf.LoadImage(path, gray=Fasle) 

path: is the complete path to your image

gray: whether to load the image as a grayscale image, default is False

Tip: Load img as it is and another img_gray as a graysacle image. You will need both of them later.

4. Make a black replica of img (not compulsory)

black = sdf.PseudoImage(img) 

5. Detect pores/defects using ClassifySurface() function

thresh = sdf.ClassifySurface(img_gray, threshold, invert_color=True)
plt.imshow(thresh, cmap='gray')

thresh: the resultant image is better known as thresholded image hence thresh

img_gray: the original grayscale image

threshold: verily the most important parameter, threshold is what that controls the detection of pores/defects. Ranges between 0 (black) and 255 (white).

invert_color: swaps colors i.e., black to white. Default is True


plt's cmap='gray' for a grayscale image.

thresholded images

6. Find boundary of pores/defects using FindContours() function

Contours are lines joining points of same instensity.

Those points in this case are located along the boundaries of pores.

contours, _ = sdf.FindContours(classified_img)

contours: an array

_: the hierarchy and can be ignored in this particular case.

classified_img = thresh, the thresholded image.

7. SignificatContours()

Some of the contours found by FindContours() might be insignificant in that their areas might be zero. SignificatContours() will automatically discard contours whose areas are zero.

sig_contours, _ = sdf.SignificantContours(classified_img)

sig_contours: an array

_: the hierarchy and can be ignored in this particular case.

classified_img = thresh, the thresholded image.

8. Define a scale using DefineScale() function

scale_factor = sdf.Scale(height, width) 

scale_factor: a ratio of scale, or better known as a Referesentative Factor

height, width: height and width of real object/surface in units of length

9. Calculate area of pores using ContourArea()

pore_area = sdf.ContourArea(classified_img, sum=False, scale_factor=1)

If sum=True, total pore area will be calculated; otherwise a list.

scale_factor: a ratio of scale, or better known as a Referesentative Factor. Default value is $1$ which means no conversion from units of pixel to units of length.

10. EquivalentDiameter() calculates diameter of a circle whose area equals that of a pore

equ_dia =  sdf.EquivalentDiameter(contours, scale_factor=1)

11. DrawContours() draws boundaries of each pore

contour_img = sdf.DrawContours(img,contours, index=-1, color = (0,255,0), thickness=1)
#display
plt.imshow(contour_img)

img: original or black img

contours: array from DrawContours() or SignificantContours()

index: which contour boundary to plot? $-1$ means all. Similarly $2, 3, 4$ for number $3$rd, $4$th, $5$th respectively, and so on.

color: color of boundary line, default is green.

thickness: thickness of boundary line, default is 1.

12. DrawCircles() draws circle aroud the boundary of equivalent diameter

circle_img = sdf.DrawCircles(img, contours, color=(0,255,0), thickness=1)
plt.imshow(circle_img)

Refer to point number $11$ for parameters/arguments.

contours vs circles

13. Denoise() smoothens/denoises the original image

#applies GaussianBlur filter of opencv-python

denoised_img = sdf.Denoise(img, kernel=(3,3), channels=0)

kernel: default ($3,3$)

channels: $3$ for an RGB/BGR image and $0$ for a grayscale image

14. SurfacePorosity() calculates the ratio in percentage of area covered by pores to the total area

porosity = sdf.SurfacePorosity(img, contour_area)

contour_area: a float or an integer


Acknowledgement | Dependencies

  1. opencv-python
  2. numpy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SurfaceDefects-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SurfaceDefects-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file SurfaceDefects-0.1.0.tar.gz.

File metadata

  • Download URL: SurfaceDefects-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for SurfaceDefects-0.1.0.tar.gz
Algorithm Hash digest
SHA256 db876b62a29d6b7416fe00377d649adb38f9d2b998a9f0f3be159592d0d0829d
MD5 d99d452fa6963aced8ae0b4f246d00fa
BLAKE2b-256 55ed194b6ab1e931cd26c9db23dba0e7a894ce9f15bc6fd96ae253c2cde4aa8a

See more details on using hashes here.

File details

Details for the file SurfaceDefects-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: SurfaceDefects-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for SurfaceDefects-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 057fce5f6211ebbc388ff157b5fb1247853adc4901eb3673843d35da4637a149
MD5 7d22326de45b3ed96490b96bdcbd579e
BLAKE2b-256 60816b1253c68fdb12a722055e50f0f9a0dfbf18733c8beff5e45b7163efb7b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page