fix python parsing, update deps
python parsing was broken & openai changed their internal API
This commit is contained in:
@@ -1,58 +1,101 @@
|
||||
# Documentation for `example_code.py`
|
||||
# Documentation for `example/example_code.py`
|
||||
|
||||
## `remove_dirt(image)`
|
||||
This function removes small dirt and noise from a binary image by closing small holes and removing small objects.
|
||||
This function removes small elements from an image using area closing morphological operation.
|
||||
|
||||
Here is an example of how to use the function:
|
||||
Example:
|
||||
|
||||
```
|
||||
import skimage.morphology as morphology
|
||||
from skimage import data
|
||||
# Import the required module
|
||||
from skimage import morphology
|
||||
|
||||
# Load a binary image
|
||||
image = data.coins() > 100
|
||||
# Load the image
|
||||
image = skimage.io.imread('image.jpg')
|
||||
|
||||
# Remove dirt from the image
|
||||
cleaned_image = remove_dirt(image)
|
||||
# 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)
|
||||
```
|
||||
|
||||
## `center_of_mass(X)`
|
||||
This function calculates the center of mass of a 2D shape defined by a set of points.
|
||||
This function calculates the center of mass of a set of points.
|
||||
|
||||
Here is an example of how to use the function:
|
||||
Example:
|
||||
|
||||
```
|
||||
import numpy as np
|
||||
|
||||
# Define a set of points that define a shape
|
||||
X = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
|
||||
# Define a set of points
|
||||
X = np.array([[1,2], [3,4], [5,6]])
|
||||
|
||||
# Calculate the center of mass of the shape
|
||||
center_of_mass = center_of_mass(X)
|
||||
# Calculate the center of mass of the points
|
||||
center = center_of_mass(X)
|
||||
|
||||
# Print the center of mass
|
||||
print(center_of_mass)
|
||||
# Print the result
|
||||
print('Center of mass:', center)
|
||||
```
|
||||
|
||||
The output will be `[0.5, 0.5]`, which is the coordinates of the center of the square defined by the points `X`.
|
||||
The output will be `Center of mass: [3. 4.]`.
|
||||
|
||||
## `center_of_mass(X)`
|
||||
This function calculates the center of mass of a 2D shape defined by a set of points.
|
||||
This function calculates the center of mass of a set of points.
|
||||
|
||||
Here is an example of how to use the function:
|
||||
Example:
|
||||
|
||||
```
|
||||
import numpy as np
|
||||
|
||||
# Define a set of points that define a shape
|
||||
X = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
|
||||
# Define a set of points
|
||||
X = np.array([[1,2], [3,4], [5,6]])
|
||||
|
||||
# Calculate the center of mass of the shape
|
||||
center_of_mass = center_of_mass(X)
|
||||
# Calculate the center of mass of the points
|
||||
center = center_of_mass(X)
|
||||
|
||||
# Print the center of mass
|
||||
print(center_of_mass)
|
||||
# Print the result
|
||||
print('Center of mass:', center)
|
||||
```
|
||||
|
||||
The output will be `[0.5, 0.5]`, which is the coordinates of the center of the square defined by the points `X`.
|
||||
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)
|
||||
```
|
||||
|
||||
|
||||
@@ -4,12 +4,14 @@ def remove_dirt(image):
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def calculate_area(countour):
|
||||
c = np.expand_dims(countour.astype(np.float32), 1)
|
||||
c = cv.UMat(c)
|
||||
|
||||
|
||||
return cv.contourArea(c)
|
||||
|
||||
|
||||
def center_of_mass(X):
|
||||
x = X[:,0]
|
||||
y = X[:,1]
|
||||
@@ -22,6 +24,7 @@ def center_of_mass(X):
|
||||
|
||||
img = remove_dirt(thresh_gray)
|
||||
|
||||
|
||||
def rg_ratio_normalize(imgarr):
|
||||
# set max & min to most extreme values,
|
||||
# work up & down respectively from there
|
||||
|
||||
Reference in New Issue
Block a user