-
Notifications
You must be signed in to change notification settings - Fork 24
Add column / row wise normalization to imshow and pyrshow #49
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
Open
ershook
wants to merge
8
commits into
LabForComputationalVision:main
Choose a base branch
from
ershook:row_col_vrange
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+405
−91
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
741a0f9
Add column / row wise normalization to imshow and pyrshow
ershook e4f84e2
rewrote pyrshow -- updates to complex column plotting
ershook dd4f337
Merge branch 'main' of https://github.com/LabForComputationalVision/p…
ershook e0ece91
Updated colormaprange to be responsible for complex column handling
ershook 53a3aea
Update docs and unit tests
ershook 17f1fe4
add error for using indeprow/indepcol
ershook 2cb4986
fix spacing
ershook e7fb17a
update vrange docs to format correclty
ershook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| import matplotlib.pyplot as plt | ||
|
|
||
| import pyrtools as pt | ||
| from pyrtools.pyramids.pyramid import Pyramid | ||
| from pyrtools.tools.display import colormap_range | ||
|
|
||
| import scipy.io | ||
| import os | ||
|
|
@@ -1599,7 +1601,158 @@ def test_pyrshow_2d_shape_err(self): | |
| with self.assertRaises(ValueError): | ||
| pt.pyrshow(pyr.pyr_coeffs) | ||
|
|
||
|
|
||
| class TestVrange(unittest.TestCase): | ||
|
|
||
| def _get_clims(self, fig): | ||
| """get vmin vmax for each image in fig as list of tuples (vmin, vmax)""" | ||
| return [ax.images[0].get_clim() for ax in fig.axes if ax.images] | ||
|
|
||
| def _get_title_clims(self, fig): | ||
| """get vmin vmax for each image in fig as list of tuples (vmin, vmax)""" | ||
| clims = [] | ||
| for ax in fig.axes: | ||
| title = ax.get_title() | ||
| vmin, vmax = title.split('[')[1].split(']')[0].split(',') | ||
| clims.append((float(vmin.strip()), float(vmax.strip()))) | ||
| return clims | ||
|
|
||
| def _get_images(self): | ||
| # define test images such that each image has a different range of values, | ||
| # so we can test that the correct vrange is applied to each one | ||
| images = [np.arange(4 * i, 4 * i + 4, dtype=float).reshape(2, 2) for i in range(4)] | ||
| return images | ||
|
|
||
| def _imshow(self, vrange): | ||
| return pt.imshow(self._get_images(), vrange=vrange, zoom=1, col_wrap=2) | ||
|
|
||
| def _expected_clims(self, vrange): | ||
| clims, _ = colormap_range(image=self._get_images(), contains_rgb= [False]*len(self._get_images()), vrange=vrange, cmap=None, n_cols=2) | ||
| return clims | ||
|
|
||
| def test_global_vrange_all_images_share_clim(self): | ||
| for mode in range(4): | ||
| with self.subTest(mode=mode): | ||
| clims = self._get_clims(self._imshow(f"auto{mode}")) | ||
| self.assertTrue(all(c == clims[0] for c in clims)) | ||
|
|
||
| def test_global_vrange_vmin(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| vmin, _ = self._get_clims(self._imshow(f"auto{mode}"))[img_idx] | ||
| exp_vmin, _ = self._expected_clims(f"auto{mode}")[img_idx] | ||
| self.assertTrue(np.isclose(vmin, exp_vmin, atol=1e-6)) | ||
|
|
||
| def test_global_vrange_vmax(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| _, vmax = self._get_clims(self._imshow(f"auto{mode}"))[img_idx] | ||
| _, exp_vmax = self._expected_clims(f"auto{mode}")[img_idx] | ||
| self.assertTrue(np.isclose(vmax, exp_vmax, atol=1e-6)) | ||
|
|
||
| def test_global_vrange_title_matches_clim(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| fig = self._imshow(f"auto{mode}") | ||
| clim_vmin, clim_vmax = self._get_clims(fig)[img_idx] | ||
| title_vmin, title_vmax = self._get_title_clims(fig)[img_idx] | ||
| self.assertEqual("{:.1e}".format(clim_vmin), "{:.1e}".format(title_vmin)) | ||
| self.assertEqual("{:.1e}".format(clim_vmax), "{:.1e}".format(title_vmax)) | ||
|
|
||
| def test_row_vrange_same_row_shares_clim(self): | ||
| for mode in range(4): | ||
| with self.subTest(mode=mode): | ||
| clims = self._get_clims(self._imshow(f"auto{mode}row")) | ||
| self.assertEqual(clims[0], clims[1], "row 0 images differ") | ||
| self.assertEqual(clims[2], clims[3], "row 1 images differ") | ||
|
|
||
| def test_row_vrange_vmin(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| vmin, _ = self._get_clims(self._imshow(f"auto{mode}row"))[img_idx] | ||
| exp_vmin, _ = self._expected_clims(f"auto{mode}row")[img_idx] | ||
| self.assertTrue(np.isclose(vmin, exp_vmin, atol=1e-6)) | ||
|
|
||
| def test_row_vrange_vmax(self): | ||
|
Comment on lines
+1676
to
+1679
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same point about combining |
||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| _, vmax = self._get_clims(self._imshow(f"auto{mode}row"))[img_idx] | ||
| _, exp_vmax = self._expected_clims(f"auto{mode}row")[img_idx] | ||
| self.assertTrue(np.isclose(vmax, exp_vmax, atol=1e-6)) | ||
|
|
||
| def test_row_vrange_title_matches_clim(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| fig = self._imshow(f"auto{mode}row") | ||
| clim_vmin, clim_vmax = self._get_clims(fig)[img_idx] | ||
| title_vmin, title_vmax = self._get_title_clims(fig)[img_idx] | ||
| self.assertEqual("{:.1e}".format(clim_vmin), "{:.1e}".format(title_vmin)) | ||
| self.assertEqual("{:.1e}".format(clim_vmax), "{:.1e}".format(title_vmax)) | ||
|
|
||
| def test_col_vrange_same_col_shares_clim(self): | ||
| for mode in range(4): | ||
| with self.subTest(mode=mode): | ||
| clims = self._get_clims(self._imshow(f"auto{mode}col")) | ||
| self.assertEqual(clims[0], clims[2], "col 0 images differ") | ||
| self.assertEqual(clims[1], clims[3], "col 1 images differ") | ||
|
|
||
| def test_col_vrange_vmin(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| vmin, _ = self._get_clims(self._imshow(f"auto{mode}col"))[img_idx] | ||
| exp_vmin, _ = self._expected_clims(f"auto{mode}col")[img_idx] | ||
| self.assertTrue(np.isclose(vmin, exp_vmin, atol=1e-6)) | ||
|
|
||
| def test_col_vrange_vmax(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| _, vmax = self._get_clims(self._imshow(f"auto{mode}col"))[img_idx] | ||
| _, exp_vmax = self._expected_clims(f"auto{mode}col")[img_idx] | ||
| self.assertTrue(np.isclose(vmax, exp_vmax, atol=1e-6)) | ||
|
|
||
| def test_col_vrange_title_matches_clim(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| fig = self._imshow(f"auto{mode}col") | ||
| clim_vmin, clim_vmax = self._get_clims(fig)[img_idx] | ||
| title_vmin, title_vmax = self._get_title_clims(fig)[img_idx] | ||
| self.assertEqual("{:.1e}".format(clim_vmin), "{:.1e}".format(title_vmin)) | ||
| self.assertEqual("{:.1e}".format(clim_vmax), "{:.1e}".format(title_vmax)) | ||
|
|
||
| def test_indep_vrange_vmin(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| vmin, _ = self._get_clims(self._imshow(f"indep{mode}"))[img_idx] | ||
| exp_vmin, _ = self._expected_clims(f"indep{mode}")[img_idx] | ||
| self.assertTrue(np.isclose(vmin, exp_vmin, atol=1e-6)) | ||
|
|
||
| def test_indep_vrange_vmax(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| _, vmax = self._get_clims(self._imshow(f"indep{mode}"))[img_idx] | ||
| _, exp_vmax = self._expected_clims(f"indep{mode}")[img_idx] | ||
| self.assertTrue(np.isclose(vmax, exp_vmax, atol=1e-6)) | ||
|
|
||
| def test_indep_vrange_title_matches_clim(self): | ||
| for mode in range(4): | ||
| for img_idx in range(4): | ||
| with self.subTest(mode=mode, img_idx=img_idx): | ||
| fig = self._imshow(f"indep{mode}") | ||
| clim_vmin, clim_vmax = self._get_clims(fig)[img_idx] | ||
| title_vmin, title_vmax = self._get_title_clims(fig)[img_idx] | ||
| self.assertEqual("{:.1e}".format(clim_vmin), "{:.1e}".format(title_vmin)) | ||
| self.assertEqual("{:.1e}".format(clim_vmax), "{:.1e}".format(title_vmax)) | ||
|
|
||
| def main(): | ||
| unittest.main() | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I would combine these into one test