对轮廓图进行不变矩特征的提取,用matlab实现
时间: 2023-05-27 11:01:29 浏览: 82
下面是一个使用Matlab代码提取不变矩特征的示例:
1. 读取图像并转换为灰度图像
```
img = imread('image.jpg');
gray_img = rgb2gray(img);
```
2. 二值化图像
```
threshold = graythresh(gray_img);
binary_img = imbinarize(gray_img, threshold);
```
3. 提取轮廓
```
contour_img = bwperim(binary_img);
```
4. 计算不变矩
```
[centroid_x, centroid_y] = centroid(contour_img);
m00 = moment(contour_img,0,0);
m10 = moment(contour_img,1,0);
m01 = moment(contour_img,0,1);
mu11 = moment(contour_img,1,1) - centroid_x*moment(contour_img,0,1);
mu20 = moment(contour_img,2,0) - centroid_x*moment(contour_img,1,0) + centroid_x^2*m00;
mu02 = moment(contour_img,0,2) - centroid_y*moment(contour_img,0,1) + centroid_y^2*m00;
nu11 = mu11 / m00^(2/2+1);
nu20 = mu20 / m00^(2/2);
nu02 = mu02 / m00^(2/2);
```
以上代码将计算中心矩和规范化中心矩,并存储在nu11、nu20和nu02变量中
阅读全文
相关推荐















