-
Notifications
You must be signed in to change notification settings - Fork 30
/
MI.hpp
55 lines (50 loc) · 3.4 KB
/
MI.hpp
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
// This file is part of the LITIV framework; visit the original repository at
// https://github.com/plstcharles/litiv for more information.
//
// Copyright 2017 Pierre-Luc St-Charles; pierre-luc.st-charles<at>polymtl.ca
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "litiv/features2d.hpp"
/// Mutual Information (MI) calculation helper (interface is similar to feature extractors, works only for 8U images)
class MutualInfo : public cv::Algorithm {
public:
/// default constructor
MutualInfo(const cv::Size& oWinSize=cv::Size(41,41), bool bNormalize=false, bool bUseDenseHist=false, bool bUse24BitPair=true);
/// loads params from the specified file node @@@@ not impl
virtual void read(const cv::FileNode&) override;
/// writes params to the specified file storage @@@@ not impl
virtual void write(cv::FileStorage&) const override;
/// returns the window size that will be used around each keypoint
virtual cv::Size windowSize() const;
/// returns the border size required around each keypoint in x or y direction
virtual int borderSize(int nDim=0) const; // typically equal to windowSize().width/2
/// returns the mutual information score for the given image pair (assumes full matrices are already window-sized)
double compute(const cv::Mat& oImage1, const cv::Mat& oImage2);
/// returns the mutual information scores for the given keypoints located in the image pair using subwindows of the size passed in constructor
void compute(const cv::Mat& oImage1, const cv::Mat& oImage2, const std::vector<cv::KeyPoint>& voKeypoints, std::vector<double>& vdScores);
/// returns the mutual information scores for the given keypoints located in the image pair using subwindows of the size passed in constructor (inline version)
std::vector<double> compute(const cv::Mat& oImage1, const cv::Mat& oImage2, const std::vector<cv::KeyPoint>& voKeypoints);
/// utility function, used to filter out bad keypoints that would trigger out of bounds error because they're too close to the image border
void validateKeyPoints(std::vector<cv::KeyPoint>& voKeypoints, cv::Size oImgSize) const;
/// utility function, used to filter out bad pixels in a ROI that would trigger out of bounds error because they're too close to the image border
void validateROI(cv::Mat& oROI) const;
protected:
/// defines the window size to use with keypoint-based calls (window will always be center on keypoint, and size should be odd)
const cv::Size m_oWinSize;
/// defines whether output mutual info scores should be normalized to the [0-1] range similarly to the Pearson correlation coefficient or not
const bool m_bNormalize;
/// defines whether dense histograms will be used for joint probability extimation or not
const bool m_bUseDenseHist;
/// defines whether color images in color-grayscale pairs will be quantized to 16-bit YCbCr
const bool m_bUse24BitPair;
};