可视化和椭圆regionprops
一个博客读者问我最近如何可视化ellipse-based测量计算regionprops。读者想重叠估计椭圆图像。
刷新你的记忆:函数regionprops计算几何测量的图像区域,提供了几种测量基于拟合椭圆。(如果你一定要知道的话,适合被匹配计算二阶椭圆的时刻。)这些测量是:
- MajorAxisLength
- MinorAxisLength
- 取向
我将使用一个参数方程绘制一个椭圆。方便,维基百科文章椭圆有一个参数方程的形式是正确的:
$ $ X (t) = X_c + t \ \因为因为罪罪\φ- b \ t \ \φ$ $
$ $ Y (t) = Y_c + t \ \因为罪罪\φ+ b \ t \ cosφ\ $ $
(X_c Y_c)美元在哪里椭圆中心,一美元和b美元是主要和次要的轴的长度,和\φ是美元轴和主轴之间的角度。
让我们试着用这张图片,其中包含一堆ellipse-like对象:
url =“https://blogs.mathworks.com/steve/files/rice-bw.png”;bw = imread (url);imshow (bw)
![](http://www.tatmou.com/blogs/steve/files/ellipse_lines_01.png)
问regionprops计算所有ellipse-related测量:
s = regionprops (bw, {…“重心”,…“MajorAxisLength”,…“MinorAxisLength”,…“定位”})
s = 69 x1结构体数组字段:重心MajorAxisLength MinorAxisLength取向
这是第七个对象的测量是什么样子:
(7)
ans =重心:[37.9286 - 226.9732]MajorAxisLength: 30.9655 MinorAxisLength: 9.7466取向:-64.8058
现在写一个循环一次计算椭圆曲线,为每一个对象,并添加上的曲线图像。
图imshow (bw,“InitialMagnification”,“健康”)t = linspace(0, 2 *π,50);持有在为k = 1:长度(s) = s (k) .MajorAxisLength / 2;b = s (k) .MinorAxisLength / 2;Xc = s (k) .Centroid (1);Yc = s (k) .Centroid (2);函数φ= (- s (k) .Orientation);x = Xc + * cos (t) * cos(φ)- b * sin (t) *罪(φ);y = Yc + * cos (t) * sin(φ)+ b * sin (t) * cos(φ);情节(x, y,“r”,“线宽”5)结束持有从
![](http://www.tatmou.com/blogs/steve/files/ellipse_lines_02.png)
就是这样!
享受。
评论
留下你的评论,请点击在这里MathWorks账户登录或创建一个新的。