Image manipulation functionality
Here are implemented functions for performing various image manipulations
get_common_value(v, axis=0)
Calculate initial most common value of the given array with given axis
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v |
ndarray
|
input vector |
required |
axis |
int
|
axis to calculate value |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
common_value |
Union[float, ndarray]
|
|
Source code in src/tools/processing.py
calculate_normalize_difference(x, y)
Calculate norm of the difference x/n-y/n, where n is the length of the vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
ndarray
|
first array |
required |
y |
ndarray
|
second array |
required |
Returns:
| Name | Type | Description |
|---|---|---|
normalized_difference |
float
|
resulting distance |
Source code in src/tools/processing.py
need_to_trim(img, direction, initial_thresh=10)
Check, whatever the given direction(t,b,l,r) is need to be trimmed (cropped). Function compares the norm of dummy vector and actual vector of pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img |
ndarray
|
input image |
required |
direction |
str
|
given direction (t,b,l,r) |
required |
initial_thresh |
float
|
identification thresh |
10
|
Returns:
| Type | Description |
|---|---|
flag, initial_vector, blank_vector, to_iter : bool, np.ndarray, np.ndarray, range
|
|
Source code in src/tools/processing.py
trim_image_with_thresh(img, norm_thresh=5000, initial_thresh=10, c_contiguous=True)
Perform image trimming operation for all the directions. For each direction (t,b,l,r) function checks if trimming is necessary and performs image cropping. Function is robust regarding different background colors and small watermarks in the background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img |
ndarray
|
input image |
required |
norm_thresh |
float
|
norm threshold to consider vectors the same |
5000
|
initial_thresh |
float
|
identification thresh |
10
|
c_contiguous |
bool
|
true for converting out array to c_contiguous |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
ndarray
|
out image |