Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add colormodel parameter into px.imshow and test #2932

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
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

liudj2008
Copy link

@liudj2008 liudj2008 commented Nov 24, 2020

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or
    modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

@emmanuelle
Copy link
Contributor

Thanks a lot for the PR @liudj2008 ! The CI failures probably don't have anything to do with your PR: on py2.7, it looks like a new version of qtconsole forgot to say they were not compatible with python 2.7, but they seem to have fixed this so I restarted the build 🤞 (@nicolaskruchten this might affect some other PRs). Still investigating the doc problem.

@emmanuelle
Copy link
Contributor

One difference between RGB and HSL is that the bounds for the channels are different:

  • for RGB the 3 channels are expected to be between 0 and 255
  • for HSL, H is in [0, 360] (an angle), S in [0, 100] and V in [0, 100]

Therefore I think we should disable binary_string=True when colormodel='hsl'/'hsla' since binary string implies values in [0. 255]. Also, if zmax is None it should be set to [360, 100, 100]. Could you please make these changes as well?

Here is an example (using the colour-science package) which might be worth adding to the doc:
(doc/python/imshow.md, I can also do it in a subsequent PR)

from skimage import data, color, img_as_ubyte, img_as_float
import plotly.express as px
img = data.chelsea()
import colour
img_hsl = colour.RGB_to_HSL(img_as_float(img))
img_hsl_360 = (img_hsl * np.array([360, 100, 100])[np.newaxis, np.newaxis, :]).astype(np.uint16)
fig = px.imshow(img_hsl_360, binary_string=False, colormodel='hsl', zmax=[360, 100, 100])
fig.show()

@emmanuelle
Copy link
Contributor

For the build-doc CI issue, could you please update your master branch, and then merge master into your feature branch to see if this solves the problem?

@nicolaskruchten
Copy link
Contributor

Therefore I think we should disable binary_string=True when colormodel='hsl'/'hsla' since binary string implies values in [0. 255]

I'm not sure why this would mean we can't use binary_string? We can use HSL input to create a PNG, no?

@emmanuelle
Copy link
Contributor

@nicolaskruchten we could indeed take the HSL input and convert it back to rgb to make a png, but then we're not making use of the HSL capability of the Image trace which was the original idea. With an H channel between 0 and 260 it's not possible to encode it on one byte. In fact I have no idea whether there is a native format for HSL images...

@nicolaskruchten
Copy link
Contributor

but then we're not making use of the HSL capability of the Image trace which was the original idea

Not sure I fully agree here... to me the original idea is to allow users to provide input data in HSL format, and ideally we would display that in the fastest way possible, no, regardless of the details of the underlying JS implementation? Maybe Plotly.js still needs to be told "hey this is meant to be HSL" so it can do the hover in HSL mode (essentially picking up the RGB value of the PNG pixel and reversing the HSL-to-RGB conversion) ?

@liudj2008
Copy link
Author

I agree with @nicolaskruchten , users do not have to worry about implementation, as long as we can "recognize" hsl from rga and show it properly. I do notice in graph_objs/_image.py, when initiating Image class, all we need to do is to pass in z and colormodel, and zmin and zmax will be defaulted depending on colormodel input (so we do not have to worry about the outrange issue). As @emmanuelle pointed out, the definition of binary_string in px module is to "force" image conversion to rgb/rgba so that to construct the img source to pass in go.Image, and we need to disable it for hsl/hsla images.

So in that case, I will call future px on hsl image like this (no zmax, since it will be defaulted):
fig = px.imshow(img_hsl_360, binary_string=False, colormodel='hsl')

merge updated master to branch
@liudj2008
Copy link
Author

liudj2008 commented Nov 27, 2020

@emmanuelle So I merged the updated master with the branch, but still had the build-doc issue. Seems like it is related with notebook to html conversion. Is there anything I can do to fix it? I will add the modification to doc/python/imshow.md once this is fixed. Thanks!

@gvwilson gvwilson self-assigned this Jun 18, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson removed the request for review from emmanuelle August 12, 2024 15:09
@gvwilson gvwilson added feature something new P2 considered for next cycle community community contribution labels Aug 12, 2024
@gvwilson
Copy link
Contributor

@archmoj can you please have a look and decide (a) if this is still relevant and (b) if the hard-coded 3's and 4's can now be replaced by symbolic constants? thanks - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution feature something new P2 considered for next cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants