How can I extract the numerical array from a hypercube object?
61 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Miguel Ángel
am 3 Feb. 2026 um 17:59
Bearbeitet: dpb
vor etwa 8 Stunden
Hi! I've been using the hyperspectral library for the image processing toolbox for some years now. In the beggining, when a variable of class hypercube was created, it was storing the nomerical array (i.e. the spectral image) in a struct way that you could acces via dot indexing, for instance:
spectral_image = cube.DataCube;
However this seems not to be working anymore. Instead if I try this, I get a string instead of a numerical array. I've cheked and there is a funcion called gather which is supposed to be for this. I have also tried:
spectral_image = gather(cube);
But it is also not working. I get the following error, but my spectral image fits more than enough in my RAM, so I am sure this is not a problem.
Dot indexing is not supported for variables of this type.
Error in hypercube/gather (line 1398)
if isa(obj.BlockedDataCube.Adapter,'images.blocked.InMemory')
^^^^^^^^^^^^^^^^^^^^^^^^^^^
The problem is that I have spectral images stored in files in hypercube class that I saved some time ago with Matlab R2023 version or even earlier, but now I can not access directly to this numerical arrays that previously were perfectly fitting in my RAM.
Any clue about how could I fix this?
Thanks in advance.
0 Kommentare
Akzeptierte Antwort
dpb
am 3 Feb. 2026 um 19:59
Bearbeitet: dpb
am 3 Feb. 2026 um 20:23
The <Version History> section of the doc for R2025a discusses that the new version doesn't contain the actual datacube and that the prior versions will as you've discovered return the property as text. Why on earth that is is bizarre, indeed, it seems. But, it is what it is. Fortunately, they provide a helper function to convert to the expected numeric form. Why this wasn't included as a a builtin feature is anybody's guess.
From that doc page (sans my somewht cheeky side remarks) <vbg> --
"If you have saved hypercube objects created using the hypercube function in older releases prior to R2025a, the DataCube property contains the actual data cube. However, starting from R2025a, the DataCube property will be read as a string. You cannot use the new gather and apply object functions with these hypercube objects. To extract the actual data cube from hypercube objects created in prior releases, use this helper function."
function [datacube,wavelength,metadata] = classConverter(hcube)
datacube = str2double(hcube.DataCube);
metadata = hcube.Metadata;
datatype = metadata.DataType;
datacube = cast(datacube,datatype);
wavelength = hcube.Wavelength;
end
Good luck...
5 Kommentare
dpb
vor etwa 11 Stunden
str2double is notoriously slow -- with current MATLAB, you can convert directly and is quite a lot faster.
Try replacing
function [datacube,wavelength,metadata] = classConverter(hcube)
datacube = double(hcube.DataCube);
metadata = hcube.Metadata;
datatype = metadata.DataType;
datacube = cast(datacube,datatype);
wavelength = hcube.Wavelength;
end
Weitere Antworten (1)
Parth Parikh
vor etwa 20 Stunden
Hi Miguel,
I completely understand the frustration that comes with adapting to changes in well-established workflows. Moving forward, the best solution is to adopt the latest MATLAB functions for hyperspectral data, namely imhypercube and geohypercube. These provide seamless integration with current features, improved compatibility, and enhanced data management, positioning your work for future updates and optimizations from MATLAB. The helper function is meant to recover data from legacy hypercube objects created before R2025a, for robust, long-term workflows it’s highly recommended to transition to these newer functions. This way, you’ll be able to take advantage of MATLAB’s ongoing improvements with greater ease and reliability.
Note: For multispectral data, MATLAB provides the corresponding immuticube and geomulticube functions.
6 Kommentare
dpb
vor etwa 5 Stunden
Bearbeitet: dpb
vor etwa 3 Stunden
Glad to try, anyway...good luck and let us know how it goes.
I still think this is well deserving a strong ping/complaint about unduly burdening the user with extra overhead cost.
ADDENDUM
Last thought...I think I'd request a working version of the old hcube object code that can be run with the new release, or conversely, a method that can use in the prior release to create the new objects as part of that complaint. It's only what they should have done to begin with.
Siehe auch
Kategorien
Mehr zu Hyperspectral Image Processing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!