Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support batched and float data in apply colormap #2886

Merged
merged 4 commits into from
May 28, 2024

Conversation

vgilabert94
Copy link
Collaborator

@vgilabert94 vgilabert94 commented Apr 16, 2024

Changes

fixes #2877

  • Use image in float32 in range [0,1].
    -- Also is posible to use int or uint in range [0-255] values with an internal normalization to [0-1].
  • Accept images with no restriction channels.
  • Accept batched tensors.

Output:

  • Batched tensor (B,C,H,W). Float with range [0-1]. (My suggestion, we could change it or add more flexibility if needed.)

Always the apply_colormap work in float dtype, because the problem that I detect here (#2877 (comment)) is when arange is used. I'm not sure why, but I tried to implement my function with arange and I kept getting this problem.

Type of change

  • 馃摎 Documentation Update
  • 馃И Tests Cases
  • 馃悶 Bug fix (non-breaking change which fixes an issue)
  • 馃敩 New feature (non-breaking change which adds functionality)
  • 馃毃 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 馃摑 This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Did you update CHANGELOG in case of a major change?

@johnnv1 johnnv1 added enhancement 馃殌 Improvement over an existing functionality module: color labels Apr 16, 2024
@johnnv1 johnnv1 changed the title Update apply_colormap feat: support batched and float data in apply colormap Apr 16, 2024
@johnnv1
Copy link
Member

johnnv1 commented May 18, 2024

@vgilabert94 could you check/fix the typing issue?

Copy link
Member

@edgarriba edgarriba left a comment

Choose a reason for hiding this comment

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

LGTM. after green lights

@vgilabert94
Copy link
Collaborator Author

@vgilabert94 could you check/fix the typing issue?

Yes. I have doubts about how to solve it, because is a typing error with ColorMap class. This class generates a tensor in colormap.colors, do I have to inherit from a torch class?

kornia/color/colormap.py:210: error: Incompatible types in assignment
(expression has type "Tensor", variable has type "ColorMap")  [assignment]
        colormap = colormap.colors.permute(1, 0)
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kornia/color/colormap.py:211: error: "ColorMap" has no attribute "shape" 
[attr-defined]
        num_colors, channels_cmap = colormap.shape
                                    ^~~~~~~~~~~~~~
kornia/color/colormap.py:2[15](https://github.com/kornia/kornia/actions/runs/8702817467/job/23867709917?pr=2886#step:3:16): error: "ColorMap" has no attribute "expand" 
[attr-defined]
        output = torch.gather(colormap.expand(B, C, -1, -1), 2, indices)
                              ^~~~~~~~~~~~~~~
Found 3 errors in 1 file (checked 436 source files)
Error: Process completed with exit code 1.

kornia/color/colormap.py Outdated Show resolved Hide resolved
kornia/color/colormap.py Outdated Show resolved Hide resolved
vgilabert94 and others added 2 commits May 27, 2024 11:52
Co-authored-by: Jo茫o Gustavo A. Amorim <joaogustavoamorim@gmail.com>
Co-authored-by: Jo茫o Gustavo A. Amorim <joaogustavoamorim@gmail.com>
@johnnv1 johnnv1 merged commit e461f92 into kornia:main May 28, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 馃殌 Improvement over an existing functionality module: color
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update apply_colormap
3 participants