changes
This commit is contained in:
58
example/example_code-doc.md
Normal file
58
example/example_code-doc.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# Documentation for `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.
|
||||
|
||||
Here is an example of how to use the function:
|
||||
|
||||
```
|
||||
import skimage.morphology as morphology
|
||||
from skimage import data
|
||||
|
||||
# Load a binary image
|
||||
image = data.coins() > 100
|
||||
|
||||
# Remove dirt from the image
|
||||
cleaned_image = remove_dirt(image)
|
||||
```
|
||||
|
||||
## `center_of_mass(X)`
|
||||
This 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 function:
|
||||
|
||||
```
|
||||
import numpy as np
|
||||
|
||||
# Define a set of points that define a shape
|
||||
X = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
|
||||
|
||||
# Calculate the center of mass of the shape
|
||||
center_of_mass = center_of_mass(X)
|
||||
|
||||
# Print the center of mass
|
||||
print(center_of_mass)
|
||||
```
|
||||
|
||||
The output will be `[0.5, 0.5]`, which is the coordinates of the center of the square defined by the points `X`.
|
||||
|
||||
## `center_of_mass(X)`
|
||||
This 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 function:
|
||||
|
||||
```
|
||||
import numpy as np
|
||||
|
||||
# Define a set of points that define a shape
|
||||
X = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
|
||||
|
||||
# Calculate the center of mass of the shape
|
||||
center_of_mass = center_of_mass(X)
|
||||
|
||||
# Print the center of mass
|
||||
print(center_of_mass)
|
||||
```
|
||||
|
||||
The output will be `[0.5, 0.5]`, which is the coordinates of the center of the square defined by the points `X`.
|
||||
|
||||
62
example/example_code.py
Normal file
62
example/example_code.py
Normal file
@@ -0,0 +1,62 @@
|
||||
def remove_dirt(image):
|
||||
image = morphology.area_closing(image, area_threshold=250, connectivity=1)
|
||||
# image = morphology.opening(image, morphology.square(5))
|
||||
|
||||
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]
|
||||
g = (x[:-1]*y[1:] - x[1:]*y[:-1])
|
||||
A = 0.5*g.sum()
|
||||
cx = ((x[:-1] + x[1:])*g).sum()
|
||||
cy = ((y[:-1] + y[1:])*g).sum()
|
||||
|
||||
return 1./(6*A)*np.array([cx,cy])
|
||||
|
||||
img = remove_dirt(thresh_gray)
|
||||
|
||||
def rg_ratio_normalize(imgarr):
|
||||
# set max & min to most extreme values,
|
||||
# work up & down respectively from there
|
||||
tmin = MAX_TEMP
|
||||
tmax = 0
|
||||
|
||||
imgnew = imgarr
|
||||
for i in range(len(imgarr)):
|
||||
for j in range(len(imgarr[i])):
|
||||
px = imgarr[i][j]
|
||||
r_norm = normalization_func(px[0])
|
||||
g_norm = normalization_func(px[1])
|
||||
|
||||
# apply camera calibration func
|
||||
temp_C = pyrometry_calibration_formula(g_norm, r_norm)
|
||||
|
||||
# remove pixels outside calibration range
|
||||
if MAX_TEMP != None and temp_C > MAX_TEMP or MIN_TEMP != None and temp_C < MIN_TEMP:
|
||||
temp_C = 0
|
||||
|
||||
# update min & max
|
||||
if temp_C < tmin and temp_C >= 0:
|
||||
tmin = temp_C
|
||||
if temp_C > tmax:
|
||||
tmax = temp_C
|
||||
|
||||
imgnew[i][j] = [temp_C, temp_C, temp_C]
|
||||
return imgnew, tmin, tmax
|
||||
|
||||
|
||||
def pyrometry_calibration_formula(i_ng, i_nr):
|
||||
return 362.73 * math.log10(
|
||||
(i_ng/i_nr) ** 3
|
||||
) + 2186.7 * math.log10(
|
||||
(i_ng/i_nr) ** 2
|
||||
) + 4466.5 * math.log10(
|
||||
(i_ng / i_nr)
|
||||
) + 3753.5
|
||||
Reference in New Issue
Block a user