stats = regionprops(bw4,'Centroid','ConvexHull','BoundingBox'); data(1,1:2) = cat(1,stats(1).Centroid);figure; imshow(bw4); tn = stats.BoundingBox; hold on; h = rectangle('Position', tn, 'EdgeColor','r');
时间: 2023-11-27 21:04:15 浏览: 36
要在图像上同时画出BoundingBox矩形框和中心点,可以使用 `plot` 函数或 `scatter` 函数,将BoundingBox的中心坐标作为输入参数,同时使用 `rectangle` 函数画出BoundingBox矩形框。
以下是示例代码,假设BoundingBox的左上角坐标为(x1, y1),右下角坐标为(x2, y2),BoundingBox的中心坐标为(center_x, center_y):
```python
% 计算BoundingBox的中心坐标
center_x = stats(1).Centroid(1);
center_y = stats(1).Centroid(2);
% 在图像上画出BoundingBox矩形框和中心点
imshow(bw4);
hold on;
rectangle('Position', stats(1).BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
plot(center_x, center_y, 'r+', 'MarkerSize', 10, 'LineWidth', 2);
```
其中 `imshow` 函数用于显示二值图像 `bw4`,`hold on` 用于保持当前图像并在其上添加其他图形。
`rectangle` 函数用于在图像中绘制矩形框,其中 `'Position'` 表示矩形的位置和大小,`'EdgeColor'` 表示矩形框的边缘颜色,`'LineWidth'` 表示边缘线的宽度。
`plot` 函数用于在图像中绘制点和线,其中 `'r+'` 表示将点绘制为红色十字形,`'MarkerSize'` 和 `'LineWidth'` 分别表示十字形的大小和线宽。
希望这个回答能够帮助到你。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)