Closed beachmouse closed 5 years ago
Are you doing this from within ipython or are you running a python script using the builtin interpreter? If you were running this code from an interactive session, I expect it would work (though from the way your code is structured, it would open an additional window for each image).
I think your main issue is how python, ipython, and spectral deal with matplotlib's interactive loop. If you simply want a window that cycles through the images, try replacing your imshow
line above with something like this:
plt.imshow(spy.get_rgb(img))
plt.show()
We are editing and running the code from one cell in Jupyter Notebook; will try your suggestion--thank you!
Here is the error; seems like something may not be installed...
NameError Traceback (most recent call last)
You need to
import spectral as spy
But if you're trying to do this in jupyter, that's a whole separate issue. You should still use the spy.get_rgb
function but you need to figure out how to do dynamic plots in jupyter (e.g., here).
Thanks for the link and for your help :)
import spectral as spy did the trick!
Excellent. Glad that worked for you.
Interesting occurrence just now. Yesterday, I ran the code with
import spectral as spy
and images were displayed. Today, initially, when I ran the same code, the images were not being displayed. I had to add
%matplotlib inline
to get them displayed. Any insight as to why this was needed today but not yesterday will be greatly appreciated!
I don't think the import statement would change anything since you were already importing functions from the module.
I don't know why anything would have changed since yesterday (there were no commits to spectral) but having "%matplotlib inline" is standard for using matplotlib with jupyter.
Hello,
Thank you for any help you may be able to provide.
We want to display hyperspectral images one-by-one within a for loop. We seem to be having an issue with SpectralPython displaying files outside a for loop. The information for a particular image is displayed after it is loaded, but the image itself is not. Instead, all the images are displayed after the loop exits. Code (python 2.7.15) follows:
And here is the output:
Enter the name of the directory containing HSI files. Type end when finished:\MicroHSI\May 8 test subset e:\MicroHSI\May 8 test subset ['GE2013_05_08_162859_377.hdr', 'GE2013_05_08_162859_377.hsi', 'GE2013_05_08_163243_011.hdr', 'GE2013_05_08_163243_011.hsi', 'GE2013_05_08_163806_197.hdr', 'GE2013_05_08_163806_197.hsi'] Entering for loop for all the images GE2013_05_08_162859_377.hdr GE2013_05_08_162859_377.hsi e:\MicroHSI\May 8 test subset\GE2013_05_08_162859_377.hdr e:\MicroHSI\May 8 test subset\GE2013_05_08_162859_377.hsi Loading Image ImageView object: Display bands : [0, 126, 251] Interpolation :
RGB data limits :
R: [0.0, 4095.0]
G: [86.0, 4095.0]
B: [33.0, 4095.0]
GE2013_05_08_163243_011.hdr GE2013_05_08_163243_011.hsi e:\MicroHSI\May 8 test subset\GE2013_05_08_163243_011.hdr e:\MicroHSI\May 8 test subset\GE2013_05_08_163243_011.hsi Loading Image ImageView object: Display bands : [0, 126, 251] Interpolation :
RGB data limits :
R: [0.0, 1235.0]
G: [65.0, 4095.0]
B: [30.0, 4095.0]
GE2013_05_08_163806_197.hdr GE2013_05_08_163806_197.hsi e:\MicroHSI\May 8 test subset\GE2013_05_08_163806_197.hdr e:\MicroHSI\May 8 test subset\GE2013_05_08_163806_197.hsi Loading Image ImageView object: Display bands : [0, 126, 251] Interpolation :
RGB data limits :
R: [0.0, 1194.0]
G: [65.0, 4095.0]
B: [36.0, 4095.0]
All the images are displayed at this point, instead of after their information.
Thanks again