-
Notifications
You must be signed in to change notification settings - Fork 0
/
todaytest1.m
54 lines (32 loc) · 1.04 KB
/
todaytest1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
clear all ; close all ; clc
%% import image png
[IM , M] = imread('Shape2.png') ;
IM = imresize(IM,[300 NaN]) ; % for decrease compute process
G = rgb2gray(IM) ; % rgb to grayscale image
BW = imbinarize(G) ; % grayscale image to binary image
BW = imerode(BW,strel('disk',1)) ; % Improve Binary image
%%
[~,Lab,~,~] = bwboundaries(BW) ;
bw = Lab == 1 ;
imshow(bw) ; hold on ;
[Bound,~,~,~] = bwboundaries(bw) ;
% global x y % additional
x = Bound{2,1}(:,2) ;
y = Bound{2,1}(:,1) ;
plot(x,y,'b','LineWidth',1.25) ;
index = randi(length(x),[1,25]) ;
% index = [400:10:460] ;
xr = x(index) ;
yr = y(index) ;
plot(xr,yr,'*y') ;
Para = CircleFitByKasa([xr , yr]) ;
xc = round(Para(1)) ;
yc = round(Para(2)) ;
% plot(xc,yc,'or') ;
theta = 0:0.01:2*pi ;
xp = xc + (Para(3)+10)*cos(theta) ;
yp = yc + (Para(3)+10)*sin(theta) ;
plot(xp,yp,'r')
LCen = CheckCenterInGrain(bw,xc,yc) ;
[~,Factor] = CheckCircleInGrain(bw,xc,yc,Para(3)+10,0.9)
[~,Factor] = CheckGrainInCircle(bw,xc,yc,Para(3)+10,0.9)