<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168963</link>
    <title>MATLAB Central Newsreader - load &amp; display multichannel images quickly</title>
    <description>Feed for thread: load &amp; display multichannel images quickly</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 09 May 2008 21:52:03 -0400</pubDate>
      <title>Re: load &amp; display multichannel images quickly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168963#431301</link>
      <author>jay vaughan</author>
      <description>Peter Boettcher &amp;lt;boettcher@ll.mit.edu&amp;gt; wrote in message&lt;br&gt;
&amp;lt;muy1w4bhbur.fsf@G99-Boettcher.llan.ll.mit.edu&amp;gt;...&lt;br&gt;
&amp;gt; "jay vaughan" &amp;lt;jvaughan5.nospam@gmail.com&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; thanks for the suggestions. I tried to implement them but it&lt;br&gt;
&amp;gt; &amp;gt; didn't improve things. Perhaps I implemented them&lt;br&gt;
&amp;gt; &amp;gt; incorrectly? (See attempts 3 &amp; 4.)&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % attempt 1: speed ok (0.0137 sec) but poor gain resolution&lt;br&gt;
&amp;gt; &amp;gt; f1 = 10; &lt;br&gt;
&amp;gt; &amp;gt; c1 = 10;&lt;br&gt;
&amp;gt; &amp;gt; ch1 = (fread(fid1, frame_size, '*uint8')-f1)*(255/(c1-f1));&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % attempt 2: slow (0.025 sec) but poor gain resolution&lt;br&gt;
&amp;gt; &amp;gt; f1 = 10; &lt;br&gt;
&amp;gt; &amp;gt; c1 = 10;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
ch1=(fread(fid1,frame_size,'*uint8')-f1)*(255/double(c1-f1));&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % attempt 3: slow (0.025 sec) but poor gain resolution&lt;br&gt;
&amp;gt; &amp;gt; f1 = uint32(10);&lt;br&gt;
&amp;gt; &amp;gt; c1 = uint32(10);&lt;br&gt;
&amp;gt; &amp;gt; ch1 =&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
uint8(uint32(255)*(uint32(fread(fid1,frame_size,'*uint8')-f1)/(c1-f1)));&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % attempt 4: slow (0.025 sec) but has good gain resolution&lt;br&gt;
&amp;gt; &amp;gt; f1 = uint32(10); % MATLAB f1 &amp; c1 to be uint32 not uint8&lt;br&gt;
&amp;gt; &amp;gt; c1 = uint32(10);&lt;br&gt;
&amp;gt; &amp;gt; gain = uint32(256*256)/(channel_ceiling-channel_floor);&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
ch1=uint8(gain*(uint32(fread(fid,frame_size,'*uint8'))-f)/256);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Try&lt;br&gt;
bitshift(gain*(uint32(fread(fid,frame_size,'*uint8'))-f), -8)&lt;br&gt;
&amp;gt; instead of /256&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Other than that, your only other option might be a MEX file&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Peter&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi Peter,&lt;br&gt;
&lt;br&gt;
thanks for spelling out the bitshift operation for me. It&lt;br&gt;
helped! I got things down to about 0.019 sec with good gain&lt;br&gt;
resolution, compared to approach 1 with 0.014 sec with poor&lt;br&gt;
gain resolution or approaches 2-4 with good gain resolution&lt;br&gt;
but 0.025 sec duration. 0.014 is barely a compromise! (FYI I&lt;br&gt;
had to operate on the bitshift result with uint8 before&lt;br&gt;
putting the result into the 8-bit RGB array.)&lt;br&gt;
&lt;br&gt;
I am still wondering about doing this task more quickly, but&lt;br&gt;
can move on to other issues for the moment. I haven't played&lt;br&gt;
with MEX files before, but would consider doing so depending&lt;br&gt;
on what benefit there might be.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
J&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 09 May 2008 12:59:40 -0400</pubDate>
      <title>Re: load &amp; display multichannel images quickly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168963#431242</link>
      <author>Peter Boettcher</author>
      <description>"jay vaughan" &amp;lt;jvaughan5.nospam@gmail.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; thanks for the suggestions. I tried to implement them but it&lt;br&gt;
&amp;gt; didn't improve things. Perhaps I implemented them&lt;br&gt;
&amp;gt; incorrectly? (See attempts 3 &amp; 4.)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % attempt 1: speed ok (0.0137 sec) but poor gain resolution&lt;br&gt;
&amp;gt; f1 = 10; &lt;br&gt;
&amp;gt; c1 = 10;&lt;br&gt;
&amp;gt; ch1 = (fread(fid1, frame_size, '*uint8')-f1)*(255/(c1-f1));&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % attempt 2: slow (0.025 sec) but poor gain resolution&lt;br&gt;
&amp;gt; f1 = 10; &lt;br&gt;
&amp;gt; c1 = 10;&lt;br&gt;
&amp;gt; ch1=(fread(fid1,frame_size,'*uint8')-f1)*(255/double(c1-f1));&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % attempt 3: slow (0.025 sec) but poor gain resolution&lt;br&gt;
&amp;gt; f1 = uint32(10);&lt;br&gt;
&amp;gt; c1 = uint32(10);&lt;br&gt;
&amp;gt; ch1 =&lt;br&gt;
&amp;gt; uint8(uint32(255)*(uint32(fread(fid1,frame_size,'*uint8')-f1)/(c1-f1)));&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % attempt 4: slow (0.025 sec) but has good gain resolution&lt;br&gt;
&amp;gt; f1 = uint32(10); % MATLAB f1 &amp; c1 to be uint32 not uint8&lt;br&gt;
&amp;gt; c1 = uint32(10);&lt;br&gt;
&amp;gt; gain = uint32(256*256)/(channel_ceiling-channel_floor);&lt;br&gt;
&amp;gt; ch1=uint8(gain*(uint32(fread(fid,frame_size,'*uint8'))-f)/256);&lt;br&gt;
&lt;br&gt;
Try bitshift(gain*(uint32(fread(fid,frame_size,'*uint8'))-f), -8)&lt;br&gt;
instead of /256&lt;br&gt;
&lt;br&gt;
Other than that, your only other option might be a MEX file&lt;br&gt;
&lt;br&gt;
-Peter&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 08 May 2008 22:57:03 -0400</pubDate>
      <title>Re: load &amp; display multichannel images quickly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168963#431164</link>
      <author>jay vaughan</author>
      <description>Peter Boettcher &amp;lt;boettcher@ll.mit.edu&amp;gt; wrote in message&lt;br&gt;
&amp;lt;muy63toh6j4.fsf@G99-Boettcher.llan.ll.mit.edu&amp;gt;...&lt;br&gt;
&amp;gt; "jay vaughan" &amp;lt;jvaughan5.nospam@gmail.com&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Hi again,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I am trying to optimize the speed of loading in three &lt;br&gt;
&amp;gt; &amp;gt; MxN arrays and assigning them to an 8 bit MxNx3 array &lt;br&gt;
&amp;gt; &amp;gt; (RGB) to be displayed.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; It's a sensitive part of a GUI I am working on, but&lt;br&gt;
&amp;gt; &amp;gt; I am having trouble optimizing it. A shortened version of&lt;br&gt;
&amp;gt; &amp;gt; the code is at the bottom.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; One problem is that if the floor and ceiling inputs,&lt;br&gt;
&amp;gt; &amp;gt; (contrast/brightness parameters), are doubles then &lt;br&gt;
&amp;gt; &amp;gt; MATLAB executes the code too slowly I presume since &lt;br&gt;
&amp;gt; &amp;gt; it is converting the term (255/(c1-f1)) from double &lt;br&gt;
&amp;gt; &amp;gt; to uint8. If the floor and ceiling inputs are uint8, &lt;br&gt;
&amp;gt; &amp;gt; MATLAB executes the code more quickly but then &lt;br&gt;
&amp;gt; &amp;gt; rounds the factor (255/(c1-f1)) before multiplying,&lt;br&gt;
&amp;gt; &amp;gt; which reduces the bit depth of the contrast pretty &lt;br&gt;
&amp;gt; &amp;gt; badly.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; The speed is close to what I need (a factor of 2 &lt;br&gt;
&amp;gt; &amp;gt; improvement would be great), but I am not sure how&lt;br&gt;
&amp;gt; &amp;gt; to speed things up further.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Sometimes when I find myself in this kind of pickle&lt;br&gt;
&amp;gt; &amp;gt; it means I am going about the problem the wrong way.&lt;br&gt;
&amp;gt; &amp;gt; For instance, is there be a better solution with&lt;br&gt;
&amp;gt; &amp;gt; some clever way of adjusting the colormapping &lt;br&gt;
&amp;gt; &amp;gt; rather than adjusting the data itself?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt; J&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % initialize frame&lt;br&gt;
&amp;gt; &amp;gt; frame_size = [256 256];&lt;br&gt;
&amp;gt; &amp;gt; frame = zeros(frame_size(1),frame_size(2),3,'uint8');&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % get floor &amp; ceiling inputs (min &amp; max in data channels)&lt;br&gt;
&amp;gt; &amp;gt; f1 = 10; f2 = 10; f3 = 10;&lt;br&gt;
&amp;gt; &amp;gt; c1 = 10; c2 = 10; c3 = 10;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % M maps data channels (row) to RGB weight (column)&lt;br&gt;
&amp;gt; &amp;gt; M = [1 0 0; 0 1 0; 0 0 1]; &lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % read in the three data channels&lt;br&gt;
&amp;gt; &amp;gt; ch1 = (fread(fid1, frame_size, '*uint8')-f1)*(255/(c1-f1));&lt;br&gt;
&amp;gt; &amp;gt; ch2 = (fread(fid2, frame_size, '*uint8')-f2)*(255/(c2-f2));&lt;br&gt;
&amp;gt; &amp;gt; ch3 = (fread(fid3, frame_size, '*uint8')-f3)*(255/(c3-f3));&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; % map the channels to the RGB frame for display&lt;br&gt;
&amp;gt; &amp;gt; frame(:,:,1) = M(1,1)*ch1 + M(1,2)*ch2 + M(1,3)*ch3;&lt;br&gt;
&amp;gt; &amp;gt; frame(:,:,2) = M(2,1)*ch2 + M(2,2)*ch2 + M(2,3)*ch3;&lt;br&gt;
&amp;gt; &amp;gt; frame(:,:,3) = M(3,1)*ch3 + M(3,2)*ch2 + M(3,3)*ch3;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; image(frame)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You're right, casts to and from floating point are very&lt;br&gt;
slow.  I would&lt;br&gt;
&amp;gt; stay in integer, but expand to an integer, do the&lt;br&gt;
operations, and return&lt;br&gt;
&amp;gt; to uint8.  Careful with the operation ordering.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; f1 = uint32(10);&lt;br&gt;
&amp;gt; c1 = uint32(100);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; t = fread(fid1, frame_size, '*uint8');&lt;br&gt;
&amp;gt; ch1 = (uint32(255) * (uint32(t) - f1)) / (c1 - f1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; By doing the multiply by 255 first, you don't have any&lt;br&gt;
precision&lt;br&gt;
&amp;gt; problems, and the uint32 can hold the full range.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Actually, you're even better off calculating the gain as a&lt;br&gt;
fixed&lt;br&gt;
&amp;gt; point value, so that each operation is only a multiply&lt;br&gt;
followed by a&lt;br&gt;
&amp;gt; power-of-2 divide.  Hopefully MATLAB does a shift for an&lt;br&gt;
integer&lt;br&gt;
&amp;gt; power-of-2 divide.  If not, do it yourself with "bitshift".&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; gain = uint32(256*256) / (c1 - f1);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ch1 = gain * (uint32(t) - f1) / 256;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Peter&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi Peter,&lt;br&gt;
&lt;br&gt;
thanks for the suggestions. I tried to implement them but it&lt;br&gt;
didn't improve things. Perhaps I implemented them&lt;br&gt;
incorrectly? (See attempts 3 &amp; 4.)&lt;br&gt;
&lt;br&gt;
% attempt 1: speed ok (0.0137 sec) but poor gain resolution&lt;br&gt;
f1 = 10; &lt;br&gt;
c1 = 10;&lt;br&gt;
ch1 = (fread(fid1, frame_size, '*uint8')-f1)*(255/(c1-f1));&lt;br&gt;
&lt;br&gt;
% attempt 2: slow (0.025 sec) but poor gain resolution&lt;br&gt;
f1 = 10; &lt;br&gt;
c1 = 10;&lt;br&gt;
ch1=(fread(fid1,frame_size,'*uint8')-f1)*(255/double(c1-f1));&lt;br&gt;
&lt;br&gt;
% attempt 3: slow (0.025 sec) but poor gain resolution&lt;br&gt;
f1 = uint32(10);&lt;br&gt;
c1 = uint32(10);&lt;br&gt;
ch1 =&lt;br&gt;
uint8(uint32(255)*(uint32(fread(fid1,frame_size,'*uint8')-f1)/(c1-f1)));&lt;br&gt;
&lt;br&gt;
% attempt 4: slow (0.025 sec) but has good gain resolution&lt;br&gt;
f1 = uint32(10); % MATLAB f1 &amp; c1 to be uint32 not uint8&lt;br&gt;
c1 = uint32(10);&lt;br&gt;
gain = uint32(256*256)/(channel_ceiling-channel_floor);&lt;br&gt;
ch1=uint8(gain*(uint32(fread(fid,frame_size,'*uint8'))-f)/256);&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 08 May 2008 20:42:23 -0400</pubDate>
      <title>Re: load &amp; display multichannel images quickly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168963#431142</link>
      <author>Peter Boettcher</author>
      <description>"jay vaughan" &amp;lt;jvaughan5.nospam@gmail.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi again,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I am trying to optimize the speed of loading in three &lt;br&gt;
&amp;gt; MxN arrays and assigning them to an 8 bit MxNx3 array &lt;br&gt;
&amp;gt; (RGB) to be displayed.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; It's a sensitive part of a GUI I am working on, but&lt;br&gt;
&amp;gt; I am having trouble optimizing it. A shortened version of&lt;br&gt;
&amp;gt; the code is at the bottom.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; One problem is that if the floor and ceiling inputs,&lt;br&gt;
&amp;gt; (contrast/brightness parameters), are doubles then &lt;br&gt;
&amp;gt; MATLAB executes the code too slowly I presume since &lt;br&gt;
&amp;gt; it is converting the term (255/(c1-f1)) from double &lt;br&gt;
&amp;gt; to uint8. If the floor and ceiling inputs are uint8, &lt;br&gt;
&amp;gt; MATLAB executes the code more quickly but then &lt;br&gt;
&amp;gt; rounds the factor (255/(c1-f1)) before multiplying,&lt;br&gt;
&amp;gt; which reduces the bit depth of the contrast pretty &lt;br&gt;
&amp;gt; badly.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The speed is close to what I need (a factor of 2 &lt;br&gt;
&amp;gt; improvement would be great), but I am not sure how&lt;br&gt;
&amp;gt; to speed things up further.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Sometimes when I find myself in this kind of pickle&lt;br&gt;
&amp;gt; it means I am going about the problem the wrong way.&lt;br&gt;
&amp;gt; For instance, is there be a better solution with&lt;br&gt;
&amp;gt; some clever way of adjusting the colormapping &lt;br&gt;
&amp;gt; rather than adjusting the data itself?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; J&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % initialize frame&lt;br&gt;
&amp;gt; frame_size = [256 256];&lt;br&gt;
&amp;gt; frame = zeros(frame_size(1),frame_size(2),3,'uint8');&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % get floor &amp; ceiling inputs (min &amp; max in data channels)&lt;br&gt;
&amp;gt; f1 = 10; f2 = 10; f3 = 10;&lt;br&gt;
&amp;gt; c1 = 10; c2 = 10; c3 = 10;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % M maps data channels (row) to RGB weight (column)&lt;br&gt;
&amp;gt; M = [1 0 0; 0 1 0; 0 0 1]; &lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % read in the three data channels&lt;br&gt;
&amp;gt; ch1 = (fread(fid1, frame_size, '*uint8')-f1)*(255/(c1-f1));&lt;br&gt;
&amp;gt; ch2 = (fread(fid2, frame_size, '*uint8')-f2)*(255/(c2-f2));&lt;br&gt;
&amp;gt; ch3 = (fread(fid3, frame_size, '*uint8')-f3)*(255/(c3-f3));&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % map the channels to the RGB frame for display&lt;br&gt;
&amp;gt; frame(:,:,1) = M(1,1)*ch1 + M(1,2)*ch2 + M(1,3)*ch3;&lt;br&gt;
&amp;gt; frame(:,:,2) = M(2,1)*ch2 + M(2,2)*ch2 + M(2,3)*ch3;&lt;br&gt;
&amp;gt; frame(:,:,3) = M(3,1)*ch3 + M(3,2)*ch2 + M(3,3)*ch3;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; image(frame)&lt;br&gt;
&lt;br&gt;
You're right, casts to and from floating point are very slow.  I would&lt;br&gt;
stay in integer, but expand to an integer, do the operations, and return&lt;br&gt;
to uint8.  Careful with the operation ordering.&lt;br&gt;
&lt;br&gt;
f1 = uint32(10);&lt;br&gt;
c1 = uint32(100);&lt;br&gt;
&lt;br&gt;
t = fread(fid1, frame_size, '*uint8');&lt;br&gt;
ch1 = (uint32(255) * (uint32(t) - f1)) / (c1 - f1)&lt;br&gt;
&lt;br&gt;
By doing the multiply by 255 first, you don't have any precision&lt;br&gt;
problems, and the uint32 can hold the full range.&lt;br&gt;
&lt;br&gt;
Actually, you're even better off calculating the gain as a fixed&lt;br&gt;
point value, so that each operation is only a multiply followed by a&lt;br&gt;
power-of-2 divide.  Hopefully MATLAB does a shift for an integer&lt;br&gt;
power-of-2 divide.  If not, do it yourself with "bitshift".&lt;br&gt;
&lt;br&gt;
gain = uint32(256*256) / (c1 - f1);&lt;br&gt;
&lt;br&gt;
ch1 = gain * (uint32(t) - f1) / 256;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
-Peter&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 08 May 2008 19:06:05 -0400</pubDate>
      <title>load &amp; display multichannel images quickly</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168963#431130</link>
      <author>jay vaughan</author>
      <description>Hi again,&lt;br&gt;
&lt;br&gt;
I am trying to optimize the speed of loading in three &lt;br&gt;
MxN arrays and assigning them to an 8 bit MxNx3 array &lt;br&gt;
(RGB) to be displayed.&lt;br&gt;
&lt;br&gt;
It's a sensitive part of a GUI I am working on, but&lt;br&gt;
I am having trouble optimizing it. A shortened version of&lt;br&gt;
the code is at the bottom.&lt;br&gt;
&lt;br&gt;
One problem is that if the floor and ceiling inputs,&lt;br&gt;
(contrast/brightness parameters), are doubles then &lt;br&gt;
MATLAB executes the code too slowly I presume since &lt;br&gt;
it is converting the term (255/(c1-f1)) from double &lt;br&gt;
to uint8. If the floor and ceiling inputs are uint8, &lt;br&gt;
MATLAB executes the code more quickly but then &lt;br&gt;
rounds the factor (255/(c1-f1)) before multiplying,&lt;br&gt;
which reduces the bit depth of the contrast pretty &lt;br&gt;
badly.&lt;br&gt;
&lt;br&gt;
The speed is close to what I need (a factor of 2 &lt;br&gt;
improvement would be great), but I am not sure how&lt;br&gt;
to speed things up further.&lt;br&gt;
&lt;br&gt;
Sometimes when I find myself in this kind of pickle&lt;br&gt;
it means I am going about the problem the wrong way.&lt;br&gt;
For instance, is there be a better solution with&lt;br&gt;
some clever way of adjusting the colormapping &lt;br&gt;
rather than adjusting the data itself?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
J&lt;br&gt;
&lt;br&gt;
% initialize frame&lt;br&gt;
frame_size = [256 256];&lt;br&gt;
frame = zeros(frame_size(1),frame_size(2),3,'uint8');&lt;br&gt;
&lt;br&gt;
% get floor &amp; ceiling inputs (min &amp; max in data channels)&lt;br&gt;
f1 = 10; f2 = 10; f3 = 10;&lt;br&gt;
c1 = 10; c2 = 10; c3 = 10;&lt;br&gt;
&lt;br&gt;
% M maps data channels (row) to RGB weight (column)&lt;br&gt;
M = [1 0 0; 0 1 0; 0 0 1]; &lt;br&gt;
&lt;br&gt;
% read in the three data channels&lt;br&gt;
ch1 = (fread(fid1, frame_size, '*uint8')-f1)*(255/(c1-f1));&lt;br&gt;
ch2 = (fread(fid2, frame_size, '*uint8')-f2)*(255/(c2-f2));&lt;br&gt;
ch3 = (fread(fid3, frame_size, '*uint8')-f3)*(255/(c3-f3));&lt;br&gt;
&lt;br&gt;
% map the channels to the RGB frame for display&lt;br&gt;
frame(:,:,1) = M(1,1)*ch1 + M(1,2)*ch2 + M(1,3)*ch3;&lt;br&gt;
frame(:,:,2) = M(2,1)*ch2 + M(2,2)*ch2 + M(2,3)*ch3;&lt;br&gt;
frame(:,:,3) = M(3,1)*ch3 + M(3,2)*ch2 + M(3,3)*ch3;&lt;br&gt;
&lt;br&gt;
image(frame)&lt;br&gt;
&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
