Repository navigation
Add support for y-dimensional shear to the AffineTransform - #6752
Conversation
|
@i-aki-y Thank you for this contribution, and for the fantastically detailed write-up! 🙏 We are currently in feature freeze until the next release comes out (probably end of this week or Monday). I hope that we can integrate your contribution as one of the first for the 0.21 development cycle! |
|
Needs an update based on recently marged changes by @i-aki-y. |
|
@stefanv I have updated. |
|
Thank you so much @i-aki-y! This closes an issue (#1779) from 2015! 😊 Concerning your suggestion to deprecate the attributes Long-term, we should really think about where we want the API to go. That discussion should probably continue elsewhere, e.g. in #2397? |
|
@stefanv @lagru Thank you for your time.
Sure, it depends on how the users use these properties. If there exists a usecase in which these properties are helpful, it would still be meaningful. |
# Description This MR ports several recent changes implemented upstream in scikit-image 0.21rc0. Some are just minor refactoring or documentation fixes, but I have commented on the more significant changes below so we can reuse that for the release note. If preferred, I can split the items below into separate small PRs. ## API Changes / Deprecations - The `random_state` argument of `medial_axis` and `unsupervised_wiener` is now deprecated and will be removed in the future. The new argument name, `seed`, should be used instead. - The formerly private function `_invariant_denoise` has been renamed `denoise_invariant` and is now part of the public `cucim.skimage.restoration` API. - The existing function `cucim.skimage.color.get_xyz_coords` has been renamed `cucim.skimage.color.xyz_tristimulus_values`. The former function name is deprecated and will be removed in the future. ## Enhancements - A new `return_mapping` option was added to `join_segmentations`. This provides an additional output with a mapping between the labels in the joined segmentation and the original ones. - Added support for y-axis shear to the [2D AffineTransform](scikit-image/scikit-image#6752) ## Backwards Incompatible Changes - A bug fix to the energy calculation in `chan_vese` may result in different output from previous versions. ## Bug Fixes - Fixed [bug in energy calculation in Chan-Vese](scikit-image/scikit-image#6902) - Fixed a [bug in 2D shear calculations for `AffineTransform`](scikit-image/scikit-image#6717) Authors: - Gregory Lee (https://github.com/grlee77) - https://github.com/jakirkham Approvers: - Gigon Bae (https://github.com/gigony) URL: #573
Description
Closes #1779, closes #3548
(This PR is based on the other PR #6717; sorry, I am not sure how to compare different PRs on GitHub. This shows the two PR's diffs. If needed, I will rebase if the previous PR #6717 could be approved).
In this PR, I added support for a list-like shear argument to the AffineTransform.
The current implementation supports only the x-dimensional shear parameter, and the y-dimensional shear is a missing feature (#1779, #3548, #1975).
With this PR, the constructor supports scaler and list-like values as a shear argument.
If the
shearis a scaler, it is interpreted as a tuple of an x-dimensional only to maintain backward compatibility.Including the
shear_yargument, the equation of the transformation is modified in the following ways:Some results will be:
Important Note
With this slight modification, I found that the properties
self.scale, self.rotation, self.shear, self.translationbecome meaning less. I want to conclude we should make these properties deprecated in the future.This example shows what I want to say:
In this example, we could create the same transformations with different arguments. We can not tell what value the
trans1.rotationshould return in such a case.I think this is a theoretical limitation instead of an implementation bug. See the discussion below.
Discussion of a relation between properties and matrix elements
The current AffineTransform class has the following properties:
self.scale,self.rotation,self.shear,self.translation. These are re-calculated from the matrix elements. We can explicitly show how these values are calculated.First, I define the elements of the matrix and the related arguments. A matrix of 2D affine transform can be written in the following form:
where
The$R_\theta, H_{\phi_x, \phi_y}, S_{sx, sy}$ are matrices of rotate, shear, and scale transformations, and $t$ is a translation vector.
Note we can define different forms with the other matrix orders like$S_{s_x, s_y} R_\theta H_{\phi_x, \phi_y}$ . Here, I selected the above definition because it matches the current implementation.
I will focus on the relation between the matrix$M$ and the parameters $s_x, s_y, \theta, ...$ . With the above notations, we can write the $s_x, s_y, \theta, ...$ as a function of the matrix elements $M_{i, j}$ :
An important remark is that the solution to these equations is not unique! Because the number of parameters (= 5 = 2 scales + 2 shears + 1 rotation) is larger than the number of the 2x2 matrix elements (= 4).$u \in (-\pi/2 \lt u \lt \pi/2)$ ,
The solutions are given as a function of a free parameter:
By changing the$u$ , we can get arbitrary many solutions $s_x, s_y, \phi_x, ...$ , which make the same Affine transformation. This means we can not tell the value that the $t_x, t_y$ because we can make complex transformations by combining multiple transformations $t_x, t_y$ and other properties. And then we can make similar equations to the eq.(1)-(4) including $t_x, t_y$ .
self.scaleshould return. The same discussion could be applied to the translationsAffineTransform(...) + AffineTransform(...) + ..., which mixesAppendix
I will show detailed derivations of eq.(1) and (3).
(eq.(2) and (4) are almost the same as the eq.(1) and (3))
For eq.(1):
Solving this by$s_x$ , we can get eq.(1).
For eq.(3):
Applying arctan to both sides yields eq.(3).
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.example, to backport to v0.19.x after merging, add the following in a PR
comment:
@meeseeksdev backport to v0.19.xrun-benchmarklabel. To rerun, the labelcan be removed and then added again. The benchmark output can be checked in
the "Actions" tab.
Update 2023.3.16: Added equation numbers (1) - (4).