2022-12-06 17:35:18 -08:00
|
|
|
# Documentation for `example/example_code.py`
|
2022-12-05 20:25:34 -08:00
|
|
|
|
|
|
|
## `remove_dirt(image)`
|
2022-12-06 17:35:18 -08:00
|
|
|
This function removes small elements from an image using area closing morphological operation.
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
Example:
|
2022-12-05 20:25:34 -08:00
|
|
|
|
|
|
|
```
|
2022-12-06 17:35:18 -08:00
|
|
|
# Import the required module
|
|
|
|
from skimage import morphology
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Load the image
|
|
|
|
image = skimage.io.imread('image.jpg')
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Apply the function to remove small elements from the image
|
|
|
|
image = remove_dirt(image)
|
|
|
|
|
|
|
|
# Show the result
|
|
|
|
skimage.io.imshow(image)
|
|
|
|
```
|
|
|
|
|
|
|
|
## `calculate_area(countour)`
|
|
|
|
This function calculates the area of a contour in an image.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Import the required modules
|
|
|
|
import cv2 as cv
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
# Load the image and find the contours
|
|
|
|
image = cv.imread('image.jpg')
|
|
|
|
contours, _ = cv.findContours(image, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
|
|
|
|
|
|
|
|
# Iterate over the contours and calculate their areas
|
|
|
|
for contour in contours:
|
|
|
|
area = calculate_area(contour)
|
|
|
|
print('Area of contour:', area)
|
2022-12-05 20:25:34 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
## `center_of_mass(X)`
|
2022-12-06 17:35:18 -08:00
|
|
|
This function calculates the center of mass of a set of points.
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
Example:
|
2022-12-05 20:25:34 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
import numpy as np
|
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Define a set of points
|
|
|
|
X = np.array([[1,2], [3,4], [5,6]])
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Calculate the center of mass of the points
|
|
|
|
center = center_of_mass(X)
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Print the result
|
|
|
|
print('Center of mass:', center)
|
2022-12-05 20:25:34 -08:00
|
|
|
```
|
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
The output will be `Center of mass: [3. 4.]`.
|
2022-12-05 20:25:34 -08:00
|
|
|
|
|
|
|
## `center_of_mass(X)`
|
2022-12-06 17:35:18 -08:00
|
|
|
This function calculates the center of mass of a set of points.
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
Example:
|
2022-12-05 20:25:34 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
import numpy as np
|
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Define a set of points
|
|
|
|
X = np.array([[1,2], [3,4], [5,6]])
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Calculate the center of mass of the points
|
|
|
|
center = center_of_mass(X)
|
2022-12-05 20:25:34 -08:00
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
# Print the result
|
|
|
|
print('Center of mass:', center)
|
2022-12-05 20:25:34 -08:00
|
|
|
```
|
|
|
|
|
2022-12-06 17:35:18 -08:00
|
|
|
The output will be `Center of mass: [3. 4.]`.
|
|
|
|
|
|
|
|
## `rg_ratio_normalize(imgarr)`
|
|
|
|
This function normalizes the temperature values in an image array using the RG ratio and a pyrometry calibration formula.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Import the required modules
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
# Load the image array
|
|
|
|
imgarr = np.array(...)
|
|
|
|
|
|
|
|
# Normalize the temperature values in the image
|
|
|
|
imgnew, tmin, tmax = rg_ratio_normalize(imgarr)
|
|
|
|
|
|
|
|
# Print the resulting minimum and maximum temperature values
|
|
|
|
print('Minimum temperature:', tmin)
|
|
|
|
print('Maximum temperature:', tmax)
|
|
|
|
```
|
2022-12-05 20:25:34 -08:00
|
|
|
|