<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>阅微堂 &#187; 搜索</title>
	<atom:link href="http://zhiqiang.org/blog/tag/%e6%90%9c%e7%b4%a2/feed" rel="self" type="application/rss+xml" />
	<link>http://zhiqiang.org/blog</link>
	<description>数学、金融、计算机</description>
	<lastBuildDate>Sat, 19 May 2012 13:47:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>图片搜索的原理</title>
		<link>http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html</link>
		<comments>http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html#comments</comments>
		<pubDate>Thu, 21 Jul 2011 12:52:30 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[计算机科学]]></category>
		<category><![CDATA[图片搜索]]></category>
		<category><![CDATA[搜索]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/?p=2393</guid>
		<description><![CDATA[博客 » 计算机科学 » 图片搜索，搜索，算法 » Google新推出了图片搜索，可直接上传图片（或者用图片链接）搜索网络上的相似图片，例子。估计还没多少人意识到，这玩意儿是人肉搜索的大杀器，以后大家还是少上传私人照片到公开网络。 阮一峰介绍了一个简单的图片搜索原理，可分为下面几步： 缩小尺寸。将图片缩小到8x8的尺寸，总共64个像素。这一步的作用是去除图片...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/science/computer-science">计算机科学</a> » <a href="http://zhiqiang.org/blog/tag/%e5%9b%be%e7%89%87%e6%90%9c%e7%b4%a2" rel="tag">图片搜索</a>，<a href="http://zhiqiang.org/blog/tag/%e6%90%9c%e7%b4%a2" rel="tag">搜索</a>，<a href="http://zhiqiang.org/blog/tag/%e7%ae%97%e6%b3%95" rel="tag">算法</a> » </p><p>Google新推出了<a title="图片搜索" href="http://images.google.com.hk/" target="_blank">图片搜索</a>，可直接上传图片（或者用图片链接）搜索网络上的相似图片，<a title="Google图片搜索示例" href="http://images.google.com.hk/search?tbs=sbi:AMhZZiub0aevgXm9IVunrcdmjFiDKUbz2BAvYURynMjiNR0pAf3abjiQcuUE9XFJHlFMr1cxJ5ub4lgyxYwyVK2qgvUSCD6kK2YDTadslg6TwRQcG_1PnvSdfIIK4W_1KrJ3i16AhBLVmSHYZKomjEBNWdWt9hr000DHeIdJLf6t4ODa1uJ6MwCmXCfGqJLWYEqEXyuAa_1Zg9rUBXrDYh7MtpzVY-2Y4_1BegAVHQ9Nj871b-JHGkYWeSQ2Pyp0SYxVkMczwhyO_1OqtTqE9EJL3Xvn4e7rJQdAClNSu2uLCQ6yuGWQsb5BncHpOLYiNmoI5StZveg-UwA5I2wg-dfqTWn1xOwYvKURHz5xxzj4CQkpkfBsEz9RiEpja4KK1r_1VxSGLYedGXjq4A2_1_1ASNVi_1_1FpEHgU4f66EFPd3j6zngu4_1Mv5POJMX7YjvHmb82HJ00_1ZOPK6F3Hl1strPjdhT7ir7MNJ9tBM0KPyxMOFS-f8y1hnX6xMw8N065sTmnsxXfY2Vrstf0gMx8CdNbI0eLGK13Ju-2tXPciFBh3M4pG7CYyyZzHDnHf_1V6VrXNAdVTU-D_1pLUJcbkP2AX9OzPVl1BaKZy1RAp3edU7iZb7IXOWMVkgA2_1b7F7mBewG1TClGSMRPHSxAe9WHMtDPZcBBdnIS6RXfU3HcC7iGcQjeAV6I8wgnuB1nNK_1WI4JtAcd591KH3ey168cO9p2yrmb_1sOKU_1LAKM6pYb7Tp6jdbqFhgn5WfBUAbbpXVBrJMbTh3UCyXtrOF2vyvqeDsLWVVikWydTtfjao5PrOsYK7RihZO_1Rks_1R-FowS0eAqVIuQGJVgFJUMk6Q6qw5Qmh02LfXLMP5jkzdV6foi87VQxtMCO8NWgzVIC4BURKr4Vi4_1NVY3uIk9-vtfBnwxl-bWKBIVuvK9BRaA&amp;btnG=%E6%90%9C%E7%B4%A2&amp;hl=zh-CN&amp;newwindow=1&amp;sa=N&amp;gbv=2&amp;biw=1024&amp;bih=631" target="_blank">例子</a>。估计还没多少人意识到，这玩意儿是人肉搜索的大杀器，以后大家还是少上传私人照片到公开网络。</p>
<p><a href="http://www.ruanyifeng.com/blog/2011/07/principle_of_similar_image_search.html" target="_blank">阮一峰介绍</a>了一个简单的图片搜索原理，可分为下面几步：</p>
<ol>
<li>缩小尺寸。将图片缩小到8x8的尺寸，总共64个像素。这一步的作用是去除图片的细节，只保留结构、明暗等基本信息，摒弃不同尺寸、比例带来的图片差异。</li>
<li>简化色彩。将缩小后的图片，转为64级灰度。也就是说，所有像素点总共只有64种颜色。</li>
<li>计算平均值。计算所有64个像素的灰度平均值。</li>
<li>比较像素的灰度。将每个像素的灰度，与平均值进行比较。大于或等于平均值，记为1；小于平均值，记为0。</li>
<li>计算哈希值。将上一步的比较结果，组合在一起，就构成了一个64位的整数，这就是这张图片的指纹。组合的次序并不重要，只要保证所有图片都采用同样次序就行了。</li>
</ol>
<p>这种方法对于寻找一模一样的图片是有效的，但并不能够去搜索“相似”的照片，也不能局部搜索，比如从一个人的单人照找到这个人与别人的合影。这些Google Images都能做到。</p>
<p>Google的算法，其<a href="http://insidesearch.blogspot.com/2011/07/teaching-computers-to-see-image.html" target="_blank">官方描述</a>为：</p>
<blockquote><p>When you upload an image to Search by Image, the algorithms analyze the content of the image and break it down into smaller pieces called “<a href="http://en.wikipedia.org/wiki/Feature_detection_(computer_vision)">features</a>”. These features try to capture specific, distinct characteristics of the image - like textures, colors, and shapes. Features and their geometric configuration represent the computer’s understanding of what the image looks like.</p></blockquote>
<p>大意是说在Google眼里，图片并不是一个由像素点构成点阵，而是一些“features"，包括形状、质地和颜色块。图片之间的比较，是直接去比较图片里的线条等。<a href="http://insidesearch.blogspot.com/2011/07/teaching-computers-to-see-image.html" target="_blank">官方文档里有一个视频</a>（在Youtube上）动态地描述了计算机是如何看图片的。</p>
<p>早在2008年，Google公布了一篇图片搜索的论文（<a href="http://www.www2008.org/papers/pdf/p307-jingA.pdf" target="_blank">PDF版</a>），和文本搜索的思路是一样的：</p>
<ul>
<li>对于每张图片，抽取其特征。这和文本搜索对于网页进行分词类似。</li>
<li>对于两张图片，其相关性定义为其特征的相似度。这和文本搜索里的文本相关性也是差不多的。</li>
<li>图片一样有image rank。文本搜索中的page rank依靠文本之间的超链接。图片之间并不存在这样的超链接，image rank主要依靠图片之间的相似性（两张图片相似，便认为它们之间存在超链接）。具有更多相似图片的图片，其image rank更高一些。</li>
</ul>
<div><h4>相关文章</h4><ul><li class='currentpost'><a href="http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html">图片搜索的原理</a></li><li ><a href="http://zhiqiang.org/blog/it/google-web-search-api-build-station.html">Google Web API打造站内搜索</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/preliminary-computer-theory-algorithms-and-calculation-model.html">理论计算机初步：算法和计算模型</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/an-algorithm-face-interviews-question-test.html">一个算法面试题 &#038; 面试题库</a></li><li ><a href="http://zhiqiang.org/blog/science/mathmatics-in-rubik-cube-and-algorithm.html">魔方里的数学</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/programs-depend-on-date-struct-not-algorithm.html">编程的核心是数据结构，而不是算法</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/another-perfect-shuffle-algorithm.html">Perfect Shuffle的算法</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/download-encyclopedia-of-algorithm.html">算法百科全书 - Encyclopedia of Algorithms</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/inverse-square-root-algorithm-analysis.html">求平方根倒数的算法</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/max-drawdown-algorithm.html">最大回撤和最大短期回撤的线性算法</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2011. | <a href="http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html#comments">10 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Google Web API打造站内搜索</title>
		<link>http://zhiqiang.org/blog/it/google-web-search-api-build-station.html</link>
		<comments>http://zhiqiang.org/blog/it/google-web-search-api-build-station.html#comments</comments>
		<pubDate>Tue, 05 Sep 2006 02:07:10 +0000</pubDate>
		<dc:creator>zhiqiang</dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[Google Web API]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[搜索]]></category>

		<guid isPermaLink="false">http://zhiqiang.org/blog/436.html</guid>
		<description><![CDATA[博客 » IT技术 » Google Web API，PHP，搜索 » WordPress自带了站内搜索，可是搜索结果很不令人满意。它的搜索是通过MYSQL查询得来的，所以首先它无法分词和切词，对于中文搜索效果尤其差。其次它无法在搜索结果中高亮度和重点显示搜索关键词相关内容，而是显示一堆乱七八糟的东西。但用上Google Web API构建的站内搜索后，一切都迎刃而解。 利用Google Web API，可以将搜索内容发...]]></description>
			<content:encoded><![CDATA[<p id="breadcrumb" class="breadcrumb"><a href="http://zhiqiang.org/blog/">博客</a> » <a href="http://zhiqiang.org/blog/category/it">IT技术</a> » <a href="http://zhiqiang.org/blog/tag/google-web-api" rel="tag">Google Web API</a>，<a href="http://zhiqiang.org/blog/tag/php" rel="tag">PHP</a>，<a href="http://zhiqiang.org/blog/tag/%e6%90%9c%e7%b4%a2" rel="tag">搜索</a> » </p><p>WordPress自带了站内搜索，可是搜索结果很不令人满意。它的搜索是通过<a href="http://www.mysql.com">MYSQL</a>查询得来的，所以首先它无法分词和切词，对于中文搜索效果尤其差。其次它无法在搜索结果中高亮度和重点显示搜索关键词相关内容，而是显示一堆乱七八糟的东西。但用上Google Web API构建的站内搜索后，一切都迎刃而解。</p>
<p><center><br />
<form action="http://zhiqiang.org/blog/search.php" method="get">
<input id="q" size="30" name="q" type="text" />
<input type="submit" value="Search" /> </form>
<p></center>利用<a href="http://code.google.com/" target="_blank">Google Web API</a>，可以将搜索内容发送到<a href="http://www.google.com.hk/">Google</a>，再处理Google返回的搜索结果，最后显示在自己的页面上，如下图所示：</p>
<p align="center"><a title="Photo Sharing" href="http://www.flickr.com/photos/mathzqy/234477793/"><img height="394" alt="google" src="http://farm1.static.flickr.com/97/234477793_d04c9828af.jpg" width="497" /></a></p>
<p>Google Web API的功能不限于搜索，它还可以读Google Cache，单词纠错等。不过我目前只用了它的搜索功能。主要参考了<a href="http://goood.org" target="_blank">通过php调用Google API</a>和Google Web API: PHP implementation这两篇文章。PHP的SOAP类下载于<a href="http://pear.php.net/" target="_blank">PEAR</a>。另外鄙视一下PEAR上的文档结构，包里面的文件都不全，每下载一个文件，运行就告诉我还缺少另一个补充文件。最后我只好去搜索关键词，一个文件一个文件把它们补齐。这种工作对我这种业余人士太耗费时间了。</p>
<p>网络的乐趣在于共享，所以提供<a href="http://sites.google.com/site/mathzqy/GoogleAPI.zip">下载</a>。下载后放在blog的根目录下。search.php的前几行可能需要重新配置:</p>
<blockquote>
<pre>$num = 10; <span style="color: #008000">// 每次查询显示的结果数量</span>
$<span style="color: #ffa500">key</span> = '<span style="color: #8b0000">Enter your google license key</span>';  <span style="color: #008000">// Google API key，去<a href="http://code.google.com/">http://www.google.com/apis/</a>申请</span>
$navi_num = 7; <span style="color: #008000">// 导航页面的页面数量</span></pre>
</blockquote>
<div><h4>相关文章</h4><ul><li class='currentpost'><a href="http://zhiqiang.org/blog/it/google-web-search-api-build-station.html">Google Web API打造站内搜索</a></li><li ><a href="http://zhiqiang.org/blog/science/computer-science/how-google-search-similar-images.html">图片搜索的原理</a></li></ul></div>    <p></p>
    <hr noshade style="margin:0;height:1px" />
    <p>&copy; zhiqiang for <a href="http://zhiqiang.org/blog">阅微堂</a>, 2006. | <a href="http://zhiqiang.org/blog/it/google-web-search-api-build-station.html">&#38142;&#25509;</a> | <a href="http://zhiqiang.org/blog/it/google-web-search-api-build-station.html#comments">23 &#26465;&#35780;&#35770;</a></p>]]></content:encoded>
			<wfw:commentRss>http://zhiqiang.org/blog/it/google-web-search-api-build-station.html/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

