docugen/example/example_code-doc.md

95 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

# Documentation for `example/example_code.py`
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
### `remove_dirt(image)`
The `remove_dirt` function removes small objects from the input image using area closing. Here is an example of how to use the `remove_dirt` function:
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
```python
import skimage.morphology as morphology
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
# Load an image using some library (e.g. Pillow, OpenCV, etc.)
image = ...
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
# Remove small objects from the image
image = remove_dirt(image)
```
2022-12-07 01:17:40 -08:00
### `calculate_area(countour)`
The `calculate_area` function calculates the area of a contour in an image using OpenCV. Here is an example of how to use the `calculate_area` function:
2022-12-07 01:17:40 -08:00
```python
import numpy as np
2022-12-07 01:17:40 -08:00
import cv2 as cv
2022-12-07 01:17:40 -08:00
# Load an image using some library (e.g. Pillow, OpenCV, etc.)
image = ...
2022-12-07 01:17:40 -08:00
# Find contours in the image using OpenCV
contours = cv.findContours(image, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)
# Calculate the area of each contour
for contour in contours:
area = calculate_area(contour)
2022-12-07 01:17:40 -08:00
print(area)
2022-12-05 20:25:34 -08:00
```
2022-12-07 01:17:40 -08:00
### `center_of_mass(X)`
The `center_of_mass` function calculates the center of mass of a 2D shape defined by a set of points. Here is an example of how to use the `center_of_mass` function:
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
```python
2022-12-05 20:25:34 -08:00
import numpy as np
2022-12-07 01:17:40 -08:00
# Define a set of points that define a shape
X = np.array([[0,0], [0,1], [1,1], [1,0]])
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
# Calculate the center of mass of the shape
com = center_of_mass(X)
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
# Print the center of mass
print(com)
2022-12-05 20:25:34 -08:00
```
2022-12-07 01:17:40 -08:00
In this example, the output would be `[0.5, 0.5]`, which is the center of the square defined by the points `X`.
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
### `center_of_mass(X)`
The `center_of_mass` function calculates the center of mass of a 2D shape defined by a set of points. Here is an example of how to use the `center_of_mass` function:
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
```python
2022-12-05 20:25:34 -08:00
import numpy as np
2022-12-07 01:17:40 -08:00
# Define a set of points that define a shape
X = np.array([[0,0], [0,1], [1,1], [1,0]])
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
# Calculate the center of mass of the shape
com = center_of_mass(X)
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00
# Print the center of mass
print(com)
2022-12-05 20:25:34 -08:00
```
2022-12-07 01:17:40 -08:00
In this example, the output would be `[0.5, 0.5]`, which is the center of the square defined by the points `X`.
2022-12-07 01:17:40 -08:00
### `rg_ratio_normalize(imgarr)`
The `rg_ratio_normalize` function applies a normalization function to the red and green channels of a 2D image, then applies a camera calibration formula to the resulting normalized values and returns the resulting image. Here is an example of how to use the `rg_ratio_normalize` function:
2022-12-07 01:17:40 -08:00
```python
import numpy as np
2022-12-07 01:17:40 -08:00
# Load an image using some library (e.g. Pillow, OpenCV, etc.)
image = ...
# Convert the image to a NumPy array
imgarr = np.array(image)
2022-12-07 01:17:40 -08:00
# Apply the normalization and calibration to the image
imgnew, tmin, tmax = rg_ratio_normalize(imgarr)
2022-12-07 01:17:40 -08:00
# Print the minimum and maximum temperature values in the image
print(tmin, tmax)
```
2022-12-05 20:25:34 -08:00
2022-12-07 01:17:40 -08:00