usnistgov / NFIQ2

Optical live-scan and ink fingerprint image quality assessment tool
https://www.nist.gov/services-resources/software/development-nfiq-20
Other
130 stars 57 forks source link

Rules for computing ROI not followed exactly #340

Closed gfiumara closed 3 weeks ago

gfiumara commented 2 years ago

Describe the issue 5.2.13.3 step g indicates that regions in the contour map surrounded by black shall be black. In the image 00002531_S_500_slap_03.png from NIST SD 302, this is not followed.

6_b_contoursFilled

To reproduce Steps to reproduce the issue:

  1. Compute quality for 00002531_S_500_slap_03.png, and look at filled contour output.

Expected behavior

6_b_contoursFilled-correct

OS information

Library information

NFIQ 2 version information Biometric Evaluation: 10.0 FingerJet: 5.2.1 OpenCV: 4.5.4 NFIQ 2: 2.2.0 (Date: 202208051443, Commit: e8f4914)

Code sample Is there a reliable code sample you can include?

N/A

Additional context

gfiumara commented 2 years ago

Also consider the scenario where this same image has the middle erased, as if a hole were punched out of a scanned ink card. The image B' might look like this:

5_OtsuThresh

After following steps f and g, image C should be:

6_b_contoursFilled

However, NFIQ 2 produces:

6_b_contoursFilled

gfiumara commented 1 year ago

This patch may be the solution. I think one of the bigger issues is that we may have needed to find contours on the inverted mask.

diff --git src/NFIQ2/NFIQ2Algorithm/src/features/ImgProcROIFeature.cpp dst/NFIQ2/NFIQ2Algorithm/src/features/ImgProcROIFeature.cpp
index e6d631b42c4f98929ffd9c9efda97d5f8310b636..8f5997001c3d93ed1debd57c5007e014c96f4fb9 100644
--- src/NFIQ2/NFIQ2Algorithm/src/features/ImgProcROIFeature.cpp
+++ dst/NFIQ2/NFIQ2Algorithm/src/features/ImgProcROIFeature.cpp
@@ -140,21 +140,17 @@ NFIQ2::QualityFeatures::ImgProcROIFeature::computeROI(cv::Mat &img,
    std::vector<cv::Vec4i> hierarchy;

    // find contours in image
+   contImg = ~contImg;
    cv::findContours(contImg, contours, hierarchy, cv::RETR_CCOMP,
        cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));

    // if holes are found -> close holes
-   if (hierarchy.size() > 2) {
-       cv::Mat filledImg;
-       cv::cvtColor(threshImg2, filledImg, cv::COLOR_GRAY2BGR);
-
-       for (unsigned int idx = 0; idx < (hierarchy.size() - 2);
-            idx++) {
-           cv::drawContours(filledImg, contours, idx,
-               cv::Scalar(0, 0, 0, 0), cv::FILLED, 8, hierarchy);
+   for (int h{}; h < hierarchy.size(); ++h) {
+       // If contour on inverted image has a parent, it's a hole
+       if (hierarchy[h][3] != -1) {
+           cv::drawContours(threshImg2, contours, h, cv::Scalar(0),
+               cv::LineTypes::FILLED, 8, hierarchy);
        }
-
-       cv::cvtColor(filledImg, threshImg2, cv::COLOR_BGR2GRAY);
    }

    // 7. remove smaller blobs at the edges that are not part of the
gfiumara commented 7 months ago

Fixed in 0564f51.