-
Notifications
You must be signed in to change notification settings - Fork 1
/
processing.m
79 lines (57 loc) · 2.13 KB
/
processing.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%% ######## F1 Feature extraction ########
clear, close all, clear HX;
img = imread('input.jpg');
% converts image's values in double notation
img = im2double(img);
%% Image crop
% crops the image to exclude part of the sky which does not contain useful information
img = img(900:end,:,:);
%% Compute the sky mask
% creates a mask excluding the useless sky color based.
% changes the color space to hsv
img_hsv = rgb2hsv(img);
min_v = 0;
max_v = 0.80;
% selects a range on the channel V
sky_mask = (min_v <= img_hsv(:,:,3)) & (img_hsv(:,:,3) <= max_v);
% the mask is improved with dilate function.
sky_mask = imdilate(sky_mask, strel('square',30));
% applies the mask on the image
img_masked = bsxfun(@times, img, cast(sky_mask, 'like', img));
figure; imshow(img_masked);
%% Histogram equalization
img_edge = img;
% converts the 3 channels image to one channel image
img_edge = rgb2gray(img_edge);
% applies the adaptive histogram equalization only on the castle (excluding the sky)
img_edge = roifilt2(img_edge, sky_mask, 'adapthisteq');
figure; imshow(img_edge);
%% Edges detection
% computes the rescaled image size
k = 0.4;
rescaled_size = k*size(img,1,2);
% rescales the image
img_edge = imresize(img_edge, rescaled_size, 'bilinear');
% applies the canny algorithm
edges = edge(img_edge, 'canny', [0.1, 0.2], 3);
figure; imshow(edges);
%% Detecting lines
% applies the Hough transformation
[H,T,R] = hough(edges, "Theta", (-90:1:89), 'RhoResolution', 1);
% selects the peaks in the parameters plane
P = houghpeaks(H, 300,'threshold', ceil(0.1*max(H(:))), "NHoodSize", [15,15]);
% searches the segments lines in the image given the peak lines
lines = houghlines(edges, T, R, P,'FillGap', 8,'MinLength', 25);
figure; imshow(img_edge), hold on;
draw_lines(lines);
%% Features detection
img_corners = img;
% converts the image to gray scale
img_corners = rgb2gray(img_corners);
% applies the histogram equalization
img_corners = roifilt2(img_corners, sky_mask, 'adapthisteq');
% applies the SURF algorithm
corners = detectSURFFeatures(img_corners);
figure; imshow(img_corners), hold on;
% plots the strongest features
plot(corners.selectStrongest(500));