How to convert a folder of .bin files into .mat files?
Mostra commenti meno recenti
With the code below, I was able to read a folder containing .bin files.. in the end it converts all .bin file into a single .mat file which is not so easy to process... Can somebody provide me the code for converting each .bin file into .mat file( without changing the name) to be saved within the folder itself... Please tell me the importance of header files.. Whether i need it during processing steps...
% clear;close all;clc;
binPath = 'MSR Daily Activity 3D dataset\Depth';
for ai = 1:16
for si = 1:10
for ei = 1:2
%%%%%%%%%%%%%
%%%%%%%%%%%%%
[acsr,susr,exsr]=getsr(ai,si,ei);
%%%%%%getsr(ai,si,ei) convert ai,si,ei to double bits
%%%%%%for example, if ai=3, acsr is 03
%%%%%%%%%%%
binfile = [binPath,'\a',acsr,'_s',susr,'_e',exsr,'_depth.bin'];
if ~exist(binfile,'file');
disp('error');
continue;
end;
disp(binfile);
fileread = fopen(binfile);
if fileread<0
disp('no such file.');
return;
end
header = fread(fileread,3,'uint=>uint');
nnof = header(1); ncols = header(2); nrows = header(3);
depths = zeros(ncols, nrows, nnof);
for f = 1:nnof
frame = zeros( ncols, nrows);
for row = 1:nrows
tempRow = fread(fileread, ncols, 'uint=>uint');
tempRowID = fread(fileread, ncols, 'uint8');%%%%%
frame(:,row) = tempRow;
end
depth(:,:,f) = frame;
clear tempRow tempRowID;
end
fclose(fileread);
end
end
end
end
1 Commento
Jan
il 19 Ott 2016
The question is not clear. You tell us, that the data is saved as a MAT file, but the code does not create a MAT file. Therefore we cannot see, what is contained in this file. You ask for "header files" but do not explain, which kind of "header files" are meant. The binary files contain a header, as your code shows. This means that some information for the handling of the data is written at the start of the file. In your case it is the number of rows and columns. But this is not a "header file", but a "file header".
Risposte (1)
I guess - an exact answer is not possible yet:
Simply insert this after the fclose(fileread) command:
save([binfile(1:end-4), '.mat'], 'depth');
8 Commenti
arun
il 19 Ott 2016
Walter Roberson
il 19 Ott 2016
No, you do not have to use the file header during image processing.
Walter Roberson
il 19 Ott 2016
Imagine that you have file that contains 1394 readings for a rectangular area. Now, was the rectangle 2 x 697, or was it 34 * 41, or was it 17 * 82 or was it 697 x 2 or was it 41 x 34 or was it 82 x 17? Was the data arranged down the rows or across the columns? Is the first reading the reading for the top left corner, or for the bottom left? You do not know unless it is always the same or else in the file or in a different file there is a record that says (for example) "this is 41 x 34 and the data was stored across the rows from the top left corner". That's what the header file is for, to tell you how to interpret the data.
.bin files are often multispectral files and if you do not have the details about how bands are interleaved then you can get yourself confused easily.
arun
il 19 Ott 2016
preksha pareek
il 16 Set 2017
Modificato: preksha pareek
il 16 Set 2017
In above code it is giving error as undefined function getsr() in [acsr,susr,exsr]=getsr(ai,si,ei);
Walter Roberson
il 16 Set 2017
preksha pareek
il 17 Set 2017
Is this provided by signal processing toolbox?
Walter Roberson
il 17 Set 2017
No, getsr() is not part of any Mathworks product; it appears to be from the File Exchange contribution that I linked to.
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!