使用OpenCV增强手掌静脉

cid*_*cid 3 opencv filtering biometrics image-enhancement

我正在尝试在OpenCV中实现一种算法,以显示手掌静脉模式的细节.我的基础是我在互联网上找到的一篇名为" 使用掌纹和掌静脉功能的非接触式生物识别系统 "的论文.我感兴趣的部分是第3.2预处理.这里显示了涉及的步骤.

我想使用OpenCV进行实现,但直到现在我都陷入困境.特别是他们在低通滤波器的响应上使用拉普拉斯滤波器来隔离主脉,但无论我尝试的参数如何,我的结果都会非常嘈杂!

任何帮助将不胜感激!

cid*_*cid 7

好吧最后我自己想通了怎么做.这是我的代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#define THRESHOLD 150
#define BRIGHT 0.7
#define DARK 0.2

using namespace std;
using namespace cv;

int main()
{

    // Read source image in grayscale mode
    Mat img = imread("roi.png", CV_LOAD_IMAGE_GRAYSCALE);

    // Apply ??? algorithm from https://stackoverflow.com/a/14874992/2501769
    Mat enhanced, float_gray, blur, num, den;
    img.convertTo(float_gray, CV_32F, 1.0/255.0);
    cv::GaussianBlur(float_gray, blur, Size(0,0), 10);
    num = float_gray - blur;
    cv::GaussianBlur(num.mul(num), blur, Size(0,0), 20);
    cv::pow(blur, 0.5, den);
    enhanced = num / den;
    cv::normalize(enhanced, enhanced, 0.0, 255.0, NORM_MINMAX, -1);
    enhanced.convertTo(enhanced, CV_8UC1);

    // Low-pass filter
    Mat gaussian;
    cv::GaussianBlur(enhanced, gaussian, Size(0,0), 3);

    // High-pass filter on computed low-pass image
    Mat laplace;
    Laplacian(gaussian, laplace, CV_32F, 19);
    double lapmin, lapmax;
    minMaxLoc(laplace, &lapmin, &lapmax);
    double scale = 127/ max(-lapmin, lapmax);
    laplace.convertTo(laplace, CV_8U, scale, 128);

    // Thresholding using empirical value of 150 to create a vein mask
    Mat mask;
    cv::threshold(laplace, mask, THRESHOLD, 255, CV_THRESH_BINARY);

    // Clean-up the mask using open morphological operation
    morphologyEx(mask,mask,cv::MORPH_OPEN,
        getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5,5)));

    // Connect the neighboring areas using close morphological operation
    Mat connected;
    morphologyEx(mask,mask,cv::MORPH_CLOSE,
        getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(11,11)));

    // Blurry the mask for a smoother enhancement
    cv::GaussianBlur(mask, mask, Size(15,15), 0);

    // Blurry a little bit the image as well to remove noise
    cv::GaussianBlur(enhanced, enhanced, Size(3,3), 0);

    // The mask is used to amplify the veins
    Mat result(enhanced);
    ushort new_pixel;
    double coeff;
    for(int i=0;i<mask.rows;i++){
        for(int j=0;j<mask.cols;j++){
            coeff = (1.0-(mask.at<uchar>(i,j)/255.0))*BRIGHT + (1-DARK);
            new_pixel = coeff * enhanced.at<uchar>(i,j);
            result.at<uchar>(i,j) = (new_pixel>255) ? 255 : new_pixel;
        }
    }

    // Show results
    imshow("frame", img);
    waitKey();

    imshow("frame", result);
    waitKey();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

因此,本文的主要步骤如下.对于某些部分,我激发了自己发现的代码.这是我在这里找到的第一个应用处理的情况.同样对于高通滤波器(laplacian),我对自己在OpenCV 2计算机视觉应用编程手册中给出的代码给予了启发.

最后,通过允许修改背景的亮度和静脉的暗度,我做了一些小的改进(参见定义BRIGHT和DARK).我还决定模糊一下面具以获得更"自然"的增强效果.


这里的结果(来源/论文结果/我的结果):

源图像 论文结果 我的结果