Path: news.mathworks.com!not-for-mail
From: "jay vaughan" <jvaughan5.nospam@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: load & display multichannel images quickly
Date: Fri, 9 May 2008 21:52:03 +0000 (UTC)
Organization: harvard
Lines: 59
Message-ID: <g02h23$hqb$1@fred.mathworks.com>
References: <fvviut$kf3$1@fred.mathworks.com> <muy1w4bhbur.fsf@G99-Boettcher.llan.ll.mit.edu>
Reply-To: "jay vaughan" <jvaughan5.nospam@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210369923 18251 172.30.248.38 (9 May 2008 21:52:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 9 May 2008 21:52:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1215048
Xref: news.mathworks.com comp.soft-sys.matlab:467647


Peter Boettcher <boettcher@ll.mit.edu> wrote in message
<muy1w4bhbur.fsf@G99-Boettcher.llan.ll.mit.edu>...
> "jay vaughan" <jvaughan5.nospam@gmail.com> writes:
> 
> > thanks for the suggestions. I tried to implement them but it
> > didn't improve things. Perhaps I implemented them
> > incorrectly? (See attempts 3 & 4.)
> >
> > % attempt 1: speed ok (0.0137 sec) but poor gain resolution
> > f1 = 10; 
> > c1 = 10;
> > ch1 = (fread(fid1, frame_size, '*uint8')-f1)*(255/(c1-f1));
> >
> > % attempt 2: slow (0.025 sec) but poor gain resolution
> > f1 = 10; 
> > c1 = 10;
> >
ch1=(fread(fid1,frame_size,'*uint8')-f1)*(255/double(c1-f1));
> >
> > % attempt 3: slow (0.025 sec) but poor gain resolution
> > f1 = uint32(10);
> > c1 = uint32(10);
> > ch1 =
> >
uint8(uint32(255)*(uint32(fread(fid1,frame_size,'*uint8')-f1)/(c1-f1)));
> >
> > % attempt 4: slow (0.025 sec) but has good gain resolution
> > f1 = uint32(10); % MATLAB f1 & c1 to be uint32 not uint8
> > c1 = uint32(10);
> > gain = uint32(256*256)/(channel_ceiling-channel_floor);
> >
ch1=uint8(gain*(uint32(fread(fid,frame_size,'*uint8'))-f)/256);
> 
> Try
bitshift(gain*(uint32(fread(fid,frame_size,'*uint8'))-f), -8)
> instead of /256
> 
> Other than that, your only other option might be a MEX file
> 
> -Peter


Hi Peter,

thanks for spelling out the bitshift operation for me. It
helped! I got things down to about 0.019 sec with good gain
resolution, compared to approach 1 with 0.014 sec with poor
gain resolution or approaches 2-4 with good gain resolution
but 0.025 sec duration. 0.014 is barely a compromise! (FYI I
had to operate on the bitshift result with uint8 before
putting the result into the 8-bit RGB array.)

I am still wondering about doing this task more quickly, but
can move on to other issues for the moment. I haven't played
with MEX files before, but would consider doing so depending
on what benefit there might be.

Thanks,
J