I have a huge image file (.dat file 17Gb) of columns x rows x frames. I need to import this file as fast as possible, but only every 10th frame or so.
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a huge image file (binary .dat) which takes minutes to import into memory and process. My calculations are under control after I have it in memory but I really only need every Nth frame in order to speed things up (for my calculations, and if possible loading into memory). The issue (I believe) is my for loop while loading the .dat file. I'm sure there is a better way to import this data. Thanks!
function [rawImage] = read_image_raw(loadFile,colPix, numRowsPerFrame, totalNumFrames)
% Calculate how many pixels to read in each frame
pixToRead = colPix * numRowsPerFrame;
% Open the file for reading
fid = fopen(loadFile,'r');
% Allocate space to the image variables
fileMarker = 0;
imageBlock = zeros(numRowsPerFrame,colPix,totalNumFrames);
% Loop through and read the image
for iFrame = 1:totalNumFrames
fseek(fid,fileMarker,'bof');
imageData = fread(fid,pixToRead,'uint16=>double','ieee-le');
imageBlock(:,:,iFrame) = reshape(imageData,[colPix,numRowsPerFrame])';
fileMarker = fileMarker + 2.*colPix*numRowsPerFrame;
end
% Close the file
fclose(fid);
rawImage = imageBlock;
댓글 수: 0
답변 (1개)
Asvin Kumar
2019년 9월 3일
The fseek command takes as second argument the offset which is the number of bytes to move from origin.
To obtain every Nth frame, you can modify the appropriate statement from the for loop as follows:
fileMarker = fileMarker + N*2*colPix*numRowsPerFrame;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!