图像算法-Hessian矩阵的血管肺纹理骨骼增强对比
肺纹理增强:
肺结节增强:
血管对比增强:
骨骼对比增强:
根据参考资料:
MATLAB版本:
https://ww2.mathworks.cn/matlabcentral/fileexchange/24409-hessian-based-frangi-vesselness-filter
算法原理:
https://baike.baidu.com/item/黑塞矩阵/2248782?fr=aladdin
实现代码
include "stdafx.h"
include
include
include
include
include
include "MatBase64.h"
include "frangi.h"
include "ET.Functions.h"
using namespace std;
using namespace cv;
char* GetFrangiBase64Code(char* base64code, int SIGMA_START, int SIGMA_END, int SIGMA_STEP, float BETA_ONE, float BETA_TWO, bool BLACKWHITE){
//初始化矩阵参数
frangi2d_opts_t opts;
frangi2d_createopts(&opts, SIGMA_START, SIGMA_END, SIGMA_STEP, BETA_ONE, BETA_TWO, BLACKWHITE);
//处理传入的base64编码转为Mat对象
string imgcode =base64code;
string s_mat;
s_mat = base64Decode(imgcode.data(), imgcode.size());
vector<char> base64_img(s_mat.begin(), s_mat.end());
Mat input_img = cv::imdecode(Mat(base64_img), CV_LOAD_IMAGE_GRAYSCALE);
//进行frangi算法处理
Mat input_img_fl;
input_img.convertTo(input_img_fl, CV_32FC1);
Mat vesselness, scale, angles;
frangi2d(input_img_fl, vesselness, scale, angles, opts);
vector<uchar> buf;
imencode(".jpg", vesselness * 255, buf);
auto *enc_msg = reinterpret_cast<unsigned char*>(buf.data());
string encoded = base64Encode(enc_msg, buf.size());
//返回base64编码
char *result = new char[encoded.length() + 1];
for (int i = 0; i < encoded.length(); ++i)
{
result[i] = encoded[i];
}
result[encoded.length()] = '\0';
return result;
}