How to convert .hdr image data set to .mat?
조회 수: 21 (최근 30일)
이전 댓글 표시
Please help to save my hdr image data into .mat file.
댓글 수: 5
Voss
2022년 2월 4일
편집: Voss
2022년 2월 4일
OK. The hdr file looks like a text file that looks like this:
ENVI
description = {
File Resize Result, x resize factor: 1.000000, y resize factor: 1.000000.
[Wed Feb 02 15:19:23 2022]}
samples = 361
lines = 392
bands = 6
header offset = 0
file type = ENVI Standard
data type = 12
interleave = bsq
sensor type = Unknown
byte order = 0
x start = 3349
y start = 3650
map info = {UTM, 1.000, 1.000, 642525.000, 2403045.000, 3.0000000000e+001, 3.0000000000e+001, 45, North, WGS-84, units=Meters}
coordinate system string = {PROJCS["WGS_1984_UTM_Zone_45N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",87.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]}
wavelength units = Unknown
band names = {
Resize (Layer (Band 1:LC08_L2SP_138045_20161121_20200905_02_T1_SR_B1.TIF):image),
Resize (Layer (Band 1:LC08_L2SP_138045_20161121_20200905_02_T1_SR_B2.TIF):image),
Resize (Layer (Band 1:LC08_L2SP_138045_20161121_20200905_02_T1_SR_B3.TIF):image),
Resize (Layer (Band 1:LC08_L2SP_138045_20161121_20200905_02_T1_SR_B4.TIF):image),
Resize (Layer (Band 1:LC08_L2SP_138045_20161121_20200905_02_T1_SR_B5.TIF):image),
Resize (Layer (Band 1:LC08_L2SP_138045_20161121_20200905_02_T1_SR_B6.TIF):image)}
What information do you want out of that and how should it be stored in the mat file? If you want to store it just as it is, you can do this:
fid = fopen('resizeimage.hdr');
data = char(fread(fid).');
fclose(fid);
save('resizeimage.mat','data');
채택된 답변
DGM
2022년 2월 4일
편집: DGM
2022년 2월 4일
You can use multibandread() to read these types of data files.
In order to get all those parameters, you need to read the .hdr file first. You could use enviinfo(). Similarly, you could use hypercube() to do both without needing multibandread().
I don't have enviinfo() or hypercube(), and I'm not climbing a mountain in order to install either. I just manually fetched the parameters from the header file. It's a plain text file, and the parameter translation into MATLAB terms is explained here:
headerfile = 'resizeimage.hdr'; % normally you'd use something to read this to get the parameters
datafile = 'resizeimage.bsq'; % i added the extension
datasize = [392 361 6]; % [lines samples bands]
dataprec = 'uint16'; % data type = 12
dataoffset = 0;
interleaveopt = 'bsq';
endianopt = 'ieee-le'; % byte order = 0
A = multibandread(datafile,datasize,dataprec,dataoffset,interleaveopt,endianopt);
imshow(A(:,:,1),[]) % show layer 1
In lieu of manually parsing each header file, you could probably write a simple replacement for enviinfo() relatively easily.
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!