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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hv.RGB does not display image and fails to raise an error #3752

Closed
drrmmng opened this issue Jun 1, 2019 · 6 comments · Fixed by #3956
Closed

hv.RGB does not display image and fails to raise an error #3752

drrmmng opened this issue Jun 1, 2019 · 6 comments · Fixed by #3956

Comments

@drrmmng
Copy link
Contributor

drrmmng commented Jun 1, 2019

The following code results in an error to raise a ValueError, so I think the problem is twofold. hv.RGB cannot handle the shape of the input array and neither can the error message. Maybe this is related to the fact that the image is monochrome?

Code section

to_img = torchvision.transforms.ToPILImage()
input_image = to_img(input.view([1, 28, -1]))
input_image  # correctly shows the image in a notebook

np.array(input_image).shape  # (28, 28)

plot = hv.RGB(np.array(input_image))  # error

plot2 = hv.Image(np.array(input_image))  # works but the colors are wrong (expected, I think)

error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in 
     14 reconstruction = to_img(reconstruction)
     15 
---> 16 plot = hv.RGB(np.array(input_image))
     17 plot
     18 

~/anaconda3/lib/python3.7/site-packages/holoviews/element/raster.py in __init__(self, data, kdims, vdims, **params)
    736             if data.shape[-1] == 4 and len(vdims) == 3:
    737                 vdims.append(self.alpha_dimension)
--> 738         super(RGB, self).__init__(data, kdims=kdims, vdims=vdims, **params)
    739 
    740 

~/anaconda3/lib/python3.7/site-packages/holoviews/element/raster.py in __init__(self, data, kdims, vdims, bounds, extents, xdensity, ydensity, rtol, **params)
    285         elif isinstance(data, np.ndarray) and data.ndim < self._ndim:
    286             raise ValueError('%s type expects %d-D array received %d-D'
--> 287                              'array.' % (self._ndim, data.ndim))
    288 
    289         if rtol is not None:

TypeError: not enough arguments for format string

pyviz packages

colorcet                  2.0.1                      py_0    pyvizdatashader                0.7.0                      py_0    pyviz
holoviews                 1.12.3                     py_0    pyviz
hvplot                    0.4.0                      py_0    pyviz
panel                     0.5.1                      py_0    pyviz
param                     1.9.0                      py_0    pyviz
pyct                      0.4.6                      py_0    pyviz
pyct-core                 0.4.6                      py_0    pyviz
pyviz_comms               0.7.2                      py_0    pyviz
@philippjfr
Copy link
Member

A monochrome image is by definition not an RGB image. If you want to display it as a monochrome image simply use hv.Image(np.array(input_image)).opts(cmap='gray')

@drrmmng
Copy link
Contributor Author

drrmmng commented Jun 1, 2019

Thank you.
But is the fact, that it fails to throw the ValueError intended?

@philippjfr
Copy link
Member

No, you're right that is of course a bug.

@drrmmng
Copy link
Contributor Author

drrmmng commented Jun 1, 2019

Should I open a separate issue for that or should this be reopened?

@jlstevens
Copy link
Contributor

I'll go ahead and reopen this issue.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants