Python電腦視覺:第一章 影像處理基礎,python影像處理

來源:互聯網
上載者:User

Python電腦視覺:第一章 影像處理基礎,python影像處理
<div class="article_content tracking-ad" id="article_content" data-mod="popu_307" data-dsm="post"><h1 style="font-size:20px; margin:0px; color:rgb(204,204,204); font-weight:normal; padding:15px 20px; font-family:'Helvetica Neue','Luxi Sans','DejaVu Sans',Tahoma,'Hiragino Sans GB','Microsoft Yahei',STHeiti; background:rgb(68,68,68)"><a name="t0" target="_blank"></a>
第一章 影像處理基礎</h1>
<ol class="toc" style="margin:20px; padding:0px; list-style-type:none; list-style-position:outside; color:rgb(34,34,34); font-family:'Helvetica Neue','Luxi Sans','DejaVu Sans',Tahoma,'Hiragino Sans GB','Microsoft Yahei',STHeiti; font-size:14px; line-height:22.3999996185303px">
<li><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-1" target="">1.1 PIL-Python映像庫</a>
<ol style="margin:0px; padding:0px; list-style-type:none">
<li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-1-1" target="">1.1.1 對圖片進行格式轉換</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-1-2" target="">1.1.2 建立縮圖</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-1-3" target="">1.1.3 拷貝並貼上區</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-1-4" target="">1.1.4 調整尺寸及旋轉</a></li></ol>
</li><li><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-2" target="">1.2 Matplotlib庫</a>
<ol style="margin:0px; padding:0px; list-style-type:none">
<li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-2-1" target="">1.2.1 畫圖、描點和線</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-2-2" target="">1.2.2 映像輪廓和長條圖</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-2-4" target="">1.2.4 互動注釋</a></li></ol>
</li><li><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3" target="">1.3 NumPy庫</a>
<ol style="margin:0px; padding:0px; list-style-type:none">
<li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3-1" target="">1.3.1 映像數組表示</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3-2" target="">1.3.2 灰階變換</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3-3" target="">1.3-3 調整映像尺寸</a></li></ol>
</li><li><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3-3" target="">1.3.3 長條圖均衡化</a>
<ol style="margin:0px; padding:0px; list-style-type:none">
<li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3-4" target="">1.3.4 映像平均</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3-5" target="">1.3.5 對映像進行主成分分析</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-3-6" target="">1.3.6 Pickle模組</a></li></ol>
</li><li><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-4" target="">1.4 SciPy模組</a>
<ol style="margin:0px; padding:0px; list-style-type:none">
<li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-4-1" target="">1.4.1 映像模糊</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-4-2" target="">1.4.2 映像差分</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-4-3" target="">1.4.3 形態學-物體計數</a></li><li style="padding-left:20px"><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-4-4" target="">1.4.4 有用的SciPy模組</a></li></ol>
</li><li><a style="color:rgb(221,17,68)" href="http://yongyuan.name/pcvwithpython/chapter1.html#sec-1-5" target="">1.5 更進階的例子:映像降噪</a></li></ol>
<div class="main" style="margin:0px 20px; color:rgb(34,34,34); font-family:'Helvetica Neue','Luxi Sans','DejaVu Sans',Tahoma,'Hiragino Sans GB','Microsoft Yahei',STHeiti; font-size:14px; line-height:22.3999996185303px">
<h2 id="sec-1-1" style="font-size:20px; margin:20px 0px"><a name="t1" target="_blank"></a>1.1 PIL-Python映像庫</h2>
<p style="margin-top:1em; margin-bottom:1em">PIL (Python Imaging Library)映像庫提供了很多常用的影像處理及很多有用的映像基本操作。PIL庫<a style="color:rgb(221,17,68)" href="http://www.pythonware.com/products/pil/" target="_blank">[www.pythonware.com/products/pil/]</a>。下面示範原書P001-Fig1-1讀入一幅圖片的例子:</p>
<div class="highlight" style="border:1px solid rgb(153,153,153); width:760px; margin:20px 0px; background:rgb(238,238,238)">
<pre style="margin-top:10px; margin-bottom:10px; margin-left:10px; white-space:pre-wrap; word-wrap:break-word; line-height:1.5"><code class="language-python" style="font-family:Consolas,'Liberation Mono',Courier,monospace; font-size:1em; border:none; background:rgb(238,238,238)"><span class="c" style="color:rgb(64,128,128); font-style:italic"># -*- coding: utf-8 -*-</span>
<span class="kn" style="color:rgb(0,128,0); font-weight:bold">from</span> <span class="nn" style="color:rgb(0,0,255); font-weight:bold">PIL</span> <span class="kn" style="color:rgb(0,128,0); font-weight:bold">import</span> <span class="n">Image</span>
<span class="kn" style="color:rgb(0,128,0); font-weight:bold">from</span> <span class="nn" style="color:rgb(0,0,255); font-weight:bold">pylab</span> <span class="kn" style="color:rgb(0,128,0); font-weight:bold">import</span> <span class="o" style="color:rgb(102,102,102)">*</span><span class="c" style="color:rgb(64,128,128); font-style:italic"># 添加中文字型支援</span>
<span class="kn" style="color:rgb(0,128,0); font-weight:bold">from</span> <span class="nn" style="color:rgb(0,0,255); font-weight:bold">matplotlib.font_manager</span> <span class="kn" style="color:rgb(0,128,0); font-weight:bold">import</span> <span class="n">FontProperties</span>
<span class="n">font</span> <span class="o" style="color:rgb(102,102,102)">=</span> <span class="n">FontProperties</span><span class="p">(</span><span class="n">fname</span><span class="o" style="color:rgb(102,102,102)">=</span><span class="s" style="color:rgb(186,33,33)">r"c:\windows\fonts\SimSun.ttc"</span><span class="p">,</span> <span class="n">size</span><span class="o" style="color:rgb(102,102,102)">=</span><span class="mi" style="color:rgb(102,102,102)">14</span><span class="p">)</span>
<span class="n">figure</span><span class="p">()</span><span class="n">pil_im</span> <span class="o" style="color:rgb(102,102,102)">=</span> <span class="n">Image</span><span class="o" style="color:rgb(102,102,102)">.</span><span class="n">open</span><span class="p">(</span><span class="s" style="color:rgb(186,33,33)">'../data/empire.jpg'</span><span class="p">)</span>
<span class="n">gray</span><span class="p">()</span>
<span class="n">subplot</span><span class="p">(</span><span class="mi" style="color:rgb(102,102,102)">121</span><span class="p">)</span>
<span class="n">title</span><span class="p">(</span><span class="s" style="color:rgb(186,33,33)">u'原圖'</span><span class="p">,</span><span class="n">fontproperties</span><span class="o" style="color:rgb(102,102,102)">=</span><span class="n">font</span><span class="p">)</span>
<span class="n">axis</span><span class="p">(</span><span class="s" style="color:rgb(186,33,33)">'off'</span><span class="p">)</span>
<span class="n">imshow</span><span class="p">(</span><span class="n">pil_im</span><span class="p">)</span><span class="n">pil_im</span> <span class="o" style="color:rgb(102,102,102)">=</span> <span class="n">Image</span><span class="o" style="color:rgb(102,102,102)">.</span><span class="n">open</span><span class="p">(</span><span class="s" style="color:rgb(186,33,33)">'../data/empire.jpg'</span><span class="p">)</span><span class="o" style="color:rgb(102,102,102)">.</span><span class="n">convert</span><span class="p">(</span><span class="s" style="color:rgb(186,33,33)">'L'</span><span class="p">)</span>
<span class="n">subplot</span><span class="p">(</span><span class="mi" style="color:rgb(102,102,102)">122</span><span class="p">)</span>
<span class="n">title</span><span class="p">(</span><span class="s" style="color:rgb(186,33,33)">u'灰階圖'</span><span class="p">,</span><span class="n">fontproperties</span><span class="o" style="color:rgb(102,102,102)">=</span><span class="n">font</span><span class="p">)</span>
<span class="n">axis</span><span class="p">(</span><span class="s" style="color:rgb(186,33,33)">'off'</span><span class="p">)</span>
<span class="n">imshow</span><span class="p">(</span><span class="n">pil_im</span><span class="p">)</span><span class="n">show</span><span class="p">()</span>
</code></pre>
</div>
<p style="margin-top:1em; margin-bottom:1em">運行上面的代碼,可以得出原書P002-Fig1-1中的前兩幅圖片,如下:<img style="border:0px; vertical-align:middle; display:block; margin:0px auto" alt="P002-Fig1-1" src="http://yongyuan.name/pcvwithpython/assets/images/figures/ch01/P002-Fig1-1.png">

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.