Skip to content

Texture analysis using Haralick Descriptors for Computer Vision tasks #8004

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

Merged
merged 28 commits into from
Sep 5, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
802cd20
Create haralick_descriptors
rzimmerdev Oct 19, 2022
88b014f
Working on creating Unit Testing for Haralick Descriptors module
Oct 19, 2022
bc6a189
Type hinting for Haralick descriptors
Oct 19, 2022
dff5498
Merge branch 'TheAlgorithms:master' into master
rzimmerdev Nov 27, 2022
6e23cc0
Fixed docstrings, unit testing and formatting choices
rzimmerdev Nov 27, 2022
eca7118
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 27, 2022
9d2cca7
Fixed line size formatting
rzimmerdev Nov 27, 2022
cd250cf
Merge remote-tracking branch 'origin/master'
rzimmerdev Nov 27, 2022
5e73aa6
Added final doctests
rzimmerdev Nov 27, 2022
aacb27e
Changed main callable
rzimmerdev Nov 27, 2022
5fb933d
Updated requirements.txt
rzimmerdev Nov 27, 2022
c9ec63e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 27, 2022
bfd0fd7
Update computer_vision/haralick_descriptors.py
rzimmerdev Dec 13, 2022
6f52bff
Undone wrong commit
rzimmerdev Dec 13, 2022
ca90e9a
Merge branch 'TheAlgorithms:master' into master
rzimmerdev Dec 19, 2022
408b0fb
Merge branch 'TheAlgorithms:master' into master
rzimmerdev Dec 20, 2022
fc2fa0b
Update haralick_descriptors.py
rzimmerdev Dec 20, 2022
40da555
Apply suggestions from code review
tianyizheng02 Sep 5, 2023
ba2f474
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 5, 2023
9faef36
Fix ruff errors in haralick_descriptors.py
tianyizheng02 Sep 5, 2023
7eda2b8
Add type hint to haralick_descriptors.py to fix ruff error
tianyizheng02 Sep 5, 2023
fd085df
Update haralick_descriptors.py
tianyizheng02 Sep 5, 2023
40daa68
Update haralick_descriptors.py
tianyizheng02 Sep 5, 2023
8da35eb
Update haralick_descriptors.py
tianyizheng02 Sep 5, 2023
5795fc4
Update haralick_descriptors.py
tianyizheng02 Sep 5, 2023
44d6bd1
Try to fix mypy errors in haralick_descriptors.py
tianyizheng02 Sep 5, 2023
21efc62
Update haralick_descriptors.py
tianyizheng02 Sep 5, 2023
5fa7520
Fix type hint in haralick_descriptors.py
tianyizheng02 Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Type hinting for Haralick descriptors
  • Loading branch information
Rafael Zimmer committed Oct 19, 2022
commit bc6a1894f84173910e95ba8544ca64f42788970c
22 changes: 11 additions & 11 deletions computer_vision/haralick_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def normalize_image(image: np.ndarray, cap: float = 255) -> np.ndarray:
return normalized.astype(np.uint8)


def normalize_array(array, cap: float = 1):
def normalize_array(array: np.ndarray, cap: float = 1) -> np.ndarray:
"""Normalizes a 1D array, between ranges 0-cap.

Args:
Expand All @@ -55,7 +55,7 @@ def grayscale(image: np.ndarray) -> np.ndarray:
return np.dot(image[:, :, 0:3], [0.299, 0.587, 0.114]).astype(np.uint8)
Copy link
Contributor

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 binarize(image, threshold_value):
def binarize(image: np.ndarray, threshold_value) -> np.ndarray:
"""
Binarizes a grayscale image based on a given threshold value,
setting values to 1 or 0 accordingly.
Expand All @@ -65,7 +65,7 @@ def binarize(image, threshold_value):
return binarized


def transform(image, kind, kernel=None):
def transform(image: np.ndarray, kind, kernel=None) -> np.ndarray:
"""
Simple image transformation using one of two available filter functions:
Erosion and Dilation.
Expand Down Expand Up @@ -108,7 +108,7 @@ def transform(image, kind, kernel=None):
return transformed


def opening_filter(image, kernel=None):
def opening_filter(image: np.ndarray, kernel: np.ndarray = None) -> np.ndarray:
"""
Opening filter, defined as the sequence of
erosion and then a dilation filter on the same image.
Expand All @@ -119,7 +119,7 @@ def opening_filter(image, kernel=None):
return transform(transform(image, "dilation", kernel), "erosion", kernel)


def closing_filter(image, kernel=None):
def closing_filter(image: np.ndarray, kernel: np.ndarray = None) -> np.ndarray:
"""
Opening filter, defined as the sequence of
dilation and then erosion filter on the same image.
Expand All @@ -130,7 +130,7 @@ def closing_filter(image, kernel=None):
return transform(transform(image, "erosion", kernel), "dilation", kernel)


def binary_mask(image_gray, image_map):
def binary_mask(image_gray: np.ndarray, image_map: np.ndarray) -> np.ndarray:
"""
Apply binary mask, or thresholding based
on bit mask value (mapping mask is 1 or 0).
Expand All @@ -144,7 +144,7 @@ def binary_mask(image_gray, image_map):
return true_mask, false_mask


def matrix_concurrency(image, coordinate):
def matrix_concurrency(image: np.ndarray, coordinate) -> np.ndarray:

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

"""
Calculate sample co-occurrence matrix based on input image
as well as selected coordinates on image.
Expand All @@ -166,7 +166,7 @@ def matrix_concurrency(image, coordinate):
return matrix / np.sum(matrix)


def haralick_descriptors(matrix):
def haralick_descriptors(matrix: np.ndarray) -> list:

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

"""Calculates all 8 Haralick descriptors based on co-occurence input matrix.
All descriptors are as follows:
Maximum probability, Inverse Difference, Homogeneity, Entropy,
Expand Down Expand Up @@ -213,7 +213,7 @@ def haralick_descriptors(matrix):
return descriptors


def get_descriptors(masks, coordinate):
def get_descriptors(masks, coordinate) -> np.ndarray:
"""
Calculate all Haralick descriptors for a sequence of
different co-occurrence matrices, given input masks and coordinates.
Expand All @@ -227,15 +227,15 @@ def get_descriptors(masks, coordinate):
return np.concatenate(descriptors, axis=None)


def euclidean(point_1: np.ndarray, point_2: np.ndarray):
def euclidean(point_1: np.ndarray, point_2: np.ndarray) -> np.float32:
"""
Simple method for calculating the euclidean distance between two points,
with type np.ndarray.
"""
return np.sqrt(np.sum(np.square(point_1 - point_2)))


def get_distances(descriptors, base):
def get_distances(descriptors, base) -> np.ndarray:
"""
Calculate all Euclidean distances between a selected base descriptor
and all other Haralick descriptors
Expand Down