Newer
Older
BleedingDetectionKimura-sanMethod / Feature_extraction.h
#pragma once
#include "raw_image_class.h"
#include "extravasation_detect.h"
#include <random>
//using namespace cv;

//分類器や特徴抽出に関するクラス
//その他にもMatの連結などの操作も含まれる
static class Feature_extraction
{
public :
	//濃度特徴量の構造体
	struct DensityData {
		int* Hist;
		double* NormalizeHist;
		double* CPD;
		const double t = 0.03;

		//ヒストグラム範囲の画素数
		int HistVOXELS = 0;
		//最大値
		short Max = -999;
		//最小値
		short Min = -999;
		//平均
		double Average = 0;
		//歪度
		double Skewness = 0;
		//分散
		double Variance = 0;
		//尖度
		double Kurtosis = 0;
	};
	//濃度特徴抽出
	static cv::Mat Density_histgram(Raw_image<short>& ct, array3<unsigned int>& labeling, size_t labelcount);

	//GLCMの構造体
	struct GLCMData {
		float** simMatrinx;
		float** Q;
		float Mf = -999;
		float Mn = -999;
		float* Py;
		float* Px;
		float* Pxpy;
		float* Pxsy;
		float SAvey = 0;
		float Ax = 0;
		float Ay = 0;
		float Sx = 0;
		float Sy = 0;
		float HX = 0;
		float HY = 0;
		float HXY1 = 0;
		float HXY2 = 0;
		//最頻値
		float mode = 0;

		//範囲の画素数
		float MatrixCount = 0;

		////取得する特徴量
		//角度の二次モーメント
		float ASM = 0;
		float DASM = 0;

		//コントラスト
		float Contrast = 0;
		//相関
		float Correlation = 0;
		//分散
		float Variance = 0;
		//逆差モーメント
		float IDM = 0;
		//平均
		float SAverage = 0;
		//分散
		float SVariance = 0;
		//エントロピー
		float SEntropy = 0;
		//エントロピー
		float Entropy = 0;
		//差分散
		float DVariance = 0;
		//差エントロピー
		float DEntropy = 0;
		//相関の情報量
		float IMOC1 = 0;
		//相関の情報量
		float IMOC2 = 0;
		//最大相関係数
		float MCC = 0;
	};
	//ヒストグラム均等化
	static array3<uchar> Histogram_equalization(Raw_image<short>& ct, int len);
	//GLCM
	static cv::Mat GLCM(array3<uchar>& image, array3<unsigned int>& label, size_t& labelcount,int len);

	//ラプラシアン特徴
	static cv::Mat Laplace_feature(Raw_image<short>& ct, array3<unsigned int>& label, size_t& labelcount);

	//Mat操作
	static cv::Mat MatLink(cv::Mat& firstMat, cv::Mat& secondMat);
	static cv::Mat Addsample(cv::Mat& firstMat, cv::Mat& secondMat);
	static cv::Mat LabelMat(cv::Mat& input, int Label);

	//スケーリング
	static void Scaling(cv::Mat& feature);

	//スクリーニング
	static cv::Mat Screening(cv::Mat& samples);

	//全部の特徴の抽出
	static cv::Mat All_feature_exstract(Raw_image<short> ct, array3<unsigned int>& label, size_t& labelcount, int len);

	//データ数の削減
	static cv::Mat Feature_Cut(cv::Mat& samples, bool shafful, float Falserate);
	//推定
	static array3<uchar> Predict(cv::Ptr<cv::ml::RTrees> r_tree, array3<unsigned int>& label, size_t& labelcount, cv::Mat samples);



	//csvファイルの取り扱い
	static void writeCSV(char* FileName, cv::Mat samples);
	
	//CSV出力したデータの読み込み
	struct CSVData {
		cv::Mat Labels;
		cv::Mat samples;
	};

	static CSVData readCSV(char* dataset);
};