-
Notifications
You must be signed in to change notification settings - Fork 1
/
DSPmini.m
46 lines (34 loc) · 1.14 KB
/
DSPmini.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
obj = imread('rugby.jpg');
imshow(obj)
%%Segmenting image
%% Divide image "obj" into its respective RGB intenstites
red = obj(:,:,1);
green = obj(:,:,2);
blue = obj(:,:,3);
figure(1)
subplot(2,2,1); imshow(obj); title('Original Image');
subplot(2,2,2); imshow(red); title('Red Plane');
subplot(2,2,3); imshow(green); title('Green Plane');
subplot(2,2,4); imshow(blue); title('Blue Plane');
%Threshold the blue plane
figure(2)
level = 0.37;
bw2 = im2bw(blue,level);
subplot(2,2,1);imshow(bw2); title('Blue plane threshold')
%%Remove Noise
%%Fill any holes
fill = imfill(bw2, 'holes');
subplot(2,2,2); imshow(fill); title('Holes Filled');
%%Remove any blbs on the border of the image
clear = imclearborder(fill);
subplot(2,2,3); imshow(clear); title('Remove blobs on border');
%%Remove blobs that are smaller than 7 pixels across
se = strel('disk',7);
open = imopen(fill,se);
subplot(2,2,4); imshow(clear); title('Remove small blobs')
%% Measure Onject Diameter
diameter = regionprops(open,'MajorAxisLength');
%%Show result
figure(3)
imshow(obj)
d = imdistline; %%Include a line to physically measure the ball