-
Notifications
You must be signed in to change notification settings - Fork 0
/
PetalsOrientExtract.m
62 lines (52 loc) · 1.84 KB
/
PetalsOrientExtract.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
55
56
57
58
59
60
61
62
% To extract orientation of petal-like beams
% Written by£ºZhenyu Wan (z.wan.1@research.gla.ac.uk)
clear
close all
%% Input parameters
ImageAddress = '.\';
ImageName = 'Example-CentreResizedImage.png';
FeaturePoints = 2; % number of feature points (ex. the petals)
Select = 0; % 1 for self-choosing regions; 0 for not
Threshold = 200; % remove the background noise under the threshold
Ibindex = 100; % for 'bwareaopen' function
%% Main
ImageRead = strcat(ImageAddress,ImageName);
BeamPattern = imread(ImageRead);
% Imaging processing for removing outer rings
Ib = imadjust(BeamPattern,[Threshold/255 1],[0 1],0.2);
Ib(Ib<Threshold) = 0;
Ib = imbinarize(Ib); % Binaryzation
Ib = bwareaopen(Ib,Ibindex); % remove light areas with pixel numbers below Ibindex
if Select == 1
Ib = bwselect(Ib); imshow(Ib);
end
% find centroid of each petal area
Centroid = regionprops(Ib, 'Centroid');
if size(Centroid,1) == FeaturePoints
Petals = cat(1,Centroid.Centroid);
else
Petals = cat(1,Centroid.Centroid);
disp('Check the Threshold or FeaturePoints and rerun program');
end
BeamCentre = mean(Petals,1);
% calculate orientation of beam
if FeaturePoints == 2
Orient = (Petals(1,2)-Petals(2,2))/(Petals(2,1)-Petals(1,1));
Orient = atand(Orient); % output -90~90
else
Orient = zeros(FeaturePoints,1);
for num = 1:FeaturePoints
Orient(num) = (BeamCentre(2)-Petals(num,2))/(Petals(num,1)-BeamCentre(1));
end
Orient = atand(Orient); % output -90~90
end
figure('color','w','position',[500 100 600 600]);
subplot(2,1,1)
imagesc(BeamPattern);
colormap gray; axis image; axis off;
subplot(2,1,2)
imagesc(Ib);
hold on
plot(Petals(:,1),Petals(:,2),'r.','MarkerSize',10);
plot(BeamCentre(1),BeamCentre(2),'r.','MarkerSize',10);
colormap gray; axis image; axis off;