Add utils for plotting flow, and demo of new Baker et al. color scheme #570
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.
Use the test/test_flow_coloring.py script to see a comparison of the new Baker et al. flow color scheme.
It relies on the code for the Baker et al colormap implemented in neurite in this PR: adalca/neurite#78
Use the functions in scripts/py/flow_utils.py to convert the flow output by a transformer to the format that can be plotted with the new color scheme (tested with both PyTorch and Tensorflow)
The figures below are produced by the included test_flow_coloring.py script.
Figure 1: Direct comparison of 'Baker et al.' color scheme and 'winter' colormap:
Some advantages of the Baker et al. color scheme are:
(a) Each direction is a distinctive color (instead of a range from blue-to-green).
(b) The color wheel is cyclic/circularly continuous as a function of direction angle (whereas there is a sharp blue/green discontinuity in the winter colormap)
(c) The 'lightness' of the color increases as the magnitude of the flow decreases, so that zero flow is white, which makes it easier to distinguish where the magnitude of the flow field is high or low.
Figure 2: Example simple flow fields plotted using the Baker et al color scheme.
On the left column: The Flow colorwheel for this figure as an RGB image (top), as an arrow field (middle), and a test "image" -- a rectangle of 1's surrounded by 0's (bottom). Each column after this demonstrates shows a simple, spatially varying flow field, either visualized as an RGB image (top), or as an arrow field (middle). The arrow field is more straightforward to understand for smaller images like these, but becomes harder for much larger images/flow fields, where individual arrows may be hard to make out, and for which the RGB image becomes more suitable. In the RGB image, the colors at each pixel are just the color of the arrow at the corresponding location. On the bottom of each column is the output of the SpatialTransformer when applied to the test "source" image (bottom left corner) using the flow field from this column.
Figure 3: Example simple flow fields plotted using the Winter et al color scheme. Same as Figure 2, but using the winter colormap. The advantages of the new Baker et al. color scheme are apparent by comparing Figures 2 and 3.