<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Steve on Image Processing</title>
	
	<link>http://blogs.mathworks.com/steve</link>
	<description>Steve Eddins manages the Image &amp; Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.</description>
	<lastBuildDate>Wed, 16 May 2012 02:19:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/SteveOnImageProcessing" /><feedburner:info uri="steveonimageprocessing" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Shuffling label colors</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/Eu7aYvLLLDY/</link>
		<comments>http://blogs.mathworks.com/steve/2012/05/15/shuffling-label-colors/#comments</comments>
		<pubDate>Wed, 16 May 2012 02:19:00 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=558</guid>
		<description><![CDATA[I've written often here about various computational and visualization techniques involving labeling connected components in binary images. Sometimes I use the function label2rgb to convert a label matrix into a color image with a different color assigned to each label. Here's an example.bw = imread('http://blogs.mathworks.com/images/steve/2012/rice-bw.png'); imshow(bw) Now compute the connected components and the corresponding label [...]]]></description>
			<content:encoded><![CDATA[<div xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" class="content">
   <p>I've written often here about various computational and visualization techniques involving labeling connected components in
      binary images. Sometimes I use the function <tt>label2rgb</tt> to convert a label matrix into a color image with a different color assigned to each label.
   </p>
   <p>Here's an example.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">bw = imread(<span style="color: #A020F0">'http://blogs.mathworks.com/images/steve/2012/rice-bw.png'</span>);
imshow(bw)</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/shuffle_label_colors_01.png"> <p>Now compute the connected components and the corresponding label matrix.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">cc = bwconncomp(bw);
L = labelmatrix(cc);</pre><p>In the label matrix, each foreground object in the original binary image is assigned a unique positive integer. Here, for
      instance, is how to display the tenth object.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imshow(L == 10)</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/shuffle_label_colors_02.png"> <p>Use the function <tt>label2rgb</tt> to "colorize" the label matrix.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">rgb = label2rgb(L);
imshow(rgb)</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/shuffle_label_colors_03.png"> <p>That's a nice effect, but because of the way the colors are assigned, object near each other tend to have very similar colors.
      It might be better sometimes to assign the colors differently. That's what the <tt>'shuffle'</tt> argument to <tt>label2rgb</tt> is for.
   </p>
   <p>Here's the full syntax including <tt>'shuffle'</tt>:
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">rgb = label2rgb(L,map,zerocolor,<span style="color: #A020F0">'shuffle'</span>);</pre><p><tt>zerocolor</tt> is a three-element vector specifying what color is used for the background pixels.
   </p>
   <p>Let's try it with the jet colormap and a light gray background color.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">rgb = label2rgb(L,<span style="color: #A020F0">'jet'</span>,[.7 .7 .7],<span style="color: #A020F0">'shuffle'</span>);
imshow(rgb)</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/shuffle_label_colors_04.png"> <p>Now it's easier to see where two objects might be actually touching and so receive the same label. Let's zoom in closer to
      see:
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">xlim([128 185]);
ylim([5 62]);</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/shuffle_label_colors_05.png"> <p>I hope you find this useful!</p><script language="JavaScript">
<!--

    function grabCode_244262ec1ea44d08b9c018a05519a680() {
        // Remember the title so we can use it in the new page
        title = document.title;

        // Break up these strings so that their presence
        // in the Javascript doesn't mess up the search for
        // the MATLAB code.
        t1='244262ec1ea44d08b9c018a05519a680 ' + '##### ' + 'SOURCE BEGIN' + ' #####';
        t2='##### ' + 'SOURCE END' + ' #####' + ' 244262ec1ea44d08b9c018a05519a680';
    
        b=document.getElementsByTagName('body')[0];
        i1=b.innerHTML.indexOf(t1)+t1.length;
        i2=b.innerHTML.indexOf(t2);
 
        code_string = b.innerHTML.substring(i1, i2);
        code_string = code_string.replace(/REPLACE_WITH_DASH_DASH/g,'--');

        // Use /x3C/g instead of the less-than character to avoid errors 
        // in the XML parser.
        // Use '\x26#60;' instead of '<' so that the XML parser
        // doesn't go ahead and substitute the less-than character. 
        code_string = code_string.replace(/\x3C/g, '\x26#60;');

        author = 'Steve Eddins';
        copyright = 'Copyright 2012 The MathWorks, Inc.';

        w = window.open();
        d = w.document;
        d.write('<pre>\n');
        d.write(code_string);

        // Add author and copyright lines at the bottom if specified.
        if ((author.length > 0) || (copyright.length > 0)) {
            d.writeln('');
            d.writeln('%%');
            if (author.length > 0) {
                d.writeln('% _' + author + '_');
            }
            if (copyright.length > 0) {
                d.writeln('% _' + copyright + '_');
            }
        }

        d.write('</pre>\n');
      
      d.title = title + ' (MATLAB code)';
      d.close();
      }   
      
-->
</script><p style="text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray"><br /><a href="javascript:grabCode_244262ec1ea44d08b9c018a05519a680()"><span style="font-size: x-small;        font-style: italic;">Get 
            the MATLAB code 
            <noscript>(requires JavaScript)</noscript></span></a><br /><br />
      Published with MATLAB&reg; 7.14<br /></p>
</div>
<!--
244262ec1ea44d08b9c018a05519a680 ##### SOURCE BEGIN #####
%%
% I've written often here about various computational and visualization
% techniques involving labeling connected components in binary images.
% Sometimes I use the function |label2rgb| to convert a label matrix into a
% color image with a different color assigned to each label.
%
% Here's an example.

bw = imread('http://blogs.mathworks.com/images/steve/2012/rice-bw.png');
imshow(bw)

%%
% Now compute the connected components and the corresponding label matrix.

cc = bwconncomp(bw);
L = labelmatrix(cc);

%%
% In the label matrix, each foreground object in the original binary image
% is assigned a unique positive integer. Here, for instance, is how to
% display the tenth object.

imshow(L == 10)

%%
% Use the function |label2rgb| to "colorize" the label matrix.

rgb = label2rgb(L);
imshow(rgb)

%%
% That's a nice effect, but because of the way the colors are assigned,
% object near each other tend to have very similar colors. It might be
% better sometimes to assign the colors differently. That's what the
% |'shuffle'| argument to |label2rgb| is for.
%
% Here's the full syntax including |'shuffle'|:
%
%   rgb = label2rgb(L,map,zerocolor,'shuffle');
%
% |zerocolor| is a three-element vector specifying what color is used for
% the background pixels.
%
% Let's try it with the jet colormap and a light gray background color.

rgb = label2rgb(L,'jet',[.7 .7 .7],'shuffle');
imshow(rgb)

%%
% Now it's easier to see where two objects might be actually touching and
% so receive the same label. Let's zoom in closer to see:

xlim([128 185]);
ylim([5 62]);

%%
% I hope you find this useful!
##### SOURCE END ##### 244262ec1ea44d08b9c018a05519a680
--><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/Eu7aYvLLLDY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/05/15/shuffling-label-colors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/05/15/shuffling-label-colors/</feedburner:origLink></item>
		<item>
		<title>The DFT matrix and computation time</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/y1Mqfcvz8LE/</link>
		<comments>http://blogs.mathworks.com/steve/2012/05/01/the-dft-matrix-and-computation-time/#comments</comments>
		<pubDate>Tue, 01 May 2012 22:06:59 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=555</guid>
		<description><![CDATA[On my list of potential blog topics today I saw just this cryptic item labeled dftmtx. Hmm, the MATLAB dftmtx function. But have I written about this function before? I better double-check by searching the old blog postings: Oh, I forgot about Loren's post! She showed how the discrete Fourier transform, which MATLAB users normally [...]]]></description>
			<content:encoded><![CDATA[<div xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" class="content">
   <p>On my list of potential blog topics today I saw just this cryptic item labeled <tt>dftmtx</tt>.  Hmm, the MATLAB <tt>dftmtx</tt> function. But have I written about this function before? I better double-check by searching the old blog postings:
   </p>
   <p><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/search_dftmtx.png"> </p>
   <p>Oh, I forgot about <a href="http://blogs.mathworks.com/loren/2009/02/02/a-pedagogical-tool-for-fourier-transforms/">Loren's post!</a> She showed how the discrete Fourier transform, which MATLAB users normally compute by calling <tt>fft</tt>, can also be computed via a matrix multiply.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">x = rand(1000,1);
X = fft(x);

T = dftmtx(1000);
X2 = T*x;

max(abs(X2(:) - X(:)))</pre><pre style="font-style:oblique">
ans =

   3.9790e-13

</pre><p>The difference is just floating-point round-off error.</p>
   <p><a href="http://blogs.mathworks.com/steve/2008/09/11/independent-computation-in-software-tests/">My old post</a> talked about the value of having an independent computation method available when you are testing your algorithm.
   </p>
   <p>So today let's do something a little different. Let's compare the performance of computing the discrete Fourier transform
      using the DFT matrix versus using the fast Fourier transform.
   </p>
   <p>To help with the timing, I'm going to use a function I wrote called <tt>timeit</tt> that you can <a href="http://www.mathworks.com/matlabcentral/fileexchange/18798-timeit-benchmarking-function">download</a> from the MATLAB Central File Exchange.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">clear
n = 100:50:3000;
<span style="color: #0000FF">for</span> k = 1:length(n)
    nk = n(k);
    x = rand(nk,1);
    T = dftmtx(nk);

    f = @() T*x;
    g = @() fft(x);

    times_f(k) = timeit(f);
    times_g(k) = timeit(g);
<span style="color: #0000FF">end</span>

plot(n,times_f,n,times_g)
legend({<span style="color: #A020F0">'Using T*x'</span>, <span style="color: #A020F0">'Using fft(x)'</span>})</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/timing_dftmtx_01.png"> <p>That's a pretty dramatic difference. The blue curve, showing the computation time using <tt>T*x</tt>, is an n^2 curve. Compared to that, the green curve, showing the computation time using <tt>fft(x)</tt>, is so low that you can hardly see it.
   </p>
   <p>Let's expand the y axis.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">ylim([0 0.0005])</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/timing_dftmtx_02.png"> <p>The lower green curve is an n*log(n) curve. The dramatic difference between that and the n^2 curve is why everyone got so
      excited when the fast Fourier transform algorithm was invented (or <a href="http://en.wikipedia.org/wiki/Fast_Fourier_transform#Cooley.E2.80.93Tukey_algorithm">re-invented</a>) a few decades ago.
   </p><script language="JavaScript">
<!--

    function grabCode_85fcd7bddddb40419a09e40981140863() {
        // Remember the title so we can use it in the new page
        title = document.title;

        // Break up these strings so that their presence
        // in the Javascript doesn't mess up the search for
        // the MATLAB code.
        t1='85fcd7bddddb40419a09e40981140863 ' + '##### ' + 'SOURCE BEGIN' + ' #####';
        t2='##### ' + 'SOURCE END' + ' #####' + ' 85fcd7bddddb40419a09e40981140863';
    
        b=document.getElementsByTagName('body')[0];
        i1=b.innerHTML.indexOf(t1)+t1.length;
        i2=b.innerHTML.indexOf(t2);
 
        code_string = b.innerHTML.substring(i1, i2);
        code_string = code_string.replace(/REPLACE_WITH_DASH_DASH/g,'--');

        // Use /x3C/g instead of the less-than character to avoid errors 
        // in the XML parser.
        // Use '\x26#60;' instead of '<' so that the XML parser
        // doesn't go ahead and substitute the less-than character. 
        code_string = code_string.replace(/\x3C/g, '\x26#60;');

        author = 'Steve Eddins';
        copyright = 'Copyright 2012 The MathWorks, Inc.';

        w = window.open();
        d = w.document;
        d.write('<pre>\n');
        d.write(code_string);

        // Add author and copyright lines at the bottom if specified.
        if ((author.length > 0) || (copyright.length > 0)) {
            d.writeln('');
            d.writeln('%%');
            if (author.length > 0) {
                d.writeln('% _' + author + '_');
            }
            if (copyright.length > 0) {
                d.writeln('% _' + copyright + '_');
            }
        }

        d.write('</pre>\n');
      
      d.title = title + ' (MATLAB code)';
      d.close();
      }   
      
-->
</script><p style="text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray"><br /><a href="javascript:grabCode_85fcd7bddddb40419a09e40981140863()"><span style="font-size: x-small;        font-style: italic;">Get 
            the MATLAB code 
            <noscript>(requires JavaScript)</noscript></span></a><br /><br />
      Published with MATLAB&reg; 7.14<br /></p>
</div>
<!--
85fcd7bddddb40419a09e40981140863 ##### SOURCE BEGIN #####
%%
% On my list of potential blog topics today I saw just this cryptic item
% labeled |dftmtx|.  Hmm, the MATLAB |dftmtx| function. But have I written
% about this function before? I better double-check by searching the old
% blog postings:
%
% <<http://blogs.mathworks.com/images/steve/2012/search_dftmtx.png>>
%
% Oh, I forgot about
% <http://blogs.mathworks.com/loren/2009/02/02/a-pedagogical-tool-for-fourier-transforms/
% Loren's post!> She showed how the discrete Fourier transform, which
% MATLAB users normally compute by calling |fft|, can also be computed via
% a matrix multiply.

x = rand(1000,1);
X = fft(x);

T = dftmtx(1000);
X2 = T*x;

max(abs(X2(:) - X(:)))

%%
% The difference is just floating-point round-off error.
%
% <http://blogs.mathworks.com/steve/2008/09/11/independent-computation-in-software-tests/
% My old post> talked about the value of having an independent computation
% method available when you are testing your algorithm.
%
% So today let's do something a little different. Let's compare the
% performance of computing the discrete Fourier transform using the DFT
% matrix versus using the fast Fourier transform.
%
% To help with the timing, I'm going to use a function I wrote called
% |timeit| that you can
% <http://www.mathworks.com/matlabcentral/fileexchange/18798-timeit-benchmarking-function
% download> from the MATLAB Central File Exchange.

%%
clear
n = 100:50:3000;
for k = 1:length(n)
    nk = n(k);
    x = rand(nk,1);
    T = dftmtx(nk);
    
    f = @() T*x;
    g = @() fft(x);
    
    times_f(k) = timeit(f);
    times_g(k) = timeit(g);
end

plot(n,times_f,n,times_g)
legend({'Using T*x', 'Using fft(x)'})
    
%%
% That's a pretty dramatic difference. The blue curve, showing the
% computation time using |T*x|, is an n^2 curve. Compared to that, the
% green curve, showing the computation time using |fft(x)|, is so low that
% you can hardly see it.
%
% Let's expand the y axis.

ylim([0 0.0005])

%%
% The lower green curve is an n*log(n) curve. The dramatic difference
% between that and the n^2 curve is why everyone got so excited when the
% fast Fourier transform algorithm was invented (or
% <http://en.wikipedia.org/wiki/Fast_Fourier_transform#Cooley.E2.80.93Tukey_algorithm
% re-invented>) a few decades ago.

##### SOURCE END ##### 85fcd7bddddb40419a09e40981140863
--><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/y1Mqfcvz8LE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/05/01/the-dft-matrix-and-computation-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/05/01/the-dft-matrix-and-computation-time/</feedburner:origLink></item>
		<item>
		<title>And now for something completely different</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/yTzKLpSurMg/</link>
		<comments>http://blogs.mathworks.com/steve/2012/04/11/and-now-for-something-completely-different/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 12:00:40 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=544</guid>
		<description><![CDATA[The following video spread up and down the MATLAB Math team's hallway like wildfire yesterday: http://www.youtube.com/watch?v=ywWBy6J5gz8 I said there was some room for improvement because I thought the last 20 seconds or so of the algorithm could be optimized away. However, math developer Bobby informed me that those last few dance steps are necessary to [...]]]></description>
			<content:encoded><![CDATA[<p>
The following video spread up and down the MATLAB Math team's hallway like wildfire yesterday:
<p>

<p>
<a href="http://www.youtube.com/watch?v=ywWBy6J5gz8" title="Quicksort video">http://www.youtube.com/watch?v=ywWBy6J5gz8</a>
</p>

<p>
I said there was some room for improvement because I thought the last 20 seconds or so of the algorithm could be optimized away. However, math developer Bobby informed me that those last few dance steps are necessary to make sure that the right thing happens when the input contains NaNs.  (Thanks also to Bobby for providing the title of today's post.)
</p><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/yTzKLpSurMg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/04/11/and-now-for-something-completely-different/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/04/11/and-now-for-something-completely-different/</feedburner:origLink></item>
		<item>
		<title>imzoneplate on the File Exchange</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/fWQIvqnuNYE/</link>
		<comments>http://blogs.mathworks.com/steve/2012/04/10/imzoneplate-on-the-file-exchange/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 12:45:46 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=540</guid>
		<description><![CDATA[Last year I posted a few times about the "J&#228;hne test pattern," something that readers then told me was called a zone plate. This is a radial sinusoid pattern with low frequency in the middle of the image and high frequency toward the edges: In my 02-Jul-2012 post, Filtering fun, I used the zone plate [...]]]></description>
			<content:encoded><![CDATA[<div xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" class="content">
   <p>Last year I <a href="http://blogs.mathworks.com/steve/2011/07/19/jahne-test-pattern-take-3/">posted a few times</a> about the "J&auml;hne test pattern," something that readers then told me was called a zone plate. This is a radial sinusoid pattern
      with low frequency in the middle of the image and high frequency toward the edges:
   </p>
   <p><img vspace="5" hspace="5" src="http://www.mathworks.com/matlabcentral/fx_files/35961/1/preview.jpg"> </p>
   <p>In my 02-Jul-2012 post, <a href="http://blogs.mathworks.com/steve/2011/07/22/filtering-fun/">Filtering fun</a>, I used the zone plate image to illustrate the effects of different kinds of frequency-selective filtering.
   </p>
   <p>Lowpass:</p>
   <p><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2011/filtering_fun_02.jpg"> </p>
   <p>Bandpass:</p>
   <p><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2011/filtering_fun_04.jpg"> </p>
   <p>Directional:</p>
   <p><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2011/filtering_fun_09.jpg"> </p>
   <p>Last week I submitted a function called <a href="http://www.mathworks.com/matlabcentral/fileexchange/35961-zone-plate-test-image"><tt>imzoneplate</tt></a> to the MATLAB Central File Exchange.
   </p>
   <p>I resisted the urge to give <tt>imzoneplate</tt> a lot of optional parameters. Instead there's only one, the size of the image.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imshow(imzoneplate(301))</pre><p>Here's a smaller zone plate image and its horizontal cross-section.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">I = imzoneplate(151);
imshow(I)</pre><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">plot(I(76,:))</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/zone_plate_02.jpg"> <p>Let's zoom in at the edge of the plot.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">xlim([140 151])</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/zone_plate_03.jpg"> <p>You can see that, with the parameters I've chosen for <tt>imzoneplate</tt>, the sinusoidal period decreases to about 3 samples at the edge of the image.
   </p>
   <p>Be sure to download <a href="http://www.mathworks.com/matlabcentral/fileexchange/35961-zone-plate-test-image"><tt>imzoneplate</tt></a> and give it a try. Post a comment here if you have a particular application for it.
   </p><script language="JavaScript">
<!--

    function grabCode_8df1554297904ad696551a3b286b5931() {
        // Remember the title so we can use it in the new page
        title = document.title;

        // Break up these strings so that their presence
        // in the Javascript doesn't mess up the search for
        // the MATLAB code.
        t1='8df1554297904ad696551a3b286b5931 ' + '##### ' + 'SOURCE BEGIN' + ' #####';
        t2='##### ' + 'SOURCE END' + ' #####' + ' 8df1554297904ad696551a3b286b5931';
    
        b=document.getElementsByTagName('body')[0];
        i1=b.innerHTML.indexOf(t1)+t1.length;
        i2=b.innerHTML.indexOf(t2);
 
        code_string = b.innerHTML.substring(i1, i2);
        code_string = code_string.replace(/REPLACE_WITH_DASH_DASH/g,'--');

        // Use /x3C/g instead of the less-than character to avoid errors 
        // in the XML parser.
        // Use '\x26#60;' instead of '<' so that the XML parser
        // doesn't go ahead and substitute the less-than character. 
        code_string = code_string.replace(/\x3C/g, '\x26#60;');

        author = 'Steve Eddins';
        copyright = 'Copyright 2012 The MathWorks, Inc.';

        w = window.open();
        d = w.document;
        d.write('<pre>\n');
        d.write(code_string);

        // Add author and copyright lines at the bottom if specified.
        if ((author.length > 0) || (copyright.length > 0)) {
            d.writeln('');
            d.writeln('%%');
            if (author.length > 0) {
                d.writeln('% _' + author + '_');
            }
            if (copyright.length > 0) {
                d.writeln('% _' + copyright + '_');
            }
        }

        d.write('</pre>\n');
      
      d.title = title + ' (MATLAB code)';
      d.close();
      }   
      
-->
</script><p style="text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray"><br /><a href="javascript:grabCode_8df1554297904ad696551a3b286b5931()"><span style="font-size: x-small;        font-style: italic;">Get 
            the MATLAB code 
            <noscript>(requires JavaScript)</noscript></span></a><br /><br />
      Published with MATLAB&reg; 7.14<br /></p>
</div>
<!--
8df1554297904ad696551a3b286b5931 ##### SOURCE BEGIN #####
%%
% Last year I
% <http://blogs.mathworks.com/steve/2011/07/19/jahne-test-pattern-take-3/
% posted a few times> about the "JÃ¤hne test pattern," something that
% readers then told me was called a zone plate. This is a radial sinusoid
% pattern with low frequency in the middle of the image and high frequency
% toward the edges:
%
% <<http://www.mathworks.com/matlabcentral/fx_files/35961/1/preview.jpg>>
%
% In my 02-Jul-2012 post, <http://blogs.mathworks.com/steve/2011/07/22/filtering-fun/ 
% Filtering fun>, I used the zone plate image to
% illustrate the effects of different kinds of frequency-selective
% filtering.
%
% Lowpass:
%
% <<http://blogs.mathworks.com/images/steve/2011/filtering_fun_02.jpg>>
%
% Bandpass:
%
% <<http://blogs.mathworks.com/images/steve/2011/filtering_fun_04.jpg>>
%
% Directional:
%
% <<http://blogs.mathworks.com/images/steve/2011/filtering_fun_09.jpg>>
%
% Last week I submitted a function called
% <http://www.mathworks.com/matlabcentral/fileexchange/35961-zone-plate-test-image
% |imzoneplate|> to the MATLAB Central File Exchange. 
%
% I resisted the urge to give |imzoneplate| a lot of optional parameters.
% Instead there's only one, the size of the image.

imshow(imzoneplate(301))

%%
% Here's a smaller zone plate image and its horizontal cross-section.

I = imzoneplate(151);
imshow(I)

%%
plot(I(76,:))

%%
% Let's zoom in at the edge of the plot.

xlim([140 151])

%%
% You can see that, with the parameters I've chosen for |imzoneplate|, the
% sinusoidal period decreases to about 3 samples at the edge of the image.
%
% Be sure to download <http://www.mathworks.com/matlabcentral/fileexchange/35961-zone-plate-test-image
% |imzoneplate|> and give it a try. Post a comment here if you have a
% particular application for it.
##### SOURCE END ##### 8df1554297904ad696551a3b286b5931
--><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/fWQIvqnuNYE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/04/10/imzoneplate-on-the-file-exchange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/04/10/imzoneplate-on-the-file-exchange/</feedburner:origLink></item>
		<item>
		<title>Bug reports on mathworks.com – “Fixed in R2012a”</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/X8JhatkbhXA/</link>
		<comments>http://blogs.mathworks.com/steve/2012/04/06/bug-reports-on-mathworks-com-%e2%80%93-%e2%80%9cfixed-in-r2012a%e2%80%9d/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 12:00:51 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=526</guid>
		<description><![CDATA[Do you want to know what bugs have been fixed in R2012a for your favorite products? Are you looking for a workaround for a bug? Try visiting the "Bug Reports" section of mathworks.com. Start by clicking on Support. Then click on Bug Reports. To find out which bugs have been fixed in R2012a in the [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to know what bugs have been fixed in R2012a for your favorite products? Are you looking for a workaround for a bug? Try visiting the "Bug Reports" section of mathworks.com.
</p><p>Start by clicking on <a href="http://www.mathworks.com/support/">Support</a>.
</p><p>Then click on <a href="http://www.mathworks.com/support/bugreports/">Bug Reports</a>.
</p><p>To find out which bugs have been fixed in R2012a in the Image Processing Toolbox, for example, perform the following search:
</p><p><img src="http://blogs.mathworks.com/steve/files/033112_1222_Bugreportso12.png" alt=""/>
	</p><p>Here's the result:
</p><p><img src="http://blogs.mathworks.com/steve/files/033112_1222_Bugreportso22.png" alt=""/>
	</p><p>This icon:
</p><p><img src="http://blogs.mathworks.com/steve/files/033112_1222_Bugreportso32.png" alt=""/>
	</p><p>means that there is a way to work around the problem if you are using an earlier release.
</p><p>I want to mention the iradon issue in particular and acknowledge Bob Alvarez, who called our attention to it with a <a href="http://blogs.mathworks.com/steve/2010/04/19/performance-improvements-in-r2010a/">blog comment last July</a>. (However, you should generally report product bugs directly to <a href="http://www.mathworks.com/support/">MathWorks technical support</a> rather than posting them as comments on this or other MATLAB Central blogs. My usual practice is to delete comments that aren't directly relevant to the topic of the blog post.)
</p><p>We are, of course, continually trying to improve the quality of our products and therefore reduce the need for published bug reports.</p><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/X8JhatkbhXA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/04/06/bug-reports-on-mathworks-com-%e2%80%93-%e2%80%9cfixed-in-r2012a%e2%80%9d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/04/06/bug-reports-on-mathworks-com-%e2%80%93-%e2%80%9cfixed-in-r2012a%e2%80%9d/</feedburner:origLink></item>
		<item>
		<title>MATLAB R2012a</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/diisF0aiZ60/</link>
		<comments>http://blogs.mathworks.com/steve/2012/04/03/matlab-r2012a/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 12:00:28 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=512</guid>
		<description><![CDATA[Some of my fellow MATLAB Central bloggers have already talked about the MATLAB R2012a release. Usually, I like to scan the release notes and pick out just a few things that particularly interest me. I encourage you to take a look at the release notes to see what else is there that might interest you. [...]]]></description>
			<content:encoded><![CDATA[<div xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" class="content">
   <p>Some of my fellow <a href="http://blogs.mathworks.com">MATLAB Central bloggers</a> have already talked about the MATLAB R2012a release. Usually, I like to scan the release notes and pick out just a few things
      that particularly interest me. I encourage you to take a look at the <a href="http://www.mathworks.com/help/techdoc/rn/rn_intro.html">release notes</a> to see what else is there that might interest you.
   </p>
   <p>I was particularly happy to see that the web browser system built into MATLAB (used for various purposes, including the help
      system and the publish feature) was completely overhauled so that it looks a lot better on 64-bit Windows systems.
   </p>
   <p>Speaking of the <a href="http://www.mathworks.com/help/techdoc/matlab_env/f6-22451.html">publish</a> feature, have you heard of it? It's a great way to turn a MATLAB script (or function) into a web page, or a PDF, or a Word
      document. I use it to create almost all of my blog posts. You can find a lot of examples online by searching for the phrase
      "Published with MATLAB", such as <a href="http://www2.math.umd.edu/~jmr/241/calc.html">Calculus with MATLAB</a>. Anyway, you can include syntax-highlighted code in your published output. For example:
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">bw = imread(<span style="color: #A020F0">'text.png'</span>);
s = regionprops(bw, {<span style="color: #A020F0">'Area'</span>, <span style="color: #A020F0">'Centroid'</span>});
imshow(bw)
hold <span style="color: #A020F0">on</span>
<span style="color: #0000FF">for</span> k = 1:numel(s)
  plot(s(k).Centroid(1), s(k).Centroid(2), <span style="color: #A020F0">'b*'</span>);
<span style="color: #0000FF">end</span>
hold <span style="color: #A020F0">off</span></pre><p>There are several enhancements in the math area that interest me. For example, there are new numerical integration functions
      (<tt>integral</tt>, <tt>integral2</tt>, <tt>integral3</tt>) that have more capabilities than the functions they replace (<tt>quad</tt> and its cousins). Try an integration over an unbounded interval using <tt>integral</tt>:
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">fun = @(x) exp(-x.^2).*log(x).^2;
integral(fun,0,inf)</pre><pre style="font-style:oblique">
ans =

    1.9475

</pre><p>With <tt>quad</tt> that didn't work so well:
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">quad(fun,0,inf)</pre><pre style="font-style:oblique">Warning: Infinite or Not-a-Number function value encountered. 

ans =

   NaN

</pre><p>The <tt>griddata</tt> function now supports natural neighbor interpolation.
   </p>
   <p>And the <tt>unique</tt> function now has an additional option to preserve the original order of the data. I really like this one. The output of <tt>unique</tt> is normally sorted. Although you can postprocess the output to restore the original data order, it's tricky and I always
      puzzled over it a bit. With the new optional argument, it's really easy.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">data = [3 2 9 4 8 1 1 10 1 2];
unique(data)</pre><pre style="font-style:oblique">
ans =

     1     2     3     4     8     9    10

</pre><p>You can see that the duplicates were removed and the result is sorted.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">unique(data,<span style="color: #A020F0">'stable'</span>)</pre><pre style="font-style:oblique">
ans =

     3     2     9     4     8     1    10

</pre><p>Now the original data order has been preserved.</p>
   <p>There are several nice enhancements in the file import/export area, including:</p>
   <div>
      <ul>
         <li>.xlsx files can now be read on all platforms</li>
         <li>FITS export</li>
         <li>OPeNDAP protocol support (using the netcdf functions)</li>
      </ul>
   </div>
   <p>Finally, if you are really into object-oriented programming using MATLAB, check out the new ability to <a href="http://www.mathworks.com/help/techdoc/matlab_oop/bs885dm.html">control the set of allowed subclasses</a>, as well as the ability to <a href="http://www.mathworks.com/help/techdoc/matlab_oop/bs888fp.html">control access to class members</a>.
   </p><script language="JavaScript">
<!--

    function grabCode_88579f9a1f8e4383a425f94a46a02d9f() {
        // Remember the title so we can use it in the new page
        title = document.title;

        // Break up these strings so that their presence
        // in the Javascript doesn't mess up the search for
        // the MATLAB code.
        t1='88579f9a1f8e4383a425f94a46a02d9f ' + '##### ' + 'SOURCE BEGIN' + ' #####';
        t2='##### ' + 'SOURCE END' + ' #####' + ' 88579f9a1f8e4383a425f94a46a02d9f';
    
        b=document.getElementsByTagName('body')[0];
        i1=b.innerHTML.indexOf(t1)+t1.length;
        i2=b.innerHTML.indexOf(t2);
 
        code_string = b.innerHTML.substring(i1, i2);
        code_string = code_string.replace(/REPLACE_WITH_DASH_DASH/g,'--');

        // Use /x3C/g instead of the less-than character to avoid errors 
        // in the XML parser.
        // Use '\x26#60;' instead of '<' so that the XML parser
        // doesn't go ahead and substitute the less-than character. 
        code_string = code_string.replace(/\x3C/g, '\x26#60;');

        author = 'Steve Eddins';
        copyright = 'Copyright 2012 The MathWorks, Inc.';

        w = window.open();
        d = w.document;
        d.write('<pre>\n');
        d.write(code_string);

        // Add author and copyright lines at the bottom if specified.
        if ((author.length > 0) || (copyright.length > 0)) {
            d.writeln('');
            d.writeln('%%');
            if (author.length > 0) {
                d.writeln('% _' + author + '_');
            }
            if (copyright.length > 0) {
                d.writeln('% _' + copyright + '_');
            }
        }

        d.write('</pre>\n');
      
      d.title = title + ' (MATLAB code)';
      d.close();
      }   
      
-->
</script><p style="text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray"><br /><a href="javascript:grabCode_88579f9a1f8e4383a425f94a46a02d9f()"><span style="font-size: x-small;        font-style: italic;">Get 
            the MATLAB code 
            <noscript>(requires JavaScript)</noscript></span></a><br /><br />
      Published with MATLAB&reg; 7.14<br /></p>
</div>
<!--
88579f9a1f8e4383a425f94a46a02d9f ##### SOURCE BEGIN #####
%%
% Some of my fellow <http://blogs.mathworks.com MATLAB Central bloggers>
% have already talked about the MATLAB R2012a release. Usually, I like to
% scan the release notes and pick out just a few things that particularly
% interest me. I encourage you to take a look at the
% <http://www.mathworks.com/help/techdoc/rn/rn_intro.html release notes> to
% see what else is there that might interest you.
%
% I was particularly happy to see that the web browser system built into
% MATLAB (used for various purposes, including the help system and the
% publish feature) was completely overhauled so that it looks a lot better
% on 64-bit Windows systems.
%
% Speaking of the
% <http://www.mathworks.com/help/techdoc/matlab_env/f6-22451.html publish>
% feature, have you heard of it? It's a great way to turn a MATLAB script
% (or function) into a web page, or a PDF, or a Word document. I use it to
% create almost all of my blog posts. You can find a lot of examples online
% by searching for the phrase "Published with MATLAB", such as
% <http://www2.math.umd.edu/~jmr/241/calc.html Calculus with MATLAB>.
% Anyway, you can include syntax-highlighted code in your published output.
% For example:
%
%   bw = imread('text.png');
%   s = regionprops(bw, {'Area', 'Centroid'});
%   imshow(bw)
%   hold on
%   for k = 1:numel(s)
%     plot(s(k).Centroid(1), s(k).Centroid(2), 'b*');
%   end
%   hold off
%
% There are several enhancements in the math area that interest me. For
% example, there are new numerical integration functions (|integral|,
% |integral2|, |integral3|) that have more capabilities than the functions
% they replace (|quad| and its cousins). Try an integration over an
% unbounded interval using |integral|:

fun = @(x) exp(-x.^2).*log(x).^2;
integral(fun,0,inf)

%%
% With |quad| that didn't work so well:

quad(fun,0,inf)

%%
% The |griddata| function now supports natural neighbor interpolation.
%
% And the |unique| function now has an additional option to preserve the
% original order of the data. I really like this one. The output of
% |unique| is normally sorted. Although you can postprocess the output to
% restore the original data order, it's tricky and I always puzzled over it
% a bit. With the new optional argument, it's really easy.

data = [3 2 9 4 8 1 1 10 1 2];
unique(data)

%%
% You can see that the duplicates were removed and the result is sorted.

unique(data,'stable')

%%
% Now the original data order has been preserved.
%
% There are several nice enhancements in the file import/export area,
% including:
%
% * .xlsx files can now be read on all platforms
% * FITS export
% * OPeNDAP protocol support (using the netcdf functions)
%
% Finally, if you are really into object-oriented programming using MATLAB,
% check out the new ability to
% <http://www.mathworks.com/help/techdoc/matlab_oop/bs885dm.html control
% the set of allowed subclasses>, as well as the ability to
% <http://www.mathworks.com/help/techdoc/matlab_oop/bs888fp.html control
% access to class members>.

##### SOURCE END ##### 88579f9a1f8e4383a425f94a46a02d9f
--><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/diisF0aiZ60" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/04/03/matlab-r2012a/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/04/03/matlab-r2012a/</feedburner:origLink></item>
		<item>
		<title>Image Processing and Computer Vision Updates in R2012a</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/20K91wZUNEM/</link>
		<comments>http://blogs.mathworks.com/steve/2012/03/30/image-processing-and-computer-vision-updates-in-r2012a/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 14:59:20 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=508</guid>
		<description><![CDATA[MathWorks shipped R2012a right on schedule earlier this month. (Normally, the "a" release ships in March and the "b" release ships in September.) There's a lot to look at in the new release. Today I'll summarize the enhancements in the Image Processing Toolbox, the Computer Vision System Toolbox, and the Image Acquisition Toolbox. Image Processing [...]]]></description>
			<content:encoded><![CDATA[<p>MathWorks shipped R2012a right on schedule earlier this month. (Normally, the "a" release ships in March and the "b" release ships in September.) There's a lot to look at in the new release. Today I'll summarize the enhancements in the Image Processing Toolbox, the Computer Vision System Toolbox, and the Image Acquisition Toolbox.
</p><h2>Image Processing Toolbox Enhancements
</h2><p>Version 8.0 includes these enhancements.
</p><h4>Intensity-Based Image Registration
</h4><p>The new <a href="http://www.mathworks.com/help/toolbox/images/ref/imregister.html">imregister</a> function lets you automatically align two images using intensity values, even when the images were created by two different devices (multimodal). With intensity-based registration, you do not need to specify control points.
</p><p>You use the new <a href="http://www.mathworks.com/help/toolbox/images/ref/imregconfig.html">imregconfig</a> function to create the optimizer and the metric that imregister uses to specify the desired registration parameters.
</p><h4>Two New Functions to Visually Compare Images
</h4><p>The toolbox includes two new functions for visually comparing images: <a href="http://www.mathworks.com/help/toolbox/images/ref/imshowpair.html">imshowpair</a> and <a href="http://www.mathworks.com/help/toolbox/images/ref/imfuse.html">imfuse</a>.
</p><p>imshowpair creates a composite of two images and displays them in a figure.
</p><p>imfuse creates a composite of two images and returns a third image that is a numeric matrix containing a fused version of the original images.
</p><h4>Circle Detection Using the Circular Hough Transform
</h4><p>The new <a href="http://www.mathworks.com/help/toolbox/images/ref/imfindcircles.html">imfindcircles</a> function uses the Hough transform to find circular elements in grayscale, RGB, or binary images. To view the circles that have been detected, overlaid on the original image, use the <a href="http://www.mathworks.com/help/toolbox/images/ref/viscircles.html">viscircles</a> function.
</p><h4>Performance Improvements
</h4><p>The performance of the <a href="http://www.mathworks.com/help/toolbox/images/ref/imlincomb.html">imlincomb</a> function has improved by taking advantage of multicore capabilities.
</p><h4>New and Updated Demos
</h4><p>The toolbox includes these new and updated demos.
</p><ul><li>Registering Multimodal MRI Images (ipexknee)
</li><li>Finding the Rotation and Scale of a Distorted Image (ipexrotate)
</li><li>Measuring the Radius of a Roll of Tape (ipexradius) – Updated to use the new imfindcircles function
</li></ul><h2>Computer Vision System Toolbox
</h2><p>First, I want to note that, as R2012a, the Computer Vision System Toolbox no longer requires the DSP System Toolbox or the Signal Processing Toolbox.
</p><p>Version 5.0 includes these enhancements.
</p><h4>Audio Output Sampling Mode Added to the From Multimedia File Block
</h4><p>The From Multimedia File block now includes a new parameter, which allows you to select frame- or sample-based audio output. If you do not have a DSP System Toolbox license and you set this parameter for frame-based processing, your model will return an error. The Computer Vision System Toolbox software uses only sample-based processing.
</p><h4>New Viola-Jones Cascade Object Detector
</h4><p>The <a href="http://www.mathworks.com/help/toolbox/vision/ref/vision.cascadeobjectdetectorclass.html"><span style="font-family:Consolas">vision.CascadeObjectDetector</span></a> System object uses the Viola-Jones algorithm to detect objects in an image. This detector includes Haar-like features and a cascade of classifiers. The cascade object detector is pretrained to detect faces, noses and other objects.
</p><h4>New MSER Feature Detector
</h4><p>The <a href="http://www.mathworks.com/help/toolbox/vision/ref/detectmserfeatures.html"><span style="font-family:Consolas">detectMSERFeatures</span></a> function detects maximally stable extremal regions (MSER) features in a grayscale image. You can use the <a href="http://www.mathworks.com/help/toolbox/vision/ref/mserregionsclass.html"><span style="font-family:Consolas">MSERRegions</span></a> object, returned by the function, to manipulate and plot MSER features.
</p><h4>New CAMShift Histogram-Based Tracker
</h4><p>The <a href="http://www.mathworks.com/help/toolbox/vision/ref/vision.histogrambasedtrackerclass.html"><span style="font-family:Consolas">vision.HistogramBasedTracker</span></a> System object uses the continuously adaptive mean shift (CAMShift) algorithm for tracking objects. It uses the histogram of pixel values to identify the object.
</p><h4>New Integral Image Computation and Box Filtering
</h4><p>The <a href="http://www.mathworks.com/help/toolbox/vision/ref/integralkernelclass.html"><span style="font-family:Consolas">integralKernel</span></a> object with the <a href="http://www.mathworks.com/help/toolbox/vision/ref/integralimage.html"><span style="font-family:Consolas">integralImage</span></a> and <a href="http://www.mathworks.com/help/toolbox/vision/ref/integralfilter.html"><span style="font-family:Consolas">integralFilter</span></a> functions use integral images for filtering an image with box filters. The speed of the filtering operation is independent of the filter size, making it ideally suited for fast analysis of images at different scales.
</p><h4>New Demo to Detect and Track a Face
</h4><p>This release provides a new demo, <a href="http://www.mathworks.com/help/toolbox/vision/rn/rmvd_matlablink__3.html">Face Detection and Tracking</a>. This example shows you how to develop a simple face tracking system by detecting a face, identifying its facial features, and tracking it.
</p><h4>Improved MATLAB Compiler Support
</h4><p>MATLAB Compiler™ now supports detectSURFFeatures and disparity functions.
</p><h4>Code Generation Support
</h4><p>The <a href="http://www.mathworks.com/help/toolbox/vision/ref/vision.histogrambasedtrackerclass.html"><span style="font-family:Consolas">vision.HistogramBasedTracker</span></a> and <a href="http://www.mathworks.com/help/toolbox/vision/ref/vision.cornerdetectorclass.html"><span style="font-family:Consolas">vision.CornerDetector</span></a> System objects now support code generation. See <a href="http://www.mathworks.com/help/toolbox/coder/gs/bszcx_r-3.html">About MATLAB Coder</a> for more information about code generation.
</p><h2>Image Acquisition Toolbox Enhancements
</h2><p>Version 4.2 includes these enhancements.
</p><h4>GenTL Support for GigE Vision, USB, and FireWire Devices
</h4><p>A new adaptor type, GenTL, is now available for GigE Vision, USB, and FireWire cameras.
</p><h4>Windows 64 Support on DCAM
</h4><p>The DCAM adaptor support is now extended to 64-bit Windows®.
</p><h4>VideoDevice System Object
</h4><p>The Image Acquisition Toolbox™ introduces the VideoDevice System Object, which allows single-frame image acquisition and code generation from MATLAB.
</p><p>You use the imaq.VideoDevice function to create the System Object. It supports the same adaptors and hardware that the videoinput object supports; however, it has different functions and properties associated with it. For example, the System Object uses the step function to acquire single frames.
</p><p>For more information on using the System Object, use this command in MATLAB:
</p><p style="margin-left: 36pt"><span style="font-family:Consolas">help imaq.VideoDevice
</span></p><h4>From Video Device Block Enhancements
</h4><p>Several enhancements have been added to the From Video Device block for doing image acquisition in Simulink. Options for setting color space and Bayer Sensor Alignment are now included in the block properties.
</p><h4>New Hardware Support – National Instruments
</h4><p>Support has been added for additional National Instruments® hardware.
</p><ul><li>PCI-1433
</li><li>PXI-1435
</li></ul><h4>Test Suite for Third-Party Adaptor Developers and Camera Vendors
</h4><p>As part of the Image Acquisition Toolbox Adaptor Kit, we now offer a test suite for third-party adaptor developers and camera vendors to test adaptors and hardware against the toolbox.
</p><h4>DCAM Adaptor Improvement
</h4><p>Support has been added for strobe outputs to the DCAM adaptor on Windows.
</p><h4>Linuxvideo Adaptor Improvement
</h4><p>Improved support has been added for V4L1 cameras with the linuxvideo adaptor when using the V4L1 compatibility library provided by the libv4l project.</p><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/20K91wZUNEM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/03/30/image-processing-and-computer-vision-updates-in-r2012a/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/03/30/image-processing-and-computer-vision-updates-in-r2012a/</feedburner:origLink></item>
		<item>
		<title>Image inpainting using PDE techniques</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/H7TQLWYaX4U/</link>
		<comments>http://blogs.mathworks.com/steve/2012/03/13/image-inpainting-use-pde-techniques/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 22:00:38 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=502</guid>
		<description><![CDATA[This week I want to highlight a new article on mathworks.com called "Applying Modern PDE Techniques to Digital Image Restoration," by Carola-Bibiane Sch&#246;nlieb of the University of Cambridge. Dr. Sch&#246;nlieb describes PDE-based inpainting, or image interpolation, used to reconstruct missing parts of images. Her inpainting work began on a project to restore some 14th-century Viennese [...]]]></description>
			<content:encoded><![CDATA[<div xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" class="content">
   <p>This week I want to highlight a new article on mathworks.com called <a href="http://www.mathworks.com/company/newsletters/articles/applying-modern-pde-techniques-to-digital-image-restoration.html">"Applying Modern PDE Techniques to Digital Image Restoration,"</a> by Carola-Bibiane Sch&ouml;nlieb of the University of Cambridge. Dr. Sch&ouml;nlieb describes PDE-based <i>inpainting</i>, or image interpolation, used to reconstruct missing parts of images.
   </p>
   <p>Her inpainting work began on a project to restore some 14th-century Viennese frescoes that were rediscovered in 1979:</p>
   <p><img vspace="5" hspace="5" src="http://www.mathworks.com/company/newsletters/articles/images/cambridge24893_fig7_w.jpg"> </p>
   <p>She also describes other applications, such as filling in obscured portions of roads in satellite imagery.</p>
   <p>The article describes inpainting using Fourier's heat equation as well as more sophisticated methods that can better handle
      discontinous image features such as edges. Here's a result using the heat equation. (Click <a href="http://www.mathworks.com/company/newsletters/articles/images/cambridge24893_fig1_wl.jpg">here</a> for the full size image.)
   </p>
   <p><img vspace="5" hspace="5" src="http://www.mathworks.com/company/newsletters/articles/images/cambridge24893_fig1_w.jpg"> </p>
   <p>Check out the article if you're interested. You might also want to look at <a href="http://www.mathworks.com/help/toolbox/images/ref/roifill.html"><tt>roifill</tt></a>, which implements a simple form of PDE-based inpainting.
   </p><script language="JavaScript">
<!--

    function grabCode_4ceaa7ecb64f446a9bf465eee0751935() {
        // Remember the title so we can use it in the new page
        title = document.title;

        // Break up these strings so that their presence
        // in the Javascript doesn't mess up the search for
        // the MATLAB code.
        t1='4ceaa7ecb64f446a9bf465eee0751935 ' + '##### ' + 'SOURCE BEGIN' + ' #####';
        t2='##### ' + 'SOURCE END' + ' #####' + ' 4ceaa7ecb64f446a9bf465eee0751935';
    
        b=document.getElementsByTagName('body')[0];
        i1=b.innerHTML.indexOf(t1)+t1.length;
        i2=b.innerHTML.indexOf(t2);
 
        code_string = b.innerHTML.substring(i1, i2);
        code_string = code_string.replace(/REPLACE_WITH_DASH_DASH/g,'--');

        // Use /x3C/g instead of the less-than character to avoid errors 
        // in the XML parser.
        // Use '\x26#60;' instead of '<' so that the XML parser
        // doesn't go ahead and substitute the less-than character. 
        code_string = code_string.replace(/\x3C/g, '\x26#60;');

        author = 'Steve Eddins';
        copyright = 'Copyright 2012 The MathWorks, Inc.';

        w = window.open();
        d = w.document;
        d.write('<pre>\n');
        d.write(code_string);

        // Add author and copyright lines at the bottom if specified.
        if ((author.length > 0) || (copyright.length > 0)) {
            d.writeln('');
            d.writeln('%%');
            if (author.length > 0) {
                d.writeln('% _' + author + '_');
            }
            if (copyright.length > 0) {
                d.writeln('% _' + copyright + '_');
            }
        }

        d.write('</pre>\n');
      
      d.title = title + ' (MATLAB code)';
      d.close();
      }   
      
-->
</script><p style="text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray"><br /><a href="javascript:grabCode_4ceaa7ecb64f446a9bf465eee0751935()"><span style="font-size: x-small;        font-style: italic;">Get 
            the MATLAB code 
            <noscript>(requires JavaScript)</noscript></span></a><br /><br />
      Published with MATLAB&reg; 7.14<br /></p>
</div>
<!--
4ceaa7ecb64f446a9bf465eee0751935 ##### SOURCE BEGIN #####
%%
% This week I want to highlight a new article on mathworks.com called
% <http://www.mathworks.com/company/newsletters/articles/applying-modern-pde-techniques-to-digital-image-restoration.html 
% "Applying Modern PDE Techniques to Digital Image Restoration,"> by
% Carola-Bibiane SchÃ¶nlieb of the University of Cambridge. Dr. SchÃ¶nlieb
% describes PDE-based _inpainting_, or image interpolation, used to
% reconstruct missing parts of images.
%
% Her inpainting work began on a project to restore some 14th-century
% Viennese frescoes that were rediscovered in 1979:
%
% <<http://www.mathworks.com/company/newsletters/articles/images/cambridge24893_fig7_w.jpg>>
%
% She also describes other applications, such as filling in obscured
% portions of roads in satellite imagery.
%
% The article describes inpainting using Fourier's heat equation as well as
% more sophisticated methods that can better handle discontinous image
% features such as edges. Here's a result using the heat equation. (Click
% <http://www.mathworks.com/company/newsletters/articles/images/cambridge24893_fig1_wl.jpg
% here> for the full size image.)
%
% <<http://www.mathworks.com/company/newsletters/articles/images/cambridge24893_fig1_w.jpg>>
%
% Check out the article if you're interested. You might also want to look
% at <http://www.mathworks.com/help/toolbox/images/ref/roifill.html 
% |roifill|>, which implements a simple form of PDE-based inpainting.

##### SOURCE END ##### 4ceaa7ecb64f446a9bf465eee0751935
--><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/H7TQLWYaX4U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/03/13/image-inpainting-use-pde-techniques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/03/13/image-inpainting-use-pde-techniques/</feedburner:origLink></item>
		<item>
		<title>Writing a file reader in MATLAB</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/0rFzm9nh4bk/</link>
		<comments>http://blogs.mathworks.com/steve/2012/02/28/writing-a-file-reader-in-matlab/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 12:00:07 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=487</guid>
		<description><![CDATA[I'd like to introduce guest blogger Jeff Mather. Jeff started his MathWorks career as an application support engineer. Then, very many moons ago, I hired Jeff as a software developer to work on image and scientific file formats. Jeff's now on the Image Processing Toolbox development team, but as you'll see he still thinks about [...]]]></description>
			<content:encoded><![CDATA[<div xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" class="content">
   <introduction>
      <p><i>I'd like to introduce guest blogger Jeff Mather. Jeff started his MathWorks career as an application support engineer. Then,
            very many moons ago, I hired Jeff as a software developer to work on image and scientific file formats. Jeff's now on the
            Image Processing Toolbox development team, but as you'll see he still thinks about file formats from time to time. I first
            saw Jeff's comments below <a href="http://jeffmatherphotography.com/dispatches/2012/02/writing-a-file-reader-in-matlab/">posted on his personal blog</a>, and I asked him if I could share them here. Thanks, Jeff!</i></p>
      <p>A colleague recently asked me to help him read an NRRD file in MATLAB, which supports reading a whole bunch of image and scientific
         data formats right out-of-the-box but not NRRD. This format stores 3D volumes of radiology data and (like FITS) contains a
         text header containing key-value pairs followed by a binary payload. Having written file parsers full-time for the better
         part of ten years, it didn't take too long for me to create a <a href="http://www.mathworks.com/matlabcentral/fileexchange/34653-nrrd-format-file-reader/content/nrrdread.m">.nrrd file reader for MATLAB</a>.
      </p>
      <p>I'm kind of proud of this little feature for its simplicity, and it shows a lot of the power of MATLAB. In fewer than 200
         lines of well-structured code, I was able to implement a robust file reader. Here are a few features it uses that anyone creating
         their own file reader in MATLAB might also try to take advantage of:
      </p>
      <p><b>assert</b> - Stop writing if blocks that only exist to check whether everything is okay and error if it isn't.
      </p><pre> fid = fopen(filename, 'rb');
 assert(fid &gt; 0, 'Could not open file.');</pre></introduction>
   <p style="margin-top: 10px;">And . . .</p><pre> assert(isfield(meta, 'sizes') &amp;&amp; ...
        isfield(meta, 'dimension') &amp;&amp; ...
        isfield(meta, 'encoding') &amp;&amp; ...
        isfield(meta, 'endian'), ...
        'Missing required metadata fields.')</pre><p style="margin-top: 10px;"><b>onCleanup</b> - Why worry about trying to remember to clean up resources? Let the onCleanup class take care of it for you. Construct one
      of these objects by giving it an anonymous function that closes your file handle when the object goes out of scope&#8212;whether
      from an error or at the end of the function.
   </p><pre> cleaner = onCleanup(@() fclose(fid));</pre><p style="margin-top: 10px;"><b>regexp</b> - Use MATLAB's regular expression engine to handle complicated text parsing for you.
   </p><pre> theLine = fgetl(fid);</pre><pre> % "fieldname:= value" or "fieldname: value" or "fieldname:value"
 parsedLine = regexp(theLine, ':=?\s*', 'split', 'once');</pre><p style="margin-top: 10px;"><b>Dynamic structure field indexing</b> - If you have a string that's a legal MATLAB identifier, there's no need to write complicated logic just to use it as a field
      name in a structure. Simply use the <tt>.(string)</tt> construct.
   </p><pre> field = lower(parsedLine{1});
 value = parsedLine{2};</pre><pre> field(isspace(field)) = '';  % Remove embedded spaces.
 meta(1).(field) = value;</pre><p style="margin-top: 10px;"><b>Using temporary files to decompress data</b> - The NRRD format supports storing the image data as raw bytes, human readable text, or GZIP-compressed byte streams. When
      a file contains compressed or encapsulated data and MATLAB has a file reader capable of handling that, it's easiest just to
      write the data to a temporary file and use the supported reader. Consider the <tt>readData()</tt> subfunction that recursively handles three different kinds of encoding:
   </p><pre> function data = readData(fidIn, meta, datatype)</pre><pre> switch (meta.encoding)
  case {'raw'}</pre><pre>   data = fread(fidIn, inf, [datatype '=&gt;' datatype]);</pre><pre>  case {'gzip', 'gz'}</pre><pre>   tmpBase = tempname();
   tmpFile = [tmpBase '.gz'];
   fidTmp = fopen(tmpFile, 'wb');
   assert(fidTmp &gt; 3, ...
      'Could not open temporary file for GZIP decompression')</pre><pre>   tmp = fread(fidIn, inf, 'uint8=&gt;uint8');
   fwrite(fidTmp, tmp, 'uint8');
   fclose(fidTmp);</pre><pre>   gunzip(tmpFile)</pre><pre>   fidTmp = fopen(tmpBase, 'rb');
   cleaner = onCleanup(@() fclose(fidTmp));</pre><pre>   meta.encoding = 'raw';
   data = readData(fidTmp, meta, datatype);</pre><pre>  case {'txt', 'text', 'ascii'}</pre><pre>   data = fscanf(fidIn, '%f');
   data = cast(data, datatype);</pre><pre>  otherwise
   assert(false, 'Unsupported encoding')
 end</pre><p style="margin-top: 10px;"><b>swapbytes</b> - Like many formats, NRRD supports little-endian and big-endian byte ordering. The <tt>swapbytes</tt> function makes it dead simple to change endianness, and the computer function helps you determine whether swapping is necessary.
      Here's the pattern, which uses the "endian" metadata value read from the .nrrd file:
   </p><pre> function data = adjustEndian(data, meta)</pre><pre> [~,~,endian] = computer();</pre><pre> needToSwap = (isequal(endian, 'B') &amp;&amp; ...
                isequal(lower(meta.endian), 'little')) || ...
              (isequal(endian, 'L') &amp;&amp; ...
               isequal(lower(meta.endian), 'big'));</pre><pre> if (needToSwap)
     data = swapbytes(data);
 end</pre><p style="margin-top: 10px;">Happy coding!</p>
   <p>- Jeff Mather</p><script language="JavaScript">
<!--

    function grabCode_a646faa87c724b33aacf453ff512f801() {
        // Remember the title so we can use it in the new page
        title = document.title;

        // Break up these strings so that their presence
        // in the Javascript doesn't mess up the search for
        // the MATLAB code.
        t1='a646faa87c724b33aacf453ff512f801 ' + '##### ' + 'SOURCE BEGIN' + ' #####';
        t2='##### ' + 'SOURCE END' + ' #####' + ' a646faa87c724b33aacf453ff512f801';
    
        b=document.getElementsByTagName('body')[0];
        i1=b.innerHTML.indexOf(t1)+t1.length;
        i2=b.innerHTML.indexOf(t2);
 
        code_string = b.innerHTML.substring(i1, i2);
        code_string = code_string.replace(/REPLACE_WITH_DASH_DASH/g,'--');

        // Use /x3C/g instead of the less-than character to avoid errors 
        // in the XML parser.
        // Use '\x26#60;' instead of '<' so that the XML parser
        // doesn't go ahead and substitute the less-than character. 
        code_string = code_string.replace(/\x3C/g, '\x26#60;');

        author = 'Jeff Mather';
        copyright = 'Copyright 2012 The MathWorks, Inc.';

        w = window.open();
        d = w.document;
        d.write('<pre>\n');
        d.write(code_string);

        // Add author and copyright lines at the bottom if specified.
        if ((author.length > 0) || (copyright.length > 0)) {
            d.writeln('');
            d.writeln('%%');
            if (author.length > 0) {
                d.writeln('% _' + author + '_');
            }
            if (copyright.length > 0) {
                d.writeln('% _' + copyright + '_');
            }
        }

        d.write('</pre>\n');
      
      d.title = title + ' (MATLAB code)';
      d.close();
      }   
      
-->
</script><p style="text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray"><br /><a href="javascript:grabCode_a646faa87c724b33aacf453ff512f801()"><span style="font-size: x-small;        font-style: italic;">Get 
            the MATLAB code 
            <noscript>(requires JavaScript)</noscript></span></a><br /><br />
      Published with MATLAB&reg; 7.13<br /></p>
</div>
<!--
a646faa87c724b33aacf453ff512f801 ##### SOURCE BEGIN #####
%%
% _I'd like to introduce guest blogger Jeff Mather. Jeff started his
% MathWorks career as an application support engineer. Then, very many
% moons ago, I hired Jeff as a software developer to work on image and
% scientific file formats. Jeff's now on the Image Processing Toolbox
% development team, but as you'll see he is still thinks about file
% formats from time to time. I first saw Jeff's comments below
% <http://jeffmatherphotography.com/dispatches/2012/02/writing-a-file-reader-in-matlab/
% posted on his personal blog>, and I asked him if I could share them here.
% Thanks, Jeff!_
%
% A colleague recently asked me to help him read an NRRD file in MATLAB,
% which supports reading a whole bunch of image and scientific data formats
% right out-of-the-box but not NRRD. This format stores 3D volumes of
% radiology data and (like FITS) contains a text header containing
% key-value pairs followed by a binary payload. Having written file parsers
% full-time for the better part of ten years, it didn't take too long for
% me to create a
% <http://www.mathworks.com/matlabcentral/fileexchange/34653-nrrd-format-file-reader/content/nrrdread.m
% .nrrd file reader for MATLAB>.
% 
% I'm kind of proud of this little feature for its simplicity, and it shows
% a lot of the power of MATLAB. In fewer than 200 lines of well-structured
% code, I was able to implement a robust file reader. Here are a few
% features it uses that anyone creating their own file reader in MATLAB
% might also try to take advantage of:
% 
% *assert* - Stop writing if blocks that only exist to check whether
% everything is okay and error if it isn't.
% 
%   fid = fopen(filename, 'rb'); 
%   assert(fid > 0, 'Could not open file.');
%   
%%
% And . . .
% 
%   assert(isfield(meta, 'sizes') &#038;& ...
%          isfield(meta, 'dimension') &#038;& ... 
%          isfield(meta, 'encoding') &#038;& ...
%          isfield(meta, 'endian'), ... 
%          'Missing required metadata fields.')
%    
%% 
%
% *onCleanup* - Why worry about trying to remember to clean up resources?
% Let the onCleanup class take care of it for you. Construct one of these
% objects by giving it an anonymous function that closes your file handle
% when the object goes out of scopeâ€”whether from an error or at the end of
% the function.
% 
%   cleaner = onCleanup(@() fclose(fid));
%   
%% 
% *regexp* - Use MATLAB's regular expression engine to handle complicated
% text parsing for you.
% 
%   theLine = fgetl(fid);
%   
%   % "fieldname:= value" or "fieldname: value" or "fieldname:value"
%   parsedLine = regexp(theLine, ':=?\s*', 'split', 'once');
%   
%% 
% *Dynamic structure field indexing* - If you have a string that's a legal
% MATLAB identifier, there's no need to write complicated logic just to use
% it as a field name in a structure. Simply use the |.(string)| construct.
% 
%   field = lower(parsedLine{1}); 
%   value = parsedLine{2};
%   
%   field(isspace(field)) = '';  % Remove embedded spaces. 
%   meta(1).(field) = value;
%   
%% 
% *Using temporary files to decompress data* - The NRRD format supports
% storing the image data as raw bytes, human readable text, or
% GZIP-compressed byte streams. When a file contains compressed or
% encapsulated data and MATLAB has a file reader capable of handling that,
% it's easiest just to write the data to a temporary file and use the
% supported reader. Consider the |readData()| subfunction that recursively
% handles three different kinds of encoding:
% 
%   function data = readData(fidIn, meta, datatype)
%   
%   switch (meta.encoding)
%    case {'raw'}
%   
%     data = fread(fidIn, inf, [datatype '=>' datatype]);
%   
%    case {'gzip', 'gz'}
%   
%     tmpBase = tempname(); 
%     tmpFile = [tmpBase '.gz']; 
%     fidTmp = fopen(tmpFile, 'wb'); 
%     assert(fidTmp > 3, ...
%        'Could not open temporary file for GZIP decompression')
%   
%     tmp = fread(fidIn, inf, 'uint8=>uint8'); 
%     fwrite(fidTmp, tmp, 'uint8');
%     fclose(fidTmp);
%   
%     gunzip(tmpFile)
%   
%     fidTmp = fopen(tmpBase, 'rb'); 
%     cleaner = onCleanup(@() fclose(fidTmp));
%   
%     meta.encoding = 'raw'; 
%     data = readData(fidTmp, meta, datatype);
%   
%    case {'txt', 'text', 'ascii'}
%   
%     data = fscanf(fidIn, '%f'); 
%     data = cast(data, datatype);
%   
%    otherwise
%     assert(false, 'Unsupported encoding')
%   end
%   
%% 
% *swapbytes* - Like many formats, NRRD supports little-endian and big-endian
% byte ordering. The |swapbytes| function makes it dead simple to change
% endianness, and the computer function helps you determine whether
% swapping is necessary. Here's the pattern, which uses the "endian"
% metadata value read from the .nrrd file:
% 
%   function data = adjustEndian(data, meta)
%   
%   [~,~,endian] = computer();
%   
%   needToSwap = (isequal(endian, 'B') &#038;& ...
%                  isequal(lower(meta.endian), 'little')) || ...
%                (isequal(endian, 'L') &#038;& ...
%                 isequal(lower(meta.endian), 'big'));
%   
%   if (needToSwap)
%       data = swapbytes(data);
%   end
%   
%% 
% Happy coding!
%
% - Jeff Mather
##### SOURCE END ##### a646faa87c724b33aacf453ff512f801
--><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/0rFzm9nh4bk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/02/28/writing-a-file-reader-in-matlab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/02/28/writing-a-file-reader-in-matlab/</feedburner:origLink></item>
		<item>
		<title>Digital image processing using MATLAB: writing image files</title>
		<link>http://feedproxy.google.com/~r/SteveOnImageProcessing/~3/cAzoqe36AXs/</link>
		<comments>http://blogs.mathworks.com/steve/2012/02/20/writing-image-files/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 15:47:31 +0000</pubDate>
		<dc:creator>Steve Eddins</dc:creator>
				<category><![CDATA[DIPUM tutorials]]></category>

		<guid isPermaLink="false">http://blogs.mathworks.com/steve/?p=482</guid>
		<description><![CDATA[Today's post is part of an ongoing tutorial series on digital image processing using MATLAB. I'm covering topics in roughly the order used in the book Digital Image Processing Using MATLAB. The MATLAB function imwrite writes image data to a variety of different formats including: reads image data from a variety of formats, including JPEG, [...]]]></description>
			<content:encoded><![CDATA[<div xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd" class="content">
   <introduction>
      <p><i>Today's post is part of an ongoing <a href="http://blogs.mathworks.com/steve/category/dipum-tutorials/">tutorial series on digital image processing using MATLAB</a>. I'm covering topics in roughly the order used in the book <a href="http://imageprocessingplace.com/DIPUM-2E/dipum2e_main_page.htm">Digital Image Processing Using MATLAB</a>.</i></p>
   </introduction>
   <p>The MATLAB function <tt>imwrite</tt> writes image data to a variety of different formats including: reads image data from a variety of formats, including JPEG,
      JPEG 2000, TIFF, PNG, and GIF (as well as a few older formats no longer commonly used).
   </p>
   <p>Probably most people use form where you just provide the image array and a filename.</p>
   <p>I'll read in one of the sample images in Image Processing Toolbox to experiment with.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">rgb = imread(<span style="color: #A020F0">'peppers.png'</span>);
imshow(rgb)</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/dipum_writing_images_01.png"> <pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imwrite(rgb,<span style="color: #A020F0">'mypeppers.tif'</span>)</pre><p>In the above call to <tt>imwrite</tt>, the function decides which image format to use based on the extension (.tif) in the filename.
   </p>
   <p>Sometimes, though, you might want to use a filename extension for a different purpose. In that case, you call pass a third
      argument to <tt>imwrite</tt> to let it know which image format to use.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imwrite(rgb, <span style="color: #A020F0">'test_image.study_013'</span>, <span style="color: #A020F0">'tif'</span>)</pre><p>Most image file formats support some form of compression. That means that the image takes up less space on disk than you might
      think based on a simple calculation. For example, the <tt>rgb</tt> array above takes up about 576 kilobytes in memory.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">bytes_in_memory_peppers = numel(rgb)</pre><pre style="font-style:oblique">
bytes_in_memory_peppers =

      589824

</pre><p>But it takes less space on disk when you save it to an image format that uses compression. Let's try writing to a PNG file:</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imwrite(rgb,<span style="color: #A020F0">'mypeppers.png'</span>)

info = imfinfo(<span style="color: #A020F0">'mypeppers.png'</span>);
bytes_on_disk_peppers_png = info.FileSize</pre><pre style="font-style:oblique">
bytes_on_disk_peppers_png =

      287589

</pre><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">compression_ratio = bytes_in_memory_peppers / bytes_on_disk_peppers_png</pre><pre style="font-style:oblique">
compression_ratio =

    2.0509

</pre><p>The PNG format uses <b>lossless compression</b>. This means that you can recover the original image data exactly.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">peppers2 = imread(<span style="color: #A020F0">'mypeppers.png'</span>);
isequal(rgb, peppers2)</pre><pre style="font-style:oblique">
ans =

     1

</pre><p>Lossless compression methods save a lot more space when the image has large constant areas or contains certain kinds of repetitive,
      predictable patterns. For example, this image is a screen shot of a MATLAB plot:
   </p>
   <p><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/plot_screen_shot.png"> </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">url = <span style="color: #A020F0">'http://blogs.mathworks.com/images/steve/2012/plot_screen_shot.png'</span>;
rgb_plot = imread(url);
bytes_in_memory_plot = numel(rgb_plot)</pre><pre style="font-style:oblique">
bytes_in_memory_plot =

      336000

</pre><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">info = imfinfo(url);
bytes_on_disk_plot = info.FileSize</pre><pre style="font-style:oblique">
bytes_on_disk_plot =

        3284

</pre><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">compression_ratio = bytes_in_memory_plot / bytes_on_disk_plot</pre><pre style="font-style:oblique">
compression_ratio =

  102.3143

</pre><p>That's a pretty big compression ratio!</p>
   <p>Other image file formats, such as JPEG, use <b>lossy compression</b>. (There is a lossless form of JPEG, but it is obscure and rarely used.) With lossy compression, properties of the human visual
      system are exploited to reduce the disk size even further, but at a cost --- the original pixels are not exactly recoverable.
      Let's write out the peppers image using JPEG compression.
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imwrite(rgb,<span style="color: #A020F0">'peppers.jpg'</span>);
info = imfinfo(<span style="color: #A020F0">'peppers.jpg'</span>);
bytes_on_disk_peppers_jpg = info.FileSize</pre><pre style="font-style:oblique">
bytes_on_disk_peppers_jpg =

       23509

</pre><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">compression_ratio_peppers_jpg = bytes_in_memory_peppers / <span style="color: #0000FF">...</span>
    bytes_on_disk_peppers_jpg</pre><pre style="font-style:oblique">
compression_ratio_peppers_jpg =

   25.0893

</pre><p>That's a much bigger compression ratio than we got with the PNG format above. The cost is in reduced image quality. JPEG does
      a pretty good job of reducing space without adversely affecting image quality:
   </p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imshow(<span style="color: #A020F0">'peppers.jpg'</span>)</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/dipum_writing_images_02.png"> <p>But it isn't perfect, as you can see by zooming in.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">subplot(1,2,1)
imshow(<span style="color: #A020F0">'peppers.png'</span>)
limits = [232 276 215 248];
axis(limits)
title(<span style="color: #A020F0">'Original'</span>)

subplot(1,2,2)
imshow(<span style="color: #A020F0">'peppers.jpg'</span>)
axis(limits)
title(<span style="color: #A020F0">'JPEG compressed'</span>)</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/dipum_writing_images_03.png"> <p>You can see the compression artifacts around the stem.</p>
   <p>Compression artifacts tend to be more visible on images such as the plot screen shot above.</p><pre style="background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)">imwrite(rgb_plot,<span style="color: #A020F0">'plot_screen_shot.jpg'</span>)
rgb_plot_compressed = imread(<span style="color: #A020F0">'plot_screen_shot.jpg'</span>);

subplot(2,2,1)
imshow(rgb_plot)
title(<span style="color: #A020F0">'Original image'</span>)
limits = [80 105 210 230];
axis(limits);

subplot(2,2,2)
imshow(rgb_plot_compressed)
title(<span style="color: #A020F0">'JPEG compressed image'</span>)
axis(limits);

subplot(2,2,3)
imshow(rgb_plot)
limits = [345 380 240 265];
axis(limits);

subplot(2,2,4)
imshow(rgb_plot_compressed)
axis(limits);</pre><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2012/dipum_writing_images_04.png"> <p>That's why I usually use PNG for screen shots of many MATLAB graphics. For more complex images, on the other hand, I usually
      use JPEG.
   </p>
   <p>For more information, see Section 2.4 of <a href="http://imageprocessingplace.com/DIPUM-2E/dipum2e_main_page.htm"> <i>Digital Image Processing Using MATLAB</i></a>.
   </p>
   <p><img vspace="5" hspace="5" src="http://blogs.mathworks.com/images/steve/2011/dipum-cover.png"> </p>
   <p>See also the reference pages for <a href="http://www.mathworks.com/help/techdoc/ref/imwrite.html"><tt>imwrite</tt></a>, as well as the section <a href="http://www.mathworks.com/help/toolbox/images/f13-19056.html">Reading and Writing Image Data</a> in the Image Processing Toolbox User's Guide.
   </p><script language="JavaScript">
<!--

    function grabCode_3fd34730ffbe4516b3b41e7a1be0e7dc() {
        // Remember the title so we can use it in the new page
        title = document.title;

        // Break up these strings so that their presence
        // in the Javascript doesn't mess up the search for
        // the MATLAB code.
        t1='3fd34730ffbe4516b3b41e7a1be0e7dc ' + '##### ' + 'SOURCE BEGIN' + ' #####';
        t2='##### ' + 'SOURCE END' + ' #####' + ' 3fd34730ffbe4516b3b41e7a1be0e7dc';
    
        b=document.getElementsByTagName('body')[0];
        i1=b.innerHTML.indexOf(t1)+t1.length;
        i2=b.innerHTML.indexOf(t2);
 
        code_string = b.innerHTML.substring(i1, i2);
        code_string = code_string.replace(/REPLACE_WITH_DASH_DASH/g,'--');

        // Use /x3C/g instead of the less-than character to avoid errors 
        // in the XML parser.
        // Use '\x26#60;' instead of '<' so that the XML parser
        // doesn't go ahead and substitute the less-than character. 
        code_string = code_string.replace(/\x3C/g, '\x26#60;');

        author = 'Steve Eddins';
        copyright = 'Copyright 2012 The MathWorks, Inc.';

        w = window.open();
        d = w.document;
        d.write('<pre>\n');
        d.write(code_string);

        // Add author and copyright lines at the bottom if specified.
        if ((author.length > 0) || (copyright.length > 0)) {
            d.writeln('');
            d.writeln('%%');
            if (author.length > 0) {
                d.writeln('% _' + author + '_');
            }
            if (copyright.length > 0) {
                d.writeln('% _' + copyright + '_');
            }
        }

        d.write('</pre>\n');
      
      d.title = title + ' (MATLAB code)';
      d.close();
      }   
      
-->
</script><p style="text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray"><br /><a href="javascript:grabCode_3fd34730ffbe4516b3b41e7a1be0e7dc()"><span style="font-size: x-small;        font-style: italic;">Get 
            the MATLAB code 
            <noscript>(requires JavaScript)</noscript></span></a><br /><br />
      Published with MATLAB&reg; 7.13<br /></p>
</div>
<!--
3fd34730ffbe4516b3b41e7a1be0e7dc ##### SOURCE BEGIN #####
%%
% _Today's post is part of an ongoing
% <http://blogs.mathworks.com/steve/category/dipum-tutorials/ tutorial
% series on digital image processing using MATLAB>. I'm covering topics in
% roughly the order used in the book
% <http://imageprocessingplace.com/DIPUM-2E/dipum2e_main_page.htm Digital
% Image Processing Using MATLAB>._
%
%%
% The MATLAB function |imwrite| writes image data to a variety of different 
% formats including: reads image data from a variety of formats,
% including JPEG, JPEG 2000, TIFF, PNG, and GIF (as well as a few older
% formats no longer commonly used).
%
% Probably most people use form where you just provide the image array and
% a filename.
%
% I'll read in one of the sample images in Image Processing Toolbox to
% experiment with.

rgb = imread('peppers.png');
imshow(rgb)

%%
imwrite(rgb,'mypeppers.tif')

%%
% In the above call to |imwrite|, the function decides which image format
% to use based on the extension (.tif) in the filename.
%
% Sometimes, though, you might want to use a filename extension for a
% different purpose. In that case, you call pass a third argument to
% |imwrite| to let it know which image format to use.

imwrite(rgb, 'test_image.study_013', 'tif')

%%
% Most image file formats support some form of compression. That means that
% the image takes up less space on disk than you might think based on a
% simple calculation. For example, the |rgb| array above takes up
% about 576 kilobytes in memory.

bytes_in_memory_peppers = numel(rgb)

%%
% But it takes less space on disk when you save it to an image format that
% uses compression. Let's try writing to a PNG file:

imwrite(rgb,'mypeppers.png')

info = imfinfo('mypeppers.png');
bytes_on_disk_peppers_png = info.FileSize

%%
compression_ratio = bytes_in_memory_peppers / bytes_on_disk_peppers_png

%%
% The PNG format uses *lossless compression*. This means that you can
% recover the original image data exactly.

peppers2 = imread('mypeppers.png');
isequal(rgb, peppers2)

%%
% Lossless compression methods save a lot more space when the image has
% large constant areas or contains certain kinds of repetitive, predictable
% patterns. For example, this image is a screen shot of a MATLAB plot:
%
% <<http://blogs.mathworks.com/images/steve/2012/plot_screen_shot.png>>

url = 'http://blogs.mathworks.com/images/steve/2012/plot_screen_shot.png';
rgb_plot = imread(url);
bytes_in_memory_plot = numel(rgb_plot)

%%
info = imfinfo(url);
bytes_on_disk_plot = info.FileSize

%%
compression_ratio = bytes_in_memory_plot / bytes_on_disk_plot

%%
% That's a pretty big compression ratio!
%
% Other image file formats, such as JPEG, use *lossy compression*. (There
% is a lossless form of JPEG, but it is obscure and rarely used.) With
% lossy compression, properties of the human visual system are exploited to
% reduce the disk size even further, but at a cost REPLACE_WITH_DASH_DASH- the original pixels
% are not exactly recoverable. Let's write out the peppers image using JPEG
% compression.

imwrite(rgb,'peppers.jpg');
info = imfinfo('peppers.jpg');
bytes_on_disk_peppers_jpg = info.FileSize

%%
compression_ratio_peppers_jpg = bytes_in_memory_peppers / ...
    bytes_on_disk_peppers_jpg

%%
% That's a much bigger compression ratio than we got with the PNG format
% above. The cost is in reduced image quality. JPEG does a pretty good job
% of reducing space without adversely affecting image quality:

imshow('peppers.jpg')

%%
% But it isn't perfect, as you can see by zooming in.
subplot(1,2,1)
imshow('peppers.png')
limits = [232 276 215 248];
axis(limits)
title('Original')

subplot(1,2,2)
imshow('peppers.jpg')
axis(limits)
title('JPEG compressed')

%%
% You can see the compression artifacts around the stem.
%
% Compression artifacts tend to be more visible on images such as the plot
% screen shot above.

imwrite(rgb_plot,'plot_screen_shot.jpg')
rgb_plot_compressed = imread('plot_screen_shot.jpg');

subplot(2,2,1)
imshow(rgb_plot)
title('Original image')
limits = [80 105 210 230];
axis(limits);

subplot(2,2,2)
imshow(rgb_plot_compressed)
title('JPEG compressed image')
axis(limits);

subplot(2,2,3)
imshow(rgb_plot)
limits = [345 380 240 265];
axis(limits);

subplot(2,2,4)
imshow(rgb_plot_compressed)
axis(limits);

%%
% That's why I usually use PNG for screen shots of many MATLAB graphics.
% For more complex images, on the other hand, I usually use JPEG.

%% 
% For more information, see Section 2.4 of
% <http://imageprocessingplace.com/DIPUM-2E/dipum2e_main_page.htm
%  _Digital Image Processing Using MATLAB_>. 
%
% <<http://blogs.mathworks.com/images/steve/2011/dipum-cover.png>>
%
% See also the reference pages for
% <http://www.mathworks.com/help/techdoc/ref/imwrite.html |imwrite|>, as
% well as the section
% <http://www.mathworks.com/help/toolbox/images/f13-19056.html Reading and
% Writing Image Data> in the Image Processing Toolbox User's Guide.
%
% 
##### SOURCE END ##### 3fd34730ffbe4516b3b41e7a1be0e7dc
--><img src="http://feeds.feedburner.com/~r/SteveOnImageProcessing/~4/cAzoqe36AXs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blogs.mathworks.com/steve/2012/02/20/writing-image-files/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blogs.mathworks.com/steve/2012/02/20/writing-image-files/</feedburner:origLink></item>
	</channel>
</rss>

