Tags: 8-bit, access, caseswhen, execution, files, harddrive, image, matlab, program, programming, raw, slowest, stored, subsampling, time

Subsampling raw image files from the hard

On Programmer » Matlab

2,293 words with 0 Comments; publish: Sat, 26 Apr 2008 23:28:00 GMT; (20078.13, « »)

I have a lot of image data stored as 8-bit raw files. Right now, hard

drive access time is the slowest part of program execution. For cases

when multiple images are required onscreen, I'd like to be able to

subsample the images to reduce the number of bytes that need to be

read from the hard disk.

Here's my subsampling function as-is:

function imgS = subsample (fid, offset, imgW0, imgH0, s)

%

%subsampledImg = subsample (FILEID, OFFSET, ORIGIMGW, ORIGIMGH, S)

%

%Subsamples an image stored OFFSET bytes from the beginning of the

file

%specified by FILEID, with image dimension ORIGIMGW*ORIGIMGH, at a

%subsampling rate of S, where S is one of (2, 4, 8, 16,...)

%Dimensions of the subsampled image

imgWs = imgW0/s;

imgHs = imgH0/s;

%Preallocate imgS

imgS = zeros(imgWs, imgHs, 'uint8');

%Initial offset

fs (fid, offset, -1); %-1 = beginning of file

%Number of bytes to skip over when skipping cols;

colSkip = (s-1);

%ditto rows

rowSkip = colSkip * imgW0;

%for each row in the subsampled image

for i = 1:imgHs

%read a row of subsampled pixels, skipping (s-1) bytes inbetween

%read bytes

imgS(:, i) = fread(fid, 1, '*uint8', colSkip);

%Skip over non-sampled rows

%fs (S-1)*imgW0 bytes forward from the current position

fs(fid, rowSkip, 0);

end

%Note: because fread fills in arrays columnwise, it's slightly faster

to

%insert the rows of the image as columns in the image array and

tranpose at

%the end

imgS = imgS';

Right now, it's approximately three times as slow to subsample at S =

2 than it is to simply read the image in whole. It's not until S = 16

that it's any faster. I've tried fsing manually, as opposed to

using fread's skip option, but that was much slower.

Am I facing a fundamental limit of hard-drive random access here, or

is there something I'm missing?

All Comments

Leave a comment...

  • 0 Comments