silx-kit / vscode-h5web

VSCode extension to explore and visualize HDF5 files
https://marketplace.visualstudio.com/items?itemName=h5web.vscode-h5web
MIT License
33 stars 5 forks source link

display color image #27

Closed LogWell closed 1 year ago

LogWell commented 1 year ago

How to view color images stored in HDF5?

It is always inconvenient to only view one channel, and there is also a need to adjust the D0/1/2 and FlipY. image

axelboc commented 1 year ago

Hi, we do support RGB images as defined by the HDF5 Image and Palette Specification. All you need is to add attribute CLASS="IMAGE" to your dataset and you should automatically see a new RGB tab in H5Web.

For an example, open H5Web's demo application, select /nD_datasets/threeD_rgb, and inspect the metadata.

LogWell commented 1 year ago

Is there a reload button in the current version?

axelboc commented 1 year ago

Closing/reopening the file doesn't work? Maybe try VS Code's Developer: Reload Webviews command?

LogWell commented 1 year ago

It would be more convenient to have a reload button during debugging (>_<

LogWell commented 1 year ago

There is another problem, if I save the encoded image, will it not be displayed?

import h5py
import cv2

path_jpg = ""
path_h5 = path_jpg[:-4] + "_v1.h5"

with h5py.File(path_h5, "w") as h5f:
    with open(path_jpg, 'rb') as fb:
        binary = fb.read()
        data = np.frombuffer(binary, dtype='uint8')
        dset = h5f.create_dataset('image', data=data)
        dset.attrs["CLASS"] = "IMAGE"

with h5py.File(path_h5, "r") as h5f:
    data = h5f['image'][:]
    img_jpg = cv2.imdecode(data, cv2.IMREAD_COLOR)
    print("img_jpg:", img_jpg.shape)
    cv2.imwrite(path_jpg[:-4] + "_v1.jpg", img_jpg)
LogWell commented 1 year ago

Furthermore, how to visualize depth (uint16) images? Only the palette was supported?

In this example, the color component numeric type is an 8 bit unsigned integer. While this is most common and recommended for general use, other component color numeric datatypes, such as a 16 bit unsigned integer , may be used. This type is specified as the type attribute of the palette dataset. (see H5Tget_type(), H5Tset_type())

axelboc commented 1 year ago

Currently, H5Web supports only IMAGE_SUBCLASS="IMAGE_TRUECOLOR" as well as the following features:

We're happy to consider supporting more of the HDF5 Image and Palette specification, but the spec is quite dense and we don't want to bloat H5Web with features that few people use, so please know that we will require careful justification when considering feature requests. If you're up for it, please open an issue on the main H5Web repository.


Regarding adding a button to reload the file, this is not trivial because this VS Code extension is just a wrapper around H5Web. I'm also a bit reluctant to add a button to the UI that is meant for debugging, especially when it's so easy to close a file and re-open it (unless there's an issue with this that I'm not seeing).

That being said, we could add a VS Code command for this, like "H5Web: Reload" — that'd be fairly straightforward.

axelboc commented 1 year ago

There is another problem, if I save the encoded image, will it not be displayed?

Do you mean that you are storing a JPEG image as binary in HDF5? If so, then this is definitely not going to be supported. :wink: