Skip to content

docs: fix angle direction description in graycomatrix (Fixes #7919) - #7980

Open
samay2504 wants to merge 2 commits into
scikit-image:pre-megamove-integrationfrom
samay2504:fix/skimage-7919-graycomatrix-doc
Open

samay2504 wants to merge 2 commits into
scikit-image:pre-megamove-integrationfrom
samay2504:fix/skimage-7919-graycomatrix-doc

Conversation

@samay2504

Copy link
Copy Markdown

Description

Checklist

Release note

For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.

...

Copilot AI review requested due to automatic review settings December 5, 2025 18:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect angle direction descriptions in the graycomatrix function documentation. The original documentation incorrectly described angle directions in mathematical coordinates instead of image coordinates (where rows increase downward).

Key Changes:

  • Clarifies that angles are measured counter-clockwise from the positive x-axis
  • Corrects angle descriptions for image coordinates where rows increase downward
  • Adds explicit examples showing that π/4 radians refers to the bottom-right diagonal neighbor (not top-right) and π/2 radians refers to the pixel below (not above)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@samay2504
samay2504 force-pushed the fix/skimage-7919-graycomatrix-doc branch from 3e957a3 to 1e8252c Compare December 5, 2025 19:03
pi/4 radians to the top-right diagonal neighbor; pi/2 radians to the pixel
above, and so forth.
Compute 4 GLCMs using 1-pixel distance and 4 different angles. Angles are
measured counter-clockwise from the positive x-axis (horizontal right).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If really there is a mistake and what's below (lines 82--85) is right, then the above sentence isn't helpful at all---it's misleading. I'm tempted to just close this PR, which didn't link to any issue and didn't provide any description.

@stefanv

stefanv commented Dec 9, 2025

Copy link
Copy Markdown
Member

@samay2504 Please provide some code to show the problem that the doc change is meant to address.

@stefanv

stefanv commented Dec 13, 2025

Copy link
Copy Markdown
Member

I've now done a test and can confirm that the documentation is wrong. @matthew-brett this will may be affected by the xy/ij transformation.

Here's the test:

In [51]: X = np.arange(9).reshape((3, 3)).astype(np.uint8)

In [52]: X
Out[52]: 
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]], dtype=uint8)

In [53]: P = ski.feature.graycomatrix(X, angles=[np.pi/4], distances=[1], levels=9)

In [54]: np.array(P.nonzero()).T
Out[54]: 
array([[0, 4, 0, 0],
       [1, 5, 0, 0],
       [3, 7, 0, 0],
       [4, 8, 0, 0]])

Each row of this result is [first element, second element, distance index, angle index].

As you can see, with an angle of pi/2, the matches found are all diagonal and downward.

I also suggest the following patch to clarify that theta is not an angle—rather it is theta_idx which is an index into the provided angles. Same for distance.

diff --git a/doc/tools/gitwash b/doc/tools/gitwash
--- a/doc/tools/gitwash
+++ b/doc/tools/gitwash
@@ -1 +1 @@
-Subproject commit 06d130ab98d78e5a831b32a6624cad2bc481cacd
+Subproject commit 06d130ab98d78e5a831b32a6624cad2bc481cacd-dirty
diff --git a/src/skimage/feature/texture.py b/src/skimage/feature/texture.py
index 200aca450..84c6ea259 100644
--- a/src/skimage/feature/texture.py
+++ b/src/skimage/feature/texture.py
@@ -19,7 +19,7 @@ def graycomatrix(image, distances, angles, levels=None, symmetric=False, normed=
     grayscale values at a given offset over an image.
 
     .. versionchanged:: 0.19
-               `greymatrix` was renamed to `graymatrix` in 0.19.
+       `greycomatrix` was renamed to `graycomatrix` in 0.19.
 
     Parameters
     ----------
@@ -39,25 +39,26 @@ def graycomatrix(image, distances, angles, levels=None, symmetric=False, normed=
         be preferable to use binning of the input image rather than
         large values for `levels`.
     symmetric : bool, optional
-        If True, the output matrix `P[:, :, d, theta]` is symmetric. This
-        is accomplished by ignoring the order of value pairs, so both
-        (i, j) and (j, i) are accumulated when (i, j) is encountered
-        for a given offset. The default is False.
+        If True, the output matrix `P[:, :, d_idx, theta_idx]` is
+        symmetric. This is accomplished by ignoring the order of value
+        pairs, so both (i, j) and (j, i) are accumulated when (i, j)
+        is encountered for a given offset. The default is False.
     normed : bool, optional
-        If True, normalize each matrix `P[:, :, d, theta]` by dividing
-        by the total number of accumulated co-occurrences for the given
-        offset. The elements of the resulting matrix sum to 1. The
-        default is False.
+        If True, normalize each matrix `P[:, :, d_idx, theta_idx]` by
+        dividing by the total number of accumulated co-occurrences for
+        the given offset. The elements of the resulting matrix sum to
+        1. The default is False.
 
     Returns
     -------
     P : 4-D ndarray
         The gray-level co-occurrence histogram. The value
-        `P[i,j,d,theta]` is the number of times that gray-level `j`
-        occurs at a distance `d` and at an angle `theta` from
-        gray-level `i`. If `normed` is `False`, the output is of
-        type uint32, otherwise it is float64. The dimensions are:
-        levels x levels x number of distances x number of angles.
+        `P[i,j,d_idx,theta_idx]` is the number of times that
+        gray-level `j` occurs at a distance `distances[d_idx]` and at
+        an angle `angles[theta_idx]` from gray-level `i`. If `normed`
+        is `False`, the output is of type uint32, otherwise it is
+        float64. The dimensions are: levels x levels x number of
+        distances x number of angles.
 
     References
     ----------

@stefanv

stefanv commented Dec 13, 2025 •

Copy link
Copy Markdown
Member

Didn't spot the issue in the title there: this closes #7919

@github-actions

Copy link
Copy Markdown

Hello scikit-image core devs! There hasn't been any activity on this PR for more than 180 days. I have marked it as "dormant" to make it easy to find.

To our contributors, thank you for your contribution and apologies if this contribution fell through the cracks! Hopefully this ping will help bring some fresh attention to the review. If you need help, you can always reach out on our forum

If you think that this PR is no longer relevant, you may close it, or we may do it at some point (either way, it will be done manually). If you think the PR is valuable but you no longer have the bandwidth to update it, please let us know, so that someone can take it over. 🙏

@github-actions github-actions Bot added the 😴 Dormant No recent activity label Jun 12, 2026
matthew-brett added a commit to matthew-brett/scikit-image that referenced this pull request Jun 12, 2026
From: scikit-image#7980 - the
filter is redundant because we're already using pytest.warns for these.
@matthew-brett matthew-brett removed the 😴 Dormant No recent activity label Jun 12, 2026
@matthew-brett
matthew-brett changed the base branch from main to pre-megamove-integration June 19, 2026 19:57
@matthew-brett

Copy link
Copy Markdown
Contributor

We have changed the base branch for this PR from the main branch to the pre-megamove-integration branch.

Summary - what this means for your PR

You can continue to work on your PR, now based on pre-megamove-integration. You should update your branch to the current state of pre-megamove-integration (this is what the Github "Update branch" button does). Please do not merge the scikit-image main branch into your PR branch.

Once we've merged your PR into the pre-megamove-integration branch, we'll update your changes for Megamove, and merge into the main branch.

Read on for the rationale, and more detailed instructions.

Details

Rationale

We've changed the base branch to make it easier and smoother to continue to work on your PR, while we work through a rather large change in the directory structure of the repository - a change that we have called Megamove.

See the Megamove explanation issue for more detail.

Changing the base branch means you do not see merge conflicts related to the Megamove change, and can continue to work with the repository in its original state, without worrying about porting those changes across to the new post-Megamove structure.

As you'll see in the linked issue, you can continue to work on your PR as before, and you can continue to use the Github GUI to "Update branch" - this updates from the new pre-megamove-integration branch. However, there is one caveat: please, do not try and merge the scikit-image main branch into this one, but instead, keep track of the pre-megamove-integration branch. The issue explains more.

To emphasize again, do not try and merge the scikit-image main branch. You will get Megamove related merge conflicts that are rather tricky to resolve correctly.

When we've approved your PR, we'll merge into the pre-megamove-integration branch, and then process it so we can merge it into the main branch. We'll let you know when we've merged your PR changes into main.

Any questions, please reply here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants