⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chp2.htm

📁 数字图象处理入门,非常好的书!!!!推荐!
💻 HTM
📖 第 1 页 / 共 5 页
字号:
style='font-size:10.5pt;font-family:"Times New Roman"'>Translation</span><span
lang=ZH-CN style='font-size:10.5pt'>采用的是第一种做法,即移出的部分被截断。在给出源代码之前,先说明一个问题。</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>如果你用过</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Photoshop,Corel
PhotoPaint</span><span lang=ZH-CN style='font-size:10.5pt'>等图象处理软件,可能听说过“灰度图”</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>(grayscale)</span><span
lang=ZH-CN style='font-size:10.5pt'>这个词。灰度图是指只含亮度信息,不含色彩信息的图象,就象我们平时看到的黑白照片:亮度由暗到明,变化是连续的。因此,要表示灰度图,就需要把亮度值进行量化。通常划分成</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>0</span><span
lang=ZH-CN style='font-size:10.5pt'>到</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>255</span><span lang=ZH-CN style='font-size:
10.5pt'>共</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>256</span><span
lang=ZH-CN style='font-size:10.5pt'>个级别,其中</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>0</span><span lang=ZH-CN style='font-size:10.5pt'>最暗</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>(</span><span
lang=ZH-CN style='font-size:10.5pt'>全黑</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>)</span><span lang=ZH-CN style='font-size:10.5pt'>,</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>255</span><span
lang=ZH-CN style='font-size:10.5pt'>最亮</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>(</span><span lang=ZH-CN style='font-size:10.5pt'>全白</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>)</span><span
lang=ZH-CN style='font-size:10.5pt'>。</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>.bmp</span><span lang=ZH-CN style='font-size:
10.5pt'>格式的文件中,并没有灰度图这个概念,但是,我们可以很容易在</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>.bmp</span><span lang=ZH-CN style='font-size:
10.5pt'>文件中表示灰度图。方法是用</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>256</span><span
lang=ZH-CN style='font-size:10.5pt'>色的调色板,只不过这个调色板有点特殊,每一项的</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>值都是相同的。也就是说</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'>RGB</span><span lang=ZH-CN
style='font-size:10.5pt'>值从</span><span style='font-size:10.5pt;font-family:
"Times New Roman"'>(0</span><span lang=ZH-CN style='font-size:10.5pt'>,</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>0</span><span
lang=ZH-CN style='font-size:10.5pt'>,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>0)</span><span lang=ZH-CN style='font-size:10.5pt'>,</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>(1</span><span
lang=ZH-CN style='font-size:10.5pt'>,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>1</span><span lang=ZH-CN style='font-size:10.5pt'>,</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>1)</span><span
lang=ZH-CN style='font-size:10.5pt'>一直到</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>(255</span><span lang=ZH-CN style='font-size:
10.5pt'>,</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>255</span><span
lang=ZH-CN style='font-size:10.5pt'>,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>255)</span><span lang=ZH-CN style='font-size:
10.5pt'>。</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>(0</span><span
lang=ZH-CN style='font-size:10.5pt'>,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>0</span><span lang=ZH-CN style='font-size:10.5pt'>,</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>0)</span><span
lang=ZH-CN style='font-size:10.5pt'>是全黑色,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>(255</span><span lang=ZH-CN style='font-size:
10.5pt'>,</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>255</span><span
lang=ZH-CN style='font-size:10.5pt'>,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>255)</span><span lang=ZH-CN style='font-size:
10.5pt'>是全白色,中间的是灰色。这样,灰度图就可以用</span><span style='font-size:10.5pt;font-family:
"Times New Roman"'>256</span><span lang=ZH-CN style='font-size:10.5pt'>色图来表示了。为什么会这样呢?难道是一种巧合?其实并不是。</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>在表示颜色的方法中,除了</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>外,还有一种叫</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>YUV</span><span lang=ZH-CN style='font-size:
10.5pt'>的表示方法,应用也很多。电视信号中用的就是一种类似于</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>YUV</span><span lang=ZH-CN style='font-size:
10.5pt'>的颜色表示方法。</span><span style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>在这种表示方法中,</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Y</span><span
lang=ZH-CN style='font-size:10.5pt'>分量的物理含义就是亮度,</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'>U</span><span lang=ZH-CN
style='font-size:10.5pt'>和</span><span style='font-size:10.5pt;font-family:
"Times New Roman"'>V</span><span lang=ZH-CN style='font-size:10.5pt'>分量代表了色差信号</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>(</span><span
lang=ZH-CN style='font-size:10.5pt'>你不必了解什么是色差,只要知道有这么一个概念就可以了</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>)</span><span
lang=ZH-CN style='font-size:10.5pt'>。使用这种表示方法有很多好处,最主要的有两点:</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>(1)</span><span style='font-size:7.0pt;font-family:"Times New Roman"'>&nbsp;&nbsp;&nbsp;
</span><span lang=ZH-CN style='font-size:10.5pt'>因为</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Y</span><span
lang=ZH-CN style='font-size:10.5pt'>代表了亮度,所以</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>Y</span><span lang=ZH-CN style='font-size:10.5pt'>分量包含了灰度图的所有信息,只用</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Y</span><span
lang=ZH-CN style='font-size:10.5pt'>分量就能完全能够表示出一幅灰度图来。当同时考虑</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>U</span><span
lang=ZH-CN style='font-size:10.5pt'>,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>V</span><span lang=ZH-CN style='font-size:10.5pt'>分量时,就能够表示出彩色信息来。这样,用同一种表示方法可以很方便的在灰度和彩色图之间切换,而</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>表示方法就做不到这一点了。</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span style='font-size:10.5pt;font-family:
"Times New Roman"'>(2)</span><span style='font-size:7.0pt;font-family:"Times New Roman"'>&nbsp;&nbsp;&nbsp;
</span><span lang=ZH-CN style='font-size:10.5pt'>人眼对于亮度信号非常敏感,而对色差信号的敏感程度相对较弱。也就是说,图象的主要信息包含在</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Y</span><span
lang=ZH-CN style='font-size:10.5pt'>分量中。这就提示我们:如果在对</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>YUV</span><span
lang=ZH-CN style='font-size:10.5pt'>信号进行量化时,可以“偏心”一点,让</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Y</span><span
lang=ZH-CN style='font-size:10.5pt'>的量化级别多一些</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>(</span><span lang=ZH-CN style='font-size:10.5pt'>谁让它重要呢?</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>)</span><span
lang=ZH-CN style='font-size:10.5pt'>而让</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>UV</span><span lang=ZH-CN style='font-size:10.5pt'>的量化级别少一些,就可以实现图象信息的压缩。这一点将在第</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>9</span><span
lang=ZH-CN style='font-size:10.5pt'>章介绍图象压缩时仔细研究,这里就不深入讨论了。而</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>的表示方法就做不到这一点,因为</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>三个分量同等重要,缺了谁也不行。</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>YUV</span><span
lang=ZH-CN style='font-size:10.5pt'>和</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>RGB</span><span lang=ZH-CN style='font-size:
10.5pt'>之间有着如下的对应关系</span><span style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;
line-height:18.0pt'><sub><span style='font-size:10.5pt;font-family:"Times New Roman"'><!--[if gte vml 1]><v:shape
 id="_x0000_i1031" type="#_x0000_t75" alt="" style='width:264pt;height:57.75pt'>
 <v:imagedata src="./chp2.files/image007.gif" o:href="http://www-scf.usc.edu/~flv/ipbook/chap02.files/image014.gif"/>
</v:shape><![endif]--><![if !vml]><img width=352 height=77
src="./chp2.files/image007.gif" v:shapes="_x0000_i1031"><![endif]></span></sub><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p align=right style='margin:0cm;margin-bottom:.0001pt;text-align:right;
line-height:18.0pt'><span style='font-size:10.5pt;font-family:"Times New Roman"'>(2.3)<o:p></o:p></span></p>

<p align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;
line-height:18.0pt'><sub><span style='font-size:10.5pt;font-family:"Times New Roman"'><!--[if gte vml 1]><v:shape
 id="_x0000_i1032" type="#_x0000_t75" alt="" style='width:243pt;height:56.25pt'>
 <v:imagedata src="./chp2.files/image008.gif" o:href="http://www-scf.usc.edu/~flv/ipbook/chap02.files/image016.gif"/>
</v:shape><![endif]--><![if !vml]><img width=324 height=75
src="./chp2.files/image008.gif" v:shapes="_x0000_i1032"><![endif]></span></sub><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p align=right style='margin:0cm;margin-bottom:.0001pt;text-align:right;
line-height:18.0pt'><span style='font-size:10.5pt;font-family:"Times New Roman"'>(2.4)<o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>当</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>三个分量的大小一样时,假设都是</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>a</span><span
lang=ZH-CN style='font-size:10.5pt'>,代入公式</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>(2.3)</span><span lang=ZH-CN style='font-size:
10.5pt'>,得到</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>Y=a</span><span
lang=ZH-CN style='font-size:10.5pt'>,</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>U=0</span><span lang=ZH-CN style='font-size:
10.5pt'>,</span><span style='font-size:10.5pt;font-family:"Times New Roman"'>V=0
</span><span lang=ZH-CN style='font-size:10.5pt'>。你现在该明白我前面所说不是巧合的原因了吧。</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>使用灰度图有一个好处,那就是方便。首先</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>的值都一样;其次,图象数据即调色板索引值,也就是实际的</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>RGB</span><span
lang=ZH-CN style='font-size:10.5pt'>值,也就是亮度值;另外,因为是</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>256</span><span
lang=ZH-CN style='font-size:10.5pt'>色调色板,所以图象数据中一个字节代表一个象素,很整齐。如果是</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>2</span><span
lang=ZH-CN style='font-size:10.5pt'>色图或</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>16</span><span lang=ZH-CN style='font-size:10.5pt'>色图,还要拼凑字节,很麻烦。如果是彩色的</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>256</span><span
lang=ZH-CN style='font-size:10.5pt'>色图,由于图象处理后有可能会产生不属于这</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>256</span><span
lang=ZH-CN style='font-size:10.5pt'>种颜色的新颜色,就更麻烦了;这一点,今后你就会有深刻体会的。所以,做图象处理时,一般采用灰度图。为了将重点放在算法本身上,</span><b><span
lang=ZH-CN style='font-size:10.5pt;font-family:黑体;mso-hansi-font-family:"Times New Roman"'>今后给出的程序如不做特殊说明,都是针对</span></b><b><span
style='font-size:10.5pt;font-family:黑体;mso-hansi-font-family:"Times New Roman"'>256<span
lang=ZH-CN>级灰度图的。</span></span></b><span lang=ZH-CN style='font-size:10.5pt'>其它颜色的情况,你可以自己想一想,把算法补全。</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>如果想得到一幅灰度图,可以使用</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Sea</span><span
lang=ZH-CN style='font-size:10.5pt'>或者</span><span style='font-size:10.5pt;
font-family:"Times New Roman"'>PhotoShop</span><span lang=ZH-CN
style='font-size:10.5pt'>等软件提供的颜色转换功能将彩色图转换成灰度图。</span><span style='font-size:
10.5pt;font-family:"Times New Roman"'><o:p></o:p></span></p>

<p style='margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:
inter-ideograph;line-height:18.0pt'><span lang=ZH-CN style='font-size:10.5pt'>好了,言归正传,下面给出</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>Translation</span><span
lang=ZH-CN style='font-size:10.5pt'>的源代码。算法的思想是先将所有区域填成白色,然后找平移后显示区域的左上角点</span><span
style='font-size:10.5pt;font-family:"Times New Roman"'>(x<sub>0</sub>,y<sub>0</sub>)
</span><span lang=ZH-CN style='font-size:10.5pt'>和右下角点</span><span

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -