How do I read multiband envi generated image file into matlab?

5 visualizzazioni (ultimi 30 giorni)
I am reading the multiband envi generated image file into matlab by using following matlab code;
img_path = 'C:\Image_Data\'
d = uigetdir(pwd, 'Select a folder');
imgfiles = dir(fullfile(d, '*.img'));
for m = 1:length(imgfiles)
img_file = imgfiles(m);
disp(img_file.name);
img = imread(img_file.name);
red = img(:,:,4); % red band
rededge1 = img(:,:,5); % rededge1 band
rededge2 = img(:,:,6); % rededge2 band
rededge3 = img(:,:,7); % rededge3 band
nir = img(:,:,8); % near infrared band
This is giving the following error
>> ds_indices_caf
img_path =
'C:\Image_Data\'
20240309_SAMPLE_DATA.img
Error using imread>get_full_filename
File "20240309_SAMPLE_DATA.img" does not exist.
Error in imread (line 372)
fullname = get_full_filename(filename);
Error in ds_indices_caf (line 17)
img = imread(img_file.name);
>>
I am attaching the envi image file and request to kindly help me out to read the data from the image file.
Deva
  1 Commento
Devendra
Devendra il 26 Mar 2024
I have kept matlab code and input data in same directory. Now following errors are coming;
>> ds_indices_caf
img_path = 'C:\Data\'
20240309_SAMPLE_DATA.img
Error using imread>get_format_info (line 554)
Unable to determine the file format.
Error in imread (line 395)
fmt_s = get_format_info(fullname);
Error in ds_indices_caf (line 17)
img = imread(img_file.name);
I would appreciate any help to fix it.
Deva

Accedi per commentare.

Risposte (1)

Zuber Khan
Zuber Khan il 11 Ott 2024
Modificato: Zuber Khan il 11 Ott 2024
Hi,
As per my understanding, you are facing this issue because MATLAB's "imread" function might not support reading ".img" file format. This is also evident from the error message "Unable to determine the file format."
The "Hyperspectral Imaging Library for Image Processing Toolbox" Add-On allows us to work with ENVI files in MATLAB. Please refer to the following link to install an add-on in MATLAB:
The "hypercube" function provided by the add-on can be used to read the IMG and the HDR files. It creates a "hypercube" object which can be further analyzed using other hyperspectral-specific functions. The following documentation link provides more information on the same:
However, the above function also requires the center wavelength values of each spectral band to be present in the metadata HDR file to read the IMG image data. In case the wavelength information is not available, the below commands can be used to read the files:
info = enviinfo('sample.hdr');
data = multibandread('sample.img', [info.Height info.Width info.Bands], info.DataType, ...
info.HeaderOffset,info.Interleave,info.ByteOrder);
The returned "data" variable is a 2D matrix containing data corresponding to the input image data file. For more information on the functions used in the code above, please refer to the following documentation links:
I hope it helps resolve the issue.
Regards,
Zuber

Prodotti


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by