Filter löschen
Filter löschen

Can somebody please help me how to convert *.bil files to *.cyt file formats ?

6 Ansichten (letzte 30 Tage)
Surya Gnyawali
Surya Gnyawali am 21 Mär. 2018
Bearbeitet: Guillaume am 22 Mär. 2018
Hi I have a hyperspectral datacube in *.bil format and I need to convert it to *.cyt file format. Can you please help me with this code? Appreciate for the great help.
  7 Kommentare
Guillaume
Guillaume am 22 Mär. 2018
Please use Comment on this question rather than spamming your own question with Answers. If people see that the question has already 3 answers, there's less chance they'll look at it and you'll have less chances of getting an answer.
Surya Gnyawali
Surya Gnyawali am 22 Mär. 2018
Bearbeitet: Guillaume am 22 Mär. 2018
% Import the header file
[FileName,PathName,FilterIndex] =...
uigetfile({'*.hdr','Hyperspec Header File'},...
'Open Hyperspec Header File');
%%Gets the data from the Header File
fid = fopen([PathName,FileName]);
% fid is file ID
% fgetl gets one line
% char changes cell array to character array
% textscan helps parse around ' ' spaces
% char(Camera.Gain{3}) makes the third cell in Gain into a char array
% str2double converst the string of characters to a double number.
Data.Format = fgetl(fid);
DateStamp = fgetl(fid);
DateStamp = textscan(char(DateStamp),'%s%s%s%s%s%s%s%s',1);
Temp1 = char(DateStamp{3});
Temp2 = char(DateStamp{4});
Temp3 = char(DateStamp{5});
Temp4 = char(DateStamp{6});
Temp5 = char(DateStamp{7});
Temp6 = char(DateStamp{8});
DateStamp = [Temp1(3:length(Temp1)),' ',Temp2,' ',Temp3,' ',Temp4,...
' ',Temp5,' ',Temp6(1:(length(Temp6)-2))];
DataFormat.Samples = textscan(char(fgetl(fid)),'%s%s%s',1);
DataFormat.Samples = str2double(char((DataFormat.Samples{3})));
DataFormat.Lines = textscan(char(fgetl(fid)),'%s%s%s',1);
DataFormat.Lines = str2double(char((DataFormat.Lines{3})));
DataFormat.Bands = textscan(char(fgetl(fid)),'%s%s%s',1);
DataFormat.Bands = str2double(char((DataFormat.Bands{3})));
DataFormat.HeaderOffset = textscan(char(fgetl(fid)),'%s%s%s%s',1);
DataFormat.HeaderOffset = str2double(char((DataFormat.HeaderOffset{4})));
DataFormat.FileType = textscan(char(fgetl(fid)),'%s%s%s%s',1);
DataFormat.FileType = ([char((DataFormat.FileType{3})),' ',...
char((DataFormat.FileType{4}))]);
Temp = textscan(char(fgetl(fid)),'%s%s%s%s',1);
Temp2 = str2double(char((Temp{4})));
switch Temp2
case 1
DataFormat.DataType = 'uint8';
case 2
DataFormat.DataType = 'int16';
case 3
DataFormat.DataType = 'int32';
case 4
DataFormat.DataType = 'float32';
case 5
DataFormat.DataType = 'double';
case 9
DataFormat.DataType = 'complex';
case 12
DataFormat.DataType = 'uint16';
end
DataFormat.Interleave = textscan(char(fgetl(fid)),'%s%s%s',1);
DataFormat.Interleave = (char((DataFormat.Interleave{3})));
DataFormat.SensorType = textscan(char(fgetl(fid)),'%s%s%s%s',1);
DataFormat.SensorType = (char((DataFormat.SensorType{4})));
DataFormat.ByteOrder = textscan(char(fgetl(fid)),'%s%s%s%s',1);
DataFormat.ByteOrder = str2double(char((DataFormat.ByteOrder{4})));
if mod(DataFormat.ByteOrder,2) == 0
DataFormat.ByteOrder = 'ieee-le';
elseif mod(DataFormat.ByteOrder,2) == 1
DataFormat.ByteOrder = 'ieee-be';
end
DataFormat.Units = textscan(char(fgetl(fid)),'%s%s%s%s',1);
DataFormat.Units = (char((DataFormat.Units{4})));
Junk = fgetl(fid); % We just don't need this line, but we need to read past it.
%%Gets the wavelength data and puts it in a vector
i = 1;
j = 0;
a = [];
while i==1
b = fgetl(fid);
if b == -1
i=0;
elseif b(length(b))=='}'
a = cat(2,a,b(1:(length(b)-1)));
else
a = cat(2,a,b);
end
end
Wavelengths = str2num(a);
fclose(fid); % Closes the file.
clear Temp Temp2 Temp3 Temp4 Temp5 Temp6 a b Junk
%%Import the data file (UI version)
[FileNameData,PathName,FilterIndex] =...
uigetfile({'*.bil','Hyperspec Data File';'*.*','All Files'},...
'Open Hyperspec Data File', PathName) ;
% Set the Data Size
DataSize = [ DataFormat.Lines DataFormat.Samples DataFormat.Bands ];
% Load data with multibandread and assign to variable
HyperDataCube = multibandread([PathName,FileNameData], DataSize,...
DataFormat.DataType,DataFormat.HeaderOffset,...
DataFormat.Interleave, DataFormat.ByteOrder);
Mesh Plot of Data at specific wavelength.
Lambda = 10; % One element of the Wavelength vector
figure(3);mesh(fliplr(squeeze(HyperDataCube(:,:,Lambda))));view(180,90);
title(['Hyperspectral Data: \lambda = ',num2str(Wavelengths(Lambda)),...
' nm'],'FontSize',14);
xlabel('Pixels','FontSize',12);
ylabel('Pixels','FontSize',12);
if true
% code
end
%------------------------------------------------------------
This link has all the matlab code used on the software "CytoSpec". You may find useful info on these files. Thanks a lot

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by