advanced usage of matlab roipoly command

别等时光非礼了梦想. 提交于 2019-12-06 13:54:34

问题


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 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].

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 ?


回答1:


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)

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);



来源:https://stackoverflow.com/questions/18015190/advanced-usage-of-matlab-roipoly-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!