-
Notifications
You must be signed in to change notification settings - Fork 0
/
findBestMatchANNwithPreviousLevel.m
51 lines (39 loc) · 1.93 KB
/
findBestMatchANNwithPreviousLevel.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
function [ min_difference ] = findBestMatchANNwithPreviousLevel( fVectorB, smaller_scale_fVectorB, fVectorBp, smaller_scale_fVectorBp, A, Ap, neighborhood_size, smaller_scale_neighborhood_size, anno, annPts, k, eps )
%findBestMatchANNwithPreviousLevel Find the pixel in A/Ap that best matches the feature
%vector given using ANN.
% Detailed explanation goes here
%ANN match
Afvectors = A.fvectors;
full_neighborhood = neighborhood_size*neighborhood_size;
halfNeighborhoodSize = floor(full_neighborhood/2);
%Smaller scale
%smaller_scale_full_neighborhood = smaller_scale_neighborhood_size*smaller_scale_neighborhood_size;
%Gaussian weights
gauss_matrix = fspecial('gaussian', neighborhood_size);
gauss_weights = reshape(gauss_matrix.',1,[]); % single vector form
partial_gauss_weights = gauss_weights(1, 1:halfNeighborhoodSize);
concatGaussWeights = [gauss_weights partial_gauss_weights];
%square root of the gaussian weights
concatGaussWeightsSR = sqrt(concatGaussWeights);
%Both smaller_B and smaller_Bp use full neighborhoods
gauss_matrix = fspecial('gaussian', smaller_scale_neighborhood_size);
gauss_weights = reshape(gauss_matrix.',1,[]); % single vector form
smaller_scale_concatGaussWeights = [gauss_weights gauss_weights];
%square root of the gaussian weights
smaller_scale_concatGaussWeightsSR = sqrt(smaller_scale_concatGaussWeights);
concatGaussWeightsSR = [concatGaussWeightsSR smaller_scale_concatGaussWeightsSR];
%% Use ANN to find nearest neighbor of this B + Bp + small_B + small_Bp fvector
%numRowsA = size(Afvectors,1);
numColsA = size(Afvectors,2);
min_difference.norm = intmax; % start with max integer value
pt = [fVectorB fVectorBp smaller_scale_fVectorB smaller_scale_fVectorBp];
pt = pt.*concatGaussWeightsSR;
pt = pt';
[idx dst] = ksearch(anno, pt, k, eps);
% nearest_neighbor = annPts(idx);
rowA = ceil(double(idx)/numColsA);
colA = idx - ((rowA-1)*numColsA);
min_difference.norm = dst;
min_difference.i = rowA;
min_difference.j = colA;
end