光的世界︰派生科學計算六‧下

廬山東林寺三笑庭名聯‧清‧唐蝸寄

橋跨虎溪,三教三源流,三人三笑語;
蓮開僧舍,一花一世界,一葉一如來。

曾經三人三笑語,聞得虎嘯,恍然大悟。何故三詠三抒懷︰

詠二疏‧陶淵明

大象轉四時,功成者自去。
借問衰周來,幾人得其趣?
遊目漢廷中,二疏復此舉。
高嘯返舊居,長揖儲君傅。
餞送傾皇朝,華軒盈道路。
離別情所悲,余榮何足顧!
事勝感行人,賢哉豈常譽?
厭厭閭裏歡,所營非近務。
促席延故老,揮觴道平素。
問金終寄心,清言曉未悟。
放意樂餘年,遑恤身後慮。
誰雲其人亡,久而道彌著。

詠三良‧陶淵明

彈冠乘通津,但懼時我遺;
服勤盡歲月,常恐功愈微。
忠情謬獲露,遂為君所私。
出則陪文輿,入必侍丹帷;
箴規向已從,計議初無虧。
一朝長逝後,願言同此歸。
厚恩因難忘,君命安可違?
臨穴罔惟疑,投義誌攸希。
荊棘籠高墳,黃鳥聲正悲。
良人不可贖,泫然沾我衣。

詠荊軻‧陶淵明

燕丹善養士,誌在報強嬴。
招集百夫良,歲暮得荊卿。
君子死知己,提劍出燕京;
素驥鳴廣陌,慷慨送我行。
雄發指危冠,猛氣衝長纓。
飲餞易水上,四座列群英。
漸離擊悲筑,宋意唱高聲。
蕭蕭哀風逝,淡淡寒波生。
商音更流涕,羽奏壯士驚。
心知去不歸,且有後世名。
登車何時顧,飛蓋入秦庭。
淩厲越萬裏,逶迤過千城。
圖窮事自至,豪主正怔營。
惜哉劍術疏,奇功遂不成!
其人雖已沒,千載有餘情。

晉時淵明,晉後名潛,已棄五斗米,不知姓字忘其何人,五柳先生『伍』『柳』吟誦耶??果真二三子其志一也!!雖說是移時隔空得失不同,其人其心何其相似乎??!!先生『菀柳』之『情』仍一樣吧!!??

誰雲其人亡,久而道彌著。

良人不可贖,泫然沾我衣。

其人雖已沒,千載有餘情。

大暑已過,入秋之際,講此『春耕夏耘』之『心法』勒。古今中外『學問』縱有千百種,談起功夫『心法』則一矣。往往其『志一』其『人同』也!!只是『一花』『一葉』真誠對待歟??

如果天地公平,天理能隨觀者變乎??故知物理學之所以著意於

仿射變換性質了!!

一仿射變換保留了:

  1. 點之間的共線性,例如通過同一線之點 (即稱為共線點)在變換後仍呈共線。
  2. 向量沿著一線的比例,例如對相異共線三點 p_{1},\,p_{2},\,p_{3}, \overrightarrow {p_{1}p_{2}}\overrightarrow {p_{2}p_{3}}的比例同於 \overrightarrow {f(p_{1})f(p_{2})}  \overrightarrow {f(p_{2})f(p_{3})}
  3. 帶不同質量的點之質心

一仿射變換為可逆的若且唯若A為可逆的。在矩陣表示中,其反元素為

{\begin{bmatrix}A^{{-1}}&-A^{{-1}}{\vec {b}}\ \\0,\ldots ,0&1\end{bmatrix}}

可逆仿射變換組成仿射群,其中包含具n階的一般線性群為子群,且自身亦為一n+1階的一般線性群之子群。 當A為常數乘以正交矩陣時,此子集合構成一子群,稱之為相似變換舉例而言,假如仿射變換於一平面上且假如A之行列式為1或-1,那麼該變換即為等面積變換。此類變換組成一稱為等仿射群的子集。一同時為等面積變換與相似變換之變換,即為一平面上保持歐幾里德距離不變之保距映射 這些群都有一保留了原定向的子群,也就是其對應之A的行列式大於零。在最後一例中,即為三維中剛體運動之群(旋轉加平移)。 假如有一不動點,我們可以將其當成原點,則仿射變換被縮還到一線性變換。這使得變換更易於分類與理解。舉例而言,將一變換敘述為特定軸的旋轉,相較於將其形容為平移與旋轉的結合,更能提供變換行為清楚的解釋。只是,這取決於應用與內容。

 

若知『平移』與『旋轉』為『保距映射』,餘理可知矣︰

※矩陣乘法不具『交換性』,正是『平移』後『旋轉』往往不等於『旋轉』再『平移』也。

pi@raspberrypi:~ ipython3 Python 3.4.2 (default, Oct 19 2014, 13:31:11)  Type "copyright", "credits" or "license" for more information.  IPython 2.3.0 -- An enhanced Interactive Python. ?         -> Introduction and overview of IPython's features. %quickref -> Quick reference. help      -> Python's own help system. object?   -> Details about 'object', use 'object??' for extra details.  In [1]: from sympy import *  In [2]: init_printing()  In [3]: xα, yα, xβ, yβ, Tx, Ty, θ = symbols('xα, yα, xβ, yβ, Tx, Ty, θ')  In [4]: T = Matrix([[1, 0, Tx], [0, 1, Ty], [0, 0, 1]])  In [5]: T Out[5]:  ⎡1  0  Tx⎤ ⎢        ⎥ ⎢0  1  Ty⎥ ⎢        ⎥ ⎣0  0  1 ⎦  In [6]: T.det() Out[6]: 1  In [7]: R = Matrix([[cos(θ), sin(θ), 0], [-sin(θ), cos(θ), 0], [0, 0, 1]])  In [8]: R Out[8]:  ⎡cos(θ)   sin(θ)  0⎤ ⎢                  ⎥ ⎢-sin(θ)  cos(θ)  0⎥ ⎢                  ⎥ ⎣   0       0     1⎦  In [9]: R.det() Out[9]:     2         2    sin (θ) + cos (θ)  In [10]: R.det().simplify() Out[10]: 1  In [11]: α平移 = T * Matrix([xα, yα, 1])  In [12]: α平移 Out[12]:  ⎡Tx + xα⎤ ⎢       ⎥ ⎢Ty + yα⎥ ⎢       ⎥ ⎣   1   ⎦  In [13]: β平移 = T * Matrix([xβ, yβ, 1])  In [14]:  β平移 Out[14]:  ⎡Tx + xβ⎤ ⎢       ⎥ ⎢Ty + yβ⎥ ⎢       ⎥ ⎣   1   ⎦  In [15]: αβ平移距離 = (α平移[0] - β平移[0])** 2 + (α平移[1] - β平移[1])** 2  In [16]: αβ平移距離 Out[16]:           2            2 (xα - xβ)  + (yα - yβ)   In [17]: α旋轉 = R * Matrix([xα, yα, 1])  In [18]: α旋轉 Out[18]:  ⎡xα⋅cos(θ) + yα⋅sin(θ) ⎤ ⎢                      ⎥ ⎢-xα⋅sin(θ) + yα⋅cos(θ)⎥ ⎢                      ⎥ ⎣          1           ⎦  In [19]: β旋轉 = R * Matrix([xβ, yβ, 1])  In [20]: β旋轉 Out[20]:  ⎡xβ⋅cos(θ) + yβ⋅sin(θ) ⎤ ⎢                      ⎥ ⎢-xβ⋅sin(θ) + yβ⋅cos(θ)⎥ ⎢                      ⎥ ⎣          1           ⎦  In [21]: αβ旋轉距離 = (α旋轉[0] - β旋轉[0])** 2 + (α旋轉[1] - β旋轉[1])** 2  In [22]: αβ旋轉距離 Out[22]:                                                  2                              (-xα⋅sin(θ) + xβ⋅sin(θ) + yα⋅cos(θ) - yβ⋅cos(θ))  + (xα⋅cos(θ) - xβ⋅cos(θ) + y                       2 α⋅sin(θ) - yβ⋅sin(θ))   In [23]: αβ旋轉距離.expand().simplify() Out[23]:    2               2     2               2 xα  - 2⋅xα⋅xβ + xβ  + yα  - 2⋅yα⋅yβ + yβ   In [24]: R*T Out[24]:  ⎡cos(θ)   sin(θ)  Tx⋅cos(θ) + Ty⋅sin(θ) ⎤ ⎢                                       ⎥ ⎢-sin(θ)  cos(θ)  -Tx⋅sin(θ) + Ty⋅cos(θ)⎥ ⎢                                       ⎥ ⎣   0       0               1           ⎦  In [25]: T*R Out[25]:  ⎡cos(θ)   sin(θ)  Tx⎤ ⎢                   ⎥ ⎢-sin(θ)  cos(θ)  Ty⎥ ⎢                   ⎥ ⎣   0       0     1 ⎦  In [26]:  </pre>    <span style="color: #003300;">光有『心法』,缺少『運用』之實務修煉,功夫怕也不踏實。在此祇以『相似幾何』之理</span> <h1 id="firstHeading" class="firstHeading" lang="en"><span style="color: #003300;"><a style="color: #003300;" href="https://en.wikipedia.org/wiki/Similarity_%28geometry%29">Similarity (geometry)</a></span></h1> <span style="color: #808080;">Two geometrical objects are called <b>similar</b> if they both have the same <a style="color: #808080;" title="Shape" href="https://en.wikipedia.org/wiki/Shape">shape</a>, or one has the same shape as the mirror image of the other. More precisely, one can be obtained from the other by uniformly <a style="color: #808080;" title="Scaling (geometry)" href="https://en.wikipedia.org/wiki/Scaling_%28geometry%29">scaling</a> (enlarging or shrinking), possibly with additional <a style="color: #808080;" title="Translation (geometry)" href="https://en.wikipedia.org/wiki/Translation_%28geometry%29">translation</a>, <a style="color: #808080;" title="Rotation (mathematics)" href="https://en.wikipedia.org/wiki/Rotation_%28mathematics%29">rotation</a> and <a style="color: #808080;" title="Reflection (mathematics)" href="https://en.wikipedia.org/wiki/Reflection_%28mathematics%29">reflection</a>. This means that either object can be rescaled, repositioned, and reflected, so as to coincide precisely with the other object. If two objects are similar, each is <a style="color: #808080;" title="Congruence (geometry)" href="https://en.wikipedia.org/wiki/Congruence_%28geometry%29">congruent</a> to the result of a particular uniform scaling of the other. A modern and novel perspective of similarity is to consider geometrical objects similar if one appears congruent to the other when zoomed in or out at some level.</span>  <span style="color: #808080;">For example, all <a style="color: #808080;" title="Circle" href="https://en.wikipedia.org/wiki/Circle">circles</a> are similar to each other, all <a class="mw-redirect" style="color: #808080;" title="Square (geometry)" href="https://en.wikipedia.org/wiki/Square_%28geometry%29">squares</a> are similar to each other, and all <a class="mw-redirect" style="color: #808080;" title="Equilateral triangles" href="https://en.wikipedia.org/wiki/Equilateral_triangles">equilateral triangles</a> are similar to each other. On the other hand, <a style="color: #808080;" title="Ellipse" href="https://en.wikipedia.org/wiki/Ellipse">ellipses</a> are <i>not</i> all similar to each other, <a class="mw-redirect" style="color: #808080;" title="Rectangles" href="https://en.wikipedia.org/wiki/Rectangles">rectangles</a> are not all similar to each other, and <a style="color: #808080;" title="Isosceles triangle" href="https://en.wikipedia.org/wiki/Isosceles_triangle">isosceles triangles</a> are not all similar to each other.</span>  <span style="color: #808080;">If two angles of a triangle have measures equal to the measures of two angles of another triangle, then the triangles are similar. Corresponding sides of similar polygons are in proportion, and corresponding angles of similar polygons have the same measure.</span>  <span style="color: #808080;">This article assumes that a scaling can have a scale factor of 1, so that all congruent shapes are also similar, but some school text books specifically exclude congruent triangles from their definition of similar triangles by insisting that the sizes must be different if the triangles are to qualify as similar.</span>  <img class="alignnone size-full wp-image-56737" src="http://www.freesandal.org/wp-content/uploads/300px-Similar-geometric-shapes.svg.png" alt="300px-Similar-geometric-shapes.svg" width="300" height="208" />  <span style="color: #808080;">Figures shown in the same color are similar</span>     <span style="color: #003300;">介紹一下『skimage』程式庫</span>  <img class="alignnone size-full wp-image-56740" src="http://www.freesandal.org/wp-content/uploads/skimagelogo.png" alt="skimagelogo" width="568" height="140" /> <div class="well hero row-fluid summary-box container"> <h2><span style="color: #808080;"><a style="color: #808080;" href="http://scikit-image.org/">Image processing in Python</a></span></h2> <span style="color: #808080;"><em>scikit-image</em> is a collection of algorithms for image processing. It is available <a class="reference external" style="color: #808080;" href="http://scikit-image.org/docs/dev/license.html">free of charge and free of restriction</a>. We pride ourselves on high-quality, peer-reviewed code, written by an active <a class="reference external" style="color: #808080;" href="https://www.ohloh.net/p/scikit-image/contributors">community of volunteers</a>.</span>  <span style="color: #808080;"><a class="btn btn-warning clearfix" style="color: #808080;" href="http://scikit-image.org/download"> <i class="icon-download icon-white"></i>Download</a></span>  </div> <div id="getting-started" class="section"> <h1><span style="color: #808080;">Getting Started</span></h1> <span style="color: #808080;">Filtering an image with <code class="docutils literal"><span class="pre">scikit-image</span></code> is easy! For more examples, please visit our <a class="reference external" style="color: #808080;" href="http://scikit-image.org/docs/dev/auto_examples">gallery</a>.</span> <pre class="lang:python decode:true ">from skimage import data, io, filters  image = data.coins() # or any NumPy array! edges = filters.sobel(image) io.imshow(edges) io.show() </pre> <div class="row-fluid container"> <div class="well span6 container"><img class="coins-sample span6" src="http://scikit-image.org/_images/coins-small.png" alt="_images/coins-small.png" /> <img class="coins-sample span6" src="http://scikit-image.org/_images/sobel-coins-small.png" alt="_images/sobel-coins-small.png" /></div> </div> <div class="well hero row-fluid summary-box citation container">  <span style="color: #808080;"><b>If you find this project useful, please cite:</b> [<a style="color: #808080;" href="http://scikit-image.org/_static/skimage.bib">BiBTeX</a>]</span>  <span style="color: #808080;">Stéfan van der Walt, Johannes L. Schönberger, Juan Nunez-Iglesias, François Boulogne, Joshua D. Warner, Neil Yager, Emmanuelle Gouillart, Tony Yu and the scikit-image contributors. <b>scikit-image: Image processing in Python</b>. PeerJ 2:e453 (2014) <a style="color: #808080;" href="http://dx.doi.org/10.7717/peerj.453"> http://dx.doi.org/10.7717/peerj.453 </a></span>  </div> </div>    <span style="color: #003300;">在二維圖像上的應用,且當個門徑吧。</span>  <span style="color: #808080;">【參考資料】</span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://scikit-image.org/docs/dev/auto_examples/applications/plot_geometric.html">Using geometric transformations</a></span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://scikit-image.org/docs/dev/api/skimage.transform.html">Module: transform</a></span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4081273/">scikit-image: image processing in Python</a></span>  <span style="color: #808080;">‧ <a style="color: #808080;" href="http://www.scipy-lectures.org/packages/scikit-image/">Scikit-image: image processing</a></span>     <span style="color: #003300;">讀者切莫因五行程式範例文字儼然『校對有誤』就止步!</span> <pre class="lang:python decode:true">pi@raspberrypi:~ ipython3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from skimage import data, io, filter

In [2]: image = data.coins()

In [3]: edges = filter.sobel(image)

In [4]: io.imshow(edges)

In [5]: io.show()

In [6]: io.imshow(image)

In [7]: io.show()

In [8]: 文本 = data.text()

 

skimage_filter_1

 

skimage_filter_2

 

須知積極更新發展快速之程式庫,文件往往可能『前差後異』也?

In [9]: from skimage import transform as tf

In [10]: 旋轉文本 = tf.rotate(文本, 45, resize=True)

In [11]: io.imshow(文本)

In [12]: io.show()

In [13]: io.imshow(旋轉文本)

In [14]: io.show()

In [15]: import math

In [16]: 相似變換 = tf.SimilarityTransform( rotation=math.pi / 4, translation=( 文本.sape[0] / 2, -100))

In [17]: 相似變換文本 = tf.warp(文本, 相似變換)

In [18]: io.imshow(相似變換文本)

In [19]: io.show()

In [20]: 

 

skimage_文本

 

skimage_文本旋轉

 

skimage_文本相似變換

 

難到山不會轉,竟然路也不能轉耶??!!