<commit_before>#ģ̬ѧ
    ʴȥıԵ㣬ϸСеĵ㶼ᱻΪǱԵ㣬˻ɾȥʱĴԭĴСɾСԶʧˡ
    Ͳʹı߽ţڲСնĻͲЩϣǱ߽ˡٽиʴʱⲿ߽罫ԭӣЩڲնԶʧˡ
 
 ```cpp
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
int main(){
	IplImage* pImage= NULL;
  pImage = cvLoadImage ( "Lena.jpg", -1 ); //ͼ
	IplImage* pImgErode= NULL;// IplImage 
	IplImage* pImgDilate= NULL; 
	pImgErode=cvCloneImage(  pImage );
	pImgDilate=cvCloneImage( pImage );
	//ͼʹĬϵ33 νṹԪؽиʴ
	cvErode( pImgErode, pImgErode, 0, 2 );
 	//ͼʹĬϵ33 νṹԪؽ
	cvDilate( pImgDilate, pImgDilate, 0, 2 );
	
	cvNamedWindow("Erosion", 0);
	cvShowImage("Erosion", pImgErode );

	cvNamedWindow("Dilation", 0);
	cvShowImage("Dilation", pImgDilate );

	cvWaitKey(0);
	cvReleaseImage(&pImgErode);
	cvReleaseImage(&pImgDilate);
	cvDestroyWindow("Erosion");
	cvDestroyWindow("Dilation");

}
```

##
    ȸʴͣȥĿĹ㡣
    գٸʴȥĿڵĿס

```cpp
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
int main(){
 	IplImage* pImage= NULL;
	IplImage* pImgOpen= NULL;// IplImage 
	IplImage* pImgClose= NULL;
	IplConvKernel* pKernel =NULL;
// IplConvKernel 
	pImage = cvLoadImage ( "Lena.jpg", -1 );
	pImgOpen=cvCloneImage(pImage );
	pImgClose=cvCloneImage(pImage);
	//ṹԪ
	pKernel = cvCreateStructuringElementEx(15,15,8, 8,CV_SHAPE_ELLIPSE,NULL);
    	//п
	cvErode(pImgOpen,pImgOpen,pKernel,1);
  cvDilate(pImgOpen,pImgOpen,pKernel,1);   
 
	//б
    cvDilate(pImgClose,pImgClose,pKernel,1);   
	cvErode(pImgClose,pImgClose,pKernel,1);
		
	//ڣʾͼ
	cvNamedWindow("Open", 0);
	cvShowImage("Open", pImgOpen );

	cvNamedWindow("Close", 0);
	cvShowImage("Close", pImgClose );


		cvWaitKey(0);
	cvReleaseImage(&pImgOpen);
	cvReleaseImage(&pImgClose);
	cvDestroyWindow("Open");
	cvDestroyWindow("Close");
	

}
```

УһԵڲ̬ѧ⣬õԶ˺Ϊ
```cpp
IplConvKernel * cvCreateStructuringElementEx(  int cols,  int rows,  int anchor_x,  int anchor_y,  int shape,  int *value=NULL  );  
IplConvKernel * cvCreateStructuringElementEx(  
int cols,  
int rows,  
int anchor_x,  
int anchor_y,  
int shape,  
int *value=NULL  );
```
> 
* в`colsrows`ȷ˹ľδС 
* anchor_x,anchor_yȷ˷վڲοĺꡣ
* shapeԶ˵״Ϊ
  
      1.CV_SHAPE_RECT  Ǿ  
    2.CV_SHAPE_CROSS ӽ
    3.CV_SHAPE_ELLIPSE Բ
    4.CV_SHAPE_CUSTOM ûԶ<commit_msg>Update 10.md<commit_after>#四．形态学运算
    
> 腐蚀操作会去掉物体的边缘点，细小物体所有的点都会被认为是边缘点，因此会整个被删去。再做膨胀时，留下来的大物体会变回原来的大小，而被删除的小物体则永远消失了。  
> 
    膨胀操作会使物体的边界向外扩张，如果物体内部存在小空洞的话，经过膨胀操作这些洞将被补上，因而不再是边界了。再进行腐蚀操作时，外部边界将变回原来的样子，而这些内部空洞则永远消失了。
 
 ```cpp
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
int main(){
	IplImage* pImage= NULL;
  pImage = cvLoadImage ( "Lena.jpg", -1 ); //读入图像
	IplImage* pImgErode= NULL;// 声明IplImage 变量
	IplImage* pImgDilate= NULL; 
	pImgErode=cvCloneImage(  pImage );
	pImgDilate=cvCloneImage( pImage );
	//对输入图像使用默认的3×3 长方形结构，元素进行腐蚀
	cvErode( pImgErode, pImgErode, 0, 2 );
 	//对输入图像使用默认的3×3 长方形结构，元素进行膨胀
	cvDilate( pImgDilate, pImgDilate, 0, 2 );
	
	cvNamedWindow("Erosion", 0);
	cvShowImage("Erosion", pImgErode );

	cvNamedWindow("Dilation", 0);
	cvShowImage("Dilation", pImgDilate );

	cvWaitKey(0);
	cvReleaseImage(&pImgErode);
	cvReleaseImage(&pImgDilate);
	cvDestroyWindow("Erosion");
	cvDestroyWindow("Dilation");

}
```

##开闭运算
    开：先腐蚀再膨胀，可以去掉目标外的孤立点。
    闭：先膨胀再腐蚀，可以去掉目标内的孔。

```cpp
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
int main(){
 	IplImage* pImage= NULL;
	IplImage* pImgOpen= NULL;// 声明IplImage 变量
	IplImage* pImgClose= NULL;
	IplConvKernel* pKernel =NULL;
// 声明IplConvKernel 变量
	pImage = cvLoadImage ( "Lena.jpg", -1 );
	pImgOpen=cvCloneImage(pImage );
	pImgClose=cvCloneImage(pImage);
	//建立结构元素
	pKernel = cvCreateStructuringElementEx(15,15,8, 8,CV_SHAPE_ELLIPSE,NULL);
    	//进行开运算
	cvErode(pImgOpen,pImgOpen,pKernel,1);
  cvDilate(pImgOpen,pImgOpen,pKernel,1);   
 
	//进行闭运算
    cvDilate(pImgClose,pImgClose,pKernel,1);   
	cvErode(pImgClose,pImgClose,pKernel,1);
		
	//创建窗口，显示图像
	cvNamedWindow("Open", 0);
	cvShowImage("Open", pImgOpen );

	cvNamedWindow("Close", 0);
	cvShowImage("Close", pImgClose );


		cvWaitKey(0);
	cvReleaseImage(&pImgOpen);
	cvReleaseImage(&pImgClose);
	cvDestroyWindow("Open");
	cvDestroyWindow("Close");
	

}
```

其中，一个可以调节参数的形态学例题，用到的自定义核函数为
```cpp
IplConvKernel * cvCreateStructuringElementEx(  int cols,  int rows,  int anchor_x,  int anchor_y,  int shape,  int *value=NULL  );  
IplConvKernel * cvCreateStructuringElementEx(  
int cols,  
int rows,  
int anchor_x,  
int anchor_y,  
int shape,  
int *value=NULL  );
```
> 
* 函数中参数`cols，rows`确定了构造的矩形大小。 
* anchor_x,anchor_y确定了封闭矩形内参考点的横纵坐标。
* shape是自定义核的形状，具体为
  
      1.CV_SHAPE_RECT  核是矩形  
    2.CV_SHAPE_CROSS 核是勺子交叉形
    3.CV_SHAPE_ELLIPSE 核是椭圆形
    4.CV_SHAPE_CUSTOM 核是用户自定义类型
{'fraction_non_alphanumeric': 0.1434322033898305, 'fraction_numerical': 0.013135593220338982, 'mean_word_length': 5.091612903225807, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5286979', 'n_tokens_mistral': 2574, 'n_tokens_neox': 2578, 'n_words': 328}