-
-
Notifications
You must be signed in to change notification settings - Fork 46.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Texture analysis using Haralick Descriptors for Computer Vision tasks #8004
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
||
|
||
def normalize_image( | ||
image: np.ndarray, cap: float = 255.0, data_type=np.uint8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide type hint for the parameter: data_type
return np.where(image > threshold, 1, 0) | ||
|
||
|
||
def transform(image: np.ndarray, kind: str, kernel=None) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide type hint for the parameter: kernel
return true_mask, false_mask | ||
|
||
|
||
def matrix_concurrency(image: np.ndarray, coordinate) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/haralick_descriptors.py
, please provide doctest for the function matrix_concurrency
Please provide type hint for the parameter: coordinate
return matrix / np.sum(matrix) | ||
|
||
|
||
def haralick_descriptors(matrix: np.ndarray) -> list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/haralick_descriptors.py
, please provide doctest for the function haralick_descriptors
] | ||
|
||
|
||
def get_descriptors(masks: tuple[np.ndarray, np.ndarray], coordinate) -> np.ndarray: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/haralick_descriptors.py
, please provide doctest for the function get_descriptors
Please provide type hint for the parameter: coordinate
return np.sqrt(np.sum(np.square(point_1 - point_2))) | ||
|
||
|
||
def get_distances(descriptors, base) -> list[Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file computer_vision/haralick_descriptors.py
, please provide doctest for the function get_distances
Please provide type hint for the parameter: descriptors
Please provide type hint for the parameter: base
return sorted(enumerate(distances), key=lambda tup: tup[1]) | ||
|
||
|
||
def main(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: main
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file computer_vision/haralick_descriptors.py
, please provide doctest for the function main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
return sorted(enumerate(distances), key=lambda tup: tup[1]) | ||
|
||
|
||
def main(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: main
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file computer_vision/haralick_descriptors.py
, please provide doctest for the function main
Does the main require a doctest as well? gezz... |
for more information, see https://pre-commit.ci
@cclauss Awaiting review 😁 |
@cclauss Any insights yet? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay - Pr looks good to me, awesome work!
@cclauss Could you review please
@@ -1,5 +1,6 @@ | |||
beautifulsoup4 | |||
fake_useragent | |||
imageio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure that imageio/imageio#916 is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on how you plan to use ImageIO, I'd recommend using imageio<3.0
or imageio<4.0
instead. We will release v3.0 around the end of January which will remove deprecations. Pinning up to the next version major avoids your code breaking once that happens and puts you in charge of when/how to upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are a bit different than most repos. In general, we do not pin dependencies because we are not shipping an executable (app or library) and our individual algorithms are almost always self-standing. We hope that tests catch incompatibilities so that they can be fixed as they break. If not then users can report failures so we fix-as-we-go.
No! What if the Kernel is empty? Example: >>> kernel = np.zeros((1)) >>> kernel or np.ones((3, 3)) array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]) Co-authored-by: Christian Clauss <cclauss@me.com>
Awaiting merge :) |
array([[158, 97], | ||
[ 56, 200]], dtype=uint8) | ||
""" | ||
return np.dot(image[:, :, 0:3], [0.299, 0.587, 0.114]).astype(np.uint8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include a source (e.g., Wikipedia) for those luminance weight values?
def transform(image: np.ndarray, kind: str, kernel: np.ndarray = None) -> np.ndarray: | ||
""" | ||
Simple image transformation using one of two available filter functions: | ||
Erosion and Dilation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have digital_image_processing/morphological_operations/erosion_operation.py and digital_image_processing/morphological_operations/dilation_operation.py. Can we use those two files to replace this function in the future?
index = int(input()) | ||
q_value = [int(value) for value in input().split()] | ||
|
||
# Format is the respective filter to apply, | ||
# can be either 1 for the opening filter or else for the closing | ||
parameters = {"format": int(input()), "threshold": int(input())} | ||
|
||
# Number of images to perform methods on | ||
b_number = int(input()) | ||
|
||
files, descriptors = ([], []) | ||
|
||
for _ in range(b_number): | ||
file = input().rstrip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have prompt messages for each of the input
calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still some minor issues, but the major ones have been addressed.
…TheAlgorithms#8004) * Create haralick_descriptors * Working on creating Unit Testing for Haralick Descriptors module * Type hinting for Haralick descriptors * Fixed docstrings, unit testing and formatting choices * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed line size formatting * Added final doctests * Changed main callable * Updated requirements.txt * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update computer_vision/haralick_descriptors.py No! What if the Kernel is empty? Example: >>> kernel = np.zeros((1)) >>> kernel or np.ones((3, 3)) array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]) Co-authored-by: Christian Clauss <cclauss@me.com> * Undone wrong commit * Update haralick_descriptors.py * Apply suggestions from code review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix ruff errors in haralick_descriptors.py * Add type hint to haralick_descriptors.py to fix ruff error * Update haralick_descriptors.py * Update haralick_descriptors.py * Update haralick_descriptors.py * Update haralick_descriptors.py * Try to fix mypy errors in haralick_descriptors.py * Update haralick_descriptors.py * Fix type hint in haralick_descriptors.py --------- Co-authored-by: Rafael Zimmer <rzimmerdev@monmo.localdomain> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Describe your change:
I've added a series of methods for calculating the Haralick descriptors, as well as some encapsulating methods for comparing textures between a baseline image and a sequence of comparison images.
Checklist:
Fixes: #{$ISSUE_NO}
.