Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function write_linux #8

Open
meltingCat opened this issue Apr 6, 2021 · 3 comments
Open

function write_linux #8

meltingCat opened this issue Apr 6, 2021 · 3 comments

Comments

@meltingCat
Copy link

Error in using function write_linux. Can't write data back to a binary file.

% using N-MNIST
filename = '00004.bin';
TD = Read_Ndataset(filename); 

Show3D(TD);

filename = '11111.bin';
write_linux(TD, filename);
TD = Read_Ndataset(filename);

Show3D(TD);

image

image

@gorchard
Copy link
Owner

gorchard commented Apr 6, 2021

The names of the different formats are a bit confusing, but here's an explanation:
The datasets use a format optimized for the dataset resolution to reduce file sizes. You can read a dataset file using the "Read_Ndataset()" function as you have done.
You can write the "linux" format using "write_linux()", but this is not the same as the dataset format. To read the "linux" format you need to use the "read_linux()" function.

@meltingCat
Copy link
Author

meltingCat commented Apr 6, 2021

Thanks for reply. I read a dataset file using the Read_Ndataset() function and done some modification. I would like to convert back to dataset format same as N-MNIST .bin files.

@gorchard
Copy link
Owner

gorchard commented Apr 8, 2021

For this you'd need to make your own function which reverses the format of "Read_Ndataset.m". I haven't had access to matlab in years, so I cannot test it, but it would look something like this:

function write_Ndataset(TD, filename)

evtStream = uint8(length(TD.x)*5);

evtStream(1:5:end) = TD.x-1;
evtStream(2:5:end) = TD.y-1;
evtStream(3:5:end) = bitshift(TD.p-1,7) + bitand(bitshift(TD.ts,-16), 127);
evtStream(4:5:end) = bitand(bitshift(TD.ts, -8), 255);
evtStream(5:5:end) = bitand(TD.ts, 255);

evtFile = fopen(filename, 'w');
fwrite(evtFile,evtStream,'uint8');
fclose(evtFile);

return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants