matlab roipoly命令的高级用法 [英] advanced usage of matlab roipoly command

查看:500
本文介绍了matlab roipoly命令的高级用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是matlab的新手,正致力于图像处理。我正在使用roipoly函数来创建一个掩码。据我所知,我可以像这样使用它:

I am new to matlab and am working on Image processing. I am using the roipoly function to create a mask. As I understand I can use it like this :

I = imread('eight.tif');
c = [222 272 300 270 221 194];
r = [21 21 75 121 121 75];
BW = roipoly(I,c,r);
figure, imshow(I)
figure, imshow(BW)

图片如下所示:

The image is shown below :

One我观察到的是c& C指定的相邻点之间的插值。 r矩阵由线性插值完成,在其他意义上,总是在点之间绘制直线。是否有可能以某种方式包含其他类型的插值,如二次或三次样条插值?

One observation I had was that the interpolation between the adjacent points as specified by the c & r matrix is done by 'Linear Interpolation', in other sense always a straight line is drawn between the points. Can it be possible that somehow other types of interpolation are incorporated , like quadratic or cubic spline interpolation ?

假设我真正想要的是这样做,如下图所示。 [原谅我的画,不太好]。

Suppose what I really wanted was to do this as shown in the picture below. [Pardon my drawing, its not very good].

这里的圆圈显示轮廓上的点。我想要提取或创建的图形为线条所示的形状。正如你所看到的那样,只有当我们使用样条或二次方程进行插值而不是通过roipoly进行线性插值时才有可能。

Here the circles show the points on the contour. I wanted the figure that is extracted or created to be in the shape as shown by the lines. As you can see it is possible only if we do interpolation by using splines or quadratic equations and not by linear interpolation which is done by roipoly.

我该怎么做?你们能帮助我吗?

How can I do this ? Can you guys help me ?

推荐答案

你可以使用imellipse:

You can use imellipse:

I = imread('eight.tif');
% roughly estimating ellipse values from your given c/r
c = [222 272 300 270 221 194];
r = [21 21 75 121 121 75];
xmin = min(c);
ymin = min(r);
width = range(c);
height = range(r);

h_im = imshow(I);
e = imellipse(gca,[xmin ymin width height]);
BW = createMask(e,h_im);

figure, imshow(I)
figure, imshow(BW)

如果您不想使用日食,可以在c和r上使用interp1或其他插值函数:

If you don't want to use an eclipse, you can use interp1 or other interpolation functions on c and r :

% editing r and c so the shape closes - just take first value, append to end:
c = [222 272 300 270 221 194 222];
r = [21 21 75 121 121 75 21];
% adjust interpolation to suit
c2 = interp1(1:7,c,1:0.2:7,'pchip');
r2 = interp1(1:7,r,1:0.2:7,'pchip');
BW2 = roipoly(I,c2,r2);

这篇关于matlab roipoly命令的高级用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆