You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Can somebody please help me how to convert *.bil files to *.cyt file formats ?
5 views (last 30 days)
Show older comments
Surya Gnyawali
on 21 Mar 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 Comments
Rik
on 21 Mar 2018
If you can provide the file type descriptions, we can help you with implementation. Have you already tried your favorite internet search engine for a converter?
Rik
on 21 Mar 2018
OK, so now we have a function to read the .bil files, we need a description of how a .cyt file works. Also, can you select the code and then click the {}Code button? Currently your function is unreadable.
Guillaume
on 22 Mar 2018
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loading a Hyperspectral Cube into Matlab %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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);
Guillaume
on 22 Mar 2018
File created by Cytospec - date: 17-Mar-2018 , time: 17:30:39
please do not modify this file
INS - IFS Vector 22 + IRscope II
MAN - Bruker
SRC - MAN
BSP - Globar
FIL - open
DET - MCT (microscope)
VEL - 20 kHz
LAS - 15799.1
AQM - double sided fw bw
SNG - automatic
LWN - 397.746
UWN - 994.8992
WVS - 25.9632
NOD - 24
DAT - 09-OCT-2000
TIM - 11:30:00
PHC - Mertz
PHR - 32
PIP -
ZFF - 4
RES - 8
APO - Happ-Genzel
APT - 45
STX - 30
STY - 30
TOS - absorbance
NOS - 8
XDI - 1192
YDI - 1600
SZX - 2400
SZY - 2400
SAM - B1760/98(Buch)
SAF - dry on CaF2
OPN - Peter Lasch
AS1 - dry colon adenocarcinoma sample
AS2 - colon sample, spectrally and spatially interpolated
AS3 - Hunter College, New York
BLO - 1 0 0 0
4 ORG (original data):
data imported as ascii files, date: 10-Oct-2000, time: 15:57:0
spectral interpolation factor: 2, NOD (old): 1323, new NOD: 662, date: 14-Apr-2006, time: 16:16:19
map dimensions (old): 84 x 84, new map dimensions: 42 x 42, date: 14-Apr-2006, time: 16:17:0
spectral interpolation factor: 16, NOD (old): 373, new NOD: 24, date: 17-Mar-2018, time: 17:14:29
2 PRE (preprocessed data):
spectral interpolation factor: 2, NOD (old): 1323, new NOD: 662, date: 14-Apr-2006, time: 16:16:19
map dimensions (old): 84 x 84, new map dimensions: 42 x 42, date: 14-Apr-2006, time: 16:17:0
2 DER (derivative data):
spectral interpolation factor: 2, NOD (old): 1323, new NOD: 662, date: 14-Apr-2006, time: 16:16:19
map dimensions (old): 84 x 84, new map dimensions: 42 x 42, date: 14-Apr-2006, time: 16:17:0
2 DEC (deconvolution data):
spectral interpolation factor: 2, NOD (old): 1323, new NOD: 662, date: 14-Apr-2006, time: 16:16:19
map dimensions (old): 84 x 84, new map dimensions: 42 x 42, date: 14-Apr-2006, time: 16:17:0
Guillaume
on 22 Mar 2018
The last text is taken from a .cyt file. I am not familier about this file type.
Guillaume
on 22 Mar 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
on 22 Mar 2018
Edited: Guillaume
on 22 Mar 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
Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)