当前位置:网站首页>Matlab: obtain the figure edge contour and divide the figure n equally

Matlab: obtain the figure edge contour and divide the figure n equally

2022-06-13 02:30:00 weixin_ forty-five million six hundred and thirty-three thousan

Get the shape edge contour

Matlab It has a good effect in image processing , Use the following pictures as a demonstration
3D Graphic section

Binary picture , Reuse Matlab Of edge Function to extract edges

clear;clc;
file_path='E:\file\matlab\';% Image folder path , Modified here 
fprintf(' The image being read is :\n');

bw=0.3; %  Adaptive threshold 

img_name=[file_path,'stone1.png'];% file name , Modified here 
pitch=imread(img_name);
pitch=rgb2gray(pitch);% Grayscale 

pitch=histeq(pitch);% Enhance contrast 
pitch=imadjust(pitch);
pitch=histeq(pitch);% Enhance contrast 
pitch0=imadjust(pitch);
pitch=imbinarize(pitch0,bw);% Binary picture 

w=fspecial('gaussian',[2,2],0.02);% Filtering noise reduction 
pitch=imfilter(pitch,w);% Filtering noise reduction 

pitch=edge(pitch,'sobel',0.01);% Edge extraction 
% Extract contour coordinates , Can choose noholes Only search for objects 
[Bound, L] = bwboundaries(pitch,8,'holes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on

k=1; % For this reference figure , Take the first boundary for calculation 
x=Bound{k}(:,2);% extract x coordinate 
y=Bound{k}(:,1);% extract y coordinate 
plot(x, y, 'w', 'LineWidth', 2)
hold on

X=sum(x); %x The coordinates and 
x_average=X/length(x); % Center point x Coordinates of 
Y=sum(y);%y The coordinates and 
y_average=Y/length(y); % Center point y Coordinates of 
plot(x_average, y_average, 'g*')
hold on

Get picture effects
 outline

Put the figure n Equal division

Matlab There are already big men in the community John D’Errico Put the figure n The bisection function is written as a function :interparc , Can be in matlab Log in to the official website and download it directly to call .
stay Matlab Community File Exchange There are many excellent function functions contributed by big guys , This is also Matlab One of the features that makes it easy to use .

pt = interparc(24,x,y,'spline'); % n Bisection contour , here n take 24
plot(pt(:,1),pt(:,2),'b-o')
hold on

Get picture effects :
 Insert picture description here

Complete code

Matlab: Get the shape edge contour , Set the outline figure n Equal division , And find out n Inside corner of a concave polygon

Reference blog

原网站

版权声明
本文为[weixin_ forty-five million six hundred and thirty-three thousan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280542334447.html