writing binary file segment by segment
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hi,
i am wondering if i can carry out the following task in matlab:
i have a large multiband image that is >10 GB. since i cannot open the entire image due to limited memory, i want to open the image row by row, ie if my image is R rows by C columns by B bands, i want to open 1 row x C columns x B bands at any one time. i then want to carry out some mathematical analysis, which returns 2 values per pixel. i want to save the returned values to separate binary files, by writing them to the files row by row (again due to limited memory). this entire process is then looped over all the rows of the image, which means i will need some function/script to allow me to append data to existing files. at the end of the day, i just want to open the output files in another software.
can this be done? if so, pls let me know which functions i should work with. or even better, are there scripts on the File Exchange that allow me to do this?
thanks for any help.
0 comentarios
Respuesta aceptada
Ashish Uthama
el 9 de Mayo de 2011
Some hints:
Air code: (assumes data is in ordered in 'bil' (look at multibandwrite doc)).
fid_input = fopen('input.bin','rb');
fid_output = fopen('output.bin','wb');
for rowInd=1:1000
rowData = fread(fid_input, rowLength*NumBands,'precision');
processedData = processData(rowData);
fwrite(fid_output, processedData,'precision');
end
fclose the handles.
0 comentarios
Más respuestas (3)
Ashish Uthama
el 10 de Mayo de 2011
Its hard for me to debug your code without the data (or dummy data) and without an idea on what the code is supposed to do.
Notes on the code:
1. Always check the return status of FOPEN to ensure success.
2. Look at squeeze to remove singleton dimensions.
3. strrep is for strings. You could use the following instead to replace 0's with NaN in a numeric array. (Not sure what you do next, i.e index using non-NaN's).
imrc(iszero(imrc))=NaN;
You could try debugging the code, i.e set a breakpoint at the fwrite and inspect the variables to see if they are what you expected them to be.
0 comentarios
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!