writing binary file segment by segment
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Ashish Uthama
2011-5-9
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 个评论
更多回答(3 个)
Ashish Uthama
2011-5-10
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!