morphologyEx 形态学处理
<p>[TOC]</p>
<h5>简要描述</h5>
<ul>
<li>形态学。腐蚀、膨胀、开、闭。等。</li>
</ul>
<h5>参数</h5>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">必选</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">mat</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">mat</td>
<td>mat对象</td>
</tr>
<tr>
<td style="text-align: left;">morphType</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">int</td>
<td>形态学类型。<br/>0、膨胀(扩张) <br/>1、腐蚀(收缩) <br/>2、开运算(消黏连) <br/>3、闭运算(闭间隙)<br/> 4、黑帽(取闭算部分)<br/> 5、顶帽(取开算部分) <br/>6、基本梯度(剃出边缘)</td>
</tr>
<tr>
<td style="text-align: left;">kw ,kh</td>
<td style="text-align: left;">(可选)</td>
<td style="text-align: left;">int</td>
<td>积卷核大小,通常为。3x3。</td>
</tr>
<tr>
<td style="text-align: left;">ax , ay</td>
<td style="text-align: left;">(可选)</td>
<td style="text-align: left;">int</td>
<td>积卷核中心点,通常为-1 x -1。</td>
</tr>
<tr>
<td style="text-align: left;">kernel_type</td>
<td style="text-align: left;">(可选)</td>
<td style="text-align: left;">int</td>
<td>积卷核类型、形状。 <Br/> 0、MORPH RECT:矩形。<Br/> 1、MORPH CROSS:十字交又。<Br/>2、MORPH ELLIPSE:椭圆或者圆形</td>
</tr>
</tbody>
</table>
<h5>返回参数说明</h5>
<p>mat | null</p>
<h5>膨胀(高通,造成高亮度,逐渐覆盖低亮度效果)</h5>
<pre><code class="language-java"> //载入动漫图像
var mat=cvImg.loadFromFile("/sdcard/Pictures/tem.jpg",1);
var mat_result=cvImg.morphologyEx (mat,0,3,3,-1,-1,0);
cvImg.toFile(mat_result,"/sdcard/Pictures/tem4.jpg");
cvImg.release(mat);//释放
cvImg.release(mat_result);//释放</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=893498da37a1b32e69f8be5cee964936" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=070be5b765ae3d371267cff878703530" alt="" /></p>
<h5>腐蚀(低通,造成低亮度,逐渐覆盖高亮度效果)</h5>
<pre><code class="language-java"> //载入动漫图像
var mat=cvImg.loadFromFile("/sdcard/Pictures/tem.jpg",1);
var mat_result=cvImg.morphologyEx (mat,1,3,3,-1,-1,0);
cvImg.toFile(mat_result,"/sdcard/Pictures/tem4.jpg");
cvImg.release(mat);//释放
cvImg.release(mat_result);//释放</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=893498da37a1b32e69f8be5cee964936" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=138ef4b205b4e325028e9567a4376d6f" alt="" /></p>
<h5>开操作(消除小的杂点,黏连)</h5>
<pre><code class="language-java"> //创建500*500图
var mat=cvImg.zeros(500,500,0);
//填充白色
cvImg.rectangle(mat,0,0,500,500,[100,100,100,0],-1);
//画矩形
cvImg.rectangle(mat,50,50,280,280,[255,255,255,0],-1);
cvImg.rectangle(mat,100,100,120,120,[100,100,100,0],-1);
cvImg.rectangle(mat,250,250,480,480,[255,255,255,0],-1);
cvImg.rectangle(mat,300,300,400,400,[100,100,100,0],-1);
cvImg.rectangle(mat,10,10,30,30,[255,255,255,0],-1);
cvImg.rectangle(mat,10,200,30,250,[255,255,255,0],1);
cvImg.rectangle(mat,400,20,450,100,[255,255,255,0],1);
cvImg.toFile(mat,"/sdcard/Pictures/tem3.jpg");
//演示开操作操作
var mat_result=cvImg.morphologyEx (mat,2,3,3,-1,-1,2);
cvImg.toFile(mat_result,"/sdcard/Pictures/tem4.jpg");
cvImg.release(mat);//释放
cvImg.release(mat_result);//释放</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=6d4cda0b89297614cf4bb50918ec68b2" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=3b3906b7cfc14e884a4250c64f4408bf" alt="" /></p>
<h5>闭操作(填充小范围的间隙)</h5>
<pre><code class="language-java"> //创建500*500图
var mat=cvImg.zeros(500,500,0);
//填充白色
cvImg.rectangle(mat,0,0,500,500,[100,100,100,0],-1);
//画矩形
cvImg.rectangle(mat,50,50,280,280,[255,255,255,0],-1);
cvImg.rectangle(mat,100,100,120,120,[100,100,100,0],-1);
cvImg.rectangle(mat,285,285,480,480,[255,255,255,0],-1);
cvImg.rectangle(mat,300,300,400,400,[100,100,100,0],-1);
cvImg.rectangle(mat,10,10,20,20,[255,255,255,0],1);
cvImg.rectangle(mat,10,200,30,250,[255,255,255,0],1);
cvImg.rectangle(mat,400,20,450,100,[255,255,255,0],1);
cvImg.toFile(mat,"/sdcard/Pictures/tem3.jpg");
//演示闭操作操作
var mat_result=cvImg.morphologyEx (mat,3,15,15,-1,-1,2);
cvImg.toFile(mat_result,"/sdcard/Pictures/tem4.jpg");
cvImg.release(mat);//释放
cvImg.release(mat_result);//释放</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=5499442b08097c93c52b53294ca0f669" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c7e2fc10fb18fcbf39bfc12582614e1e" alt="" /></p>
<h5>梯度(得到边缘)</h5>
<pre><code class="language-java"> //创建500*500图
var mat=cvImg.zeros(500,500,0);
//填充白色
cvImg.rectangle(mat,0,0,500,500,[100,100,100,0],-1);
//画矩形
cvImg.rectangle(mat,50,50,280,280,[255,255,255,0],-1);
cvImg.rectangle(mat,100,100,120,120,[100,100,100,0],-1);
cvImg.rectangle(mat,250,250,480,480,[255,255,255,0],-1);
cvImg.rectangle(mat,300,300,400,400,[100,100,100,0],-1);
cvImg.rectangle(mat,10,10,20,20,[255,255,255,0],1);
cvImg.rectangle(mat,10,200,30,250,[255,255,255,0],1);
cvImg.rectangle(mat,400,20,450,100,[255,255,255,0],1);
cvImg.toFile(mat,"/sdcard/Pictures/tem3.jpg");
//演示梯度操作
var mat_result=cvImg.morphologyEx (mat,6,3,3,-1,-1,2);
cvImg.toFile(mat_result,"/sdcard/Pictures/tem4.jpg");
cvImg.release(mat);//释放
cvImg.release(mat_result);//释放</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=b33db3673c5d8e1a6055227bd16cde53" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c7a8a2aadb1251a17525a4b64aca336c" alt="" /></p>
<h5>顶帽(消除亮块)</h5>
<pre><code class="language-java"> //创建500*500图
var mat=cvImg.zeros(500,500,0);
//填充白色
cvImg.rectangle(mat,0,0,500,500,[100,100,100,0],-1);
//画矩形
cvImg.rectangle(mat,50,50,280,280,[255,255,255,0],-1);
cvImg.rectangle(mat,100,100,120,120,[100,100,100,0],-1);
cvImg.rectangle(mat,250,250,480,480,[255,255,255,0],-1);
cvImg.rectangle(mat,300,300,400,400,[100,100,100,0],-1);
cvImg.rectangle(mat,10,10,20,20,[255,255,255,0],1);
cvImg.rectangle(mat,10,200,30,250,[255,255,255,0],1);
cvImg.rectangle(mat,400,20,450,100,[255,255,255,0],1);
cvImg.toFile(mat,"/sdcard/Pictures/tem3.jpg");
//演示顶帽操作
var mat_result=cvImg.morphologyEx (mat,5,3,3,-1,-1,2);
cvImg.toFile(mat_result,"/sdcard/Pictures/tem4.jpg");
cvImg.release(mat);//释放
cvImg.release(mat_result);//释放</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=7ff75e3d1f47d3cb34c21bac3afd4715" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=7c775806642850f39a7bd17856067472" alt="" /></p>
<h5>黑帽(分离暗块)</h5>
<pre><code class="language-java"> //填充白色
cvImg.rectangle(mat,0,0,500,500,[100,100,100,0],-1);
//画矩形
cvImg.rectangle(mat,50,50,280,280,[255,255,255,0],-1);
cvImg.rectangle(mat,100,100,120,120,[100,100,100,0],-1);
cvImg.rectangle(mat,250,250,480,480,[255,255,255,0],-1);
cvImg.rectangle(mat,300,300,400,400,[100,100,100,0],-1);
cvImg.rectangle(mat,10,10,20,20,[255,255,255,0],1);
cvImg.rectangle(mat,10,200,30,250,[255,255,255,0],1);
cvImg.rectangle(mat,400,20,450,100,[255,255,255,0],1);
cvImg.toFile(mat,"/sdcard/Pictures/tem3.jpg");
//演示黑帽操作
var mat_result=cvImg.morphologyEx (mat,4,3,3,-1,-1,2);
cvImg.toFile(mat_result,"/sdcard/Pictures/tem4.jpg");
cvImg.release(mat);//释放
cvImg.release(mat_result);//释放</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=53034d15cca1f4f5315c8077b831c06a" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=45307e014340131a7fc3eac65bb98c36" alt="" /></p>