I have 6 points as shown in the picture above.
Can I make a closed contour from the 6 points as shown below?
I've tried to use creating ellipse and imfill() but they didn't work.
Thank you.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 23 日
編集済み: Ameer Hamza 2020 年 4 月 23 日

1 投票

Try this
im = im2double(imread('image.jpeg'));
im_gray = rgb2gray(im);
im_gray = imbinarize(im_gray)*1;
[r,c] = find(im_gray==1);
points = [c r];
p = convhull(points);
points = points(p, :).';
poly_points = points(:).';
im_gray = insertShape(im_gray, 'FilledPolygon', poly_points, ...
'Color', [1 1 1], ...
'Opacity', 1, ...
'SmoothEdges', false);
imshow(im_gray);

7 件のコメント

Yohanes Setiawan
Yohanes Setiawan 2020 年 4 月 24 日
Thank you for your response.
Why r, c being [c r] in points?
Yohanes Setiawan
Yohanes Setiawan 2020 年 4 月 24 日
編集済み: Yohanes Setiawan 2020 年 4 月 24 日
Anyway, I haven't had Computer Vision Toolbox :'(
I'm using MATLAB R2018b
Ameer Hamza
Ameer Hamza 2020 年 4 月 24 日
This code use image processing toolbox
im = im2double(imread('image.jpeg'));
im_gray = rgb2gray(im);
im_gray = imbinarize(im_gray)*1;
[r,c] = find(im_gray==1);
points = [c r];
p = convhull(points);
points = points(p, :);
im_gray = roipoly(im_gray, points(:,1), points(:,2));
imshow(im_gray);
Yohanes Setiawan
Yohanes Setiawan 2020 年 4 月 24 日
Thanks!
I've installed new version of MATLAB which has Computer Vision Toolbox.
Then I'm running your code and get this error:
Error using insertShape
Expected input number 1, I, to be one of these types:
uint8, uint16, int16, double, single
Instead its type was logical.
Ameer Hamza
Ameer Hamza 2020 年 4 月 24 日
Can you show your code?
Yohanes Setiawan
Yohanes Setiawan 2020 年 4 月 24 日
It has been solved!
I changed into double and WORKED!
Thank you so much for your help.
Ameer Hamza
Ameer Hamza 2020 年 4 月 24 日
I am glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by