HOW to remove horizontale line and preserve edge

asked 2018-03-05 16:37:52 -0500

garbalawal gravatar image

updated 2018-03-06 11:49:39 -0500

i want to remove small horizontal line and preserve edge of my image using opencv3 or better if existing. I used opencv3 and used fld and i got a poor result because edge were destroyed. Tfis is my code for Fast Line Detection:

     void CIpt4vMain::ApplyRemoveBarbs(Mat & InputMat, Mat & OutputMat, /*Mat& OriginalImg, */int nBarbIntensity, int& nProgress) {
        // Mat input
        Mat input = InputMat.clone();
        //int nRows = input.rows;
        //int nCols = input.cols;
        // Intensity
        cl::BarbLength bl = static_cast<cl::BarbLength>(nBarbIntensity);
        // FLD parameter
        int nLength_threshold;
        double nCanny_th1, nCanny_th2;
        // Seg

ment parameter
    float fLength_decr = 0.0f;
    float fLength_incr = 0.0f;
    float fLength_critera = 0.0f;

    switch (bl) {
    case cl::LENGTH_VERYWEAK: fLength_critera=3.0f, fLength_decr =
30.0f, fLength_incr = 2.0f, nLength_threshold = 1, nCanny_th1 =
1.0, nCanny_th2 = 1.0;
        break;
    case cl::LENGTH_WEAK: fLength_critera = 4.0f, fLength_decr =
30.0f, fLength_incr = 2.0f, nLength_threshold = 1, nCanny_th1 =
1.0, nCanny_th2 = 1.0;
        break;
    case cl::LENGTH_MEDIUM:fLength_critera =
5.0f, fLength_decr = 30.0f, fLength_incr = 2.0f, nLength_threshold
= 1, nCanny_th1 = 1.0, nCanny_th2 = 1.0;
        break;
    case cl::LENGTH_STRONG: fLength_critera = 6.0f, fLength_decr =
30.0f, fLength_incr = 2.0f, nLength_threshold = 1, nCanny_th1 =
1.0, nCanny_th2 = 1.0;
        break;
    case cl::LENGTH_VERYSTRONG: fLength_critera =7.0f, fLength_decr =
30.0f, fLength_incr = 2.0f, fLength_incr = 2.0f, nLength_threshold
= 1, nCanny_th1 = 1.0, nCanny_th2 = 1.0;
        break;
    case cl::LENGTH_POWERFULL: fLength_critera = 8.0f, fLength_decr =
30.0f, fLength_incr = 2.0f, nLength_threshold = 1, nCanny_th1 =
1.0, nCanny_th2 = 1.0;
        break;
    case cl::LENGTH_VERYPOWERFULL: fLength_critera = 9.0f, fLength_decr =
30.0f, fLength_incr = 2.0f, nLength_threshold = 10, nCanny_th1 =
1.0, nCanny_th2 = 1.0;
        break;
    default: fLength_critera = 10.0f, fLength_decr = 4.0f, fLength_incr =
2.0f, nLength_threshold = 10, nCanny_th1 = 10.0, nCanny_th2 = 10.0;
        break;
    }

    // Mask container
    //cv::Mat BarbMask = cv::Mat::zeros(input.size(), input.type());
    //cv::Mat EdgeMask = BarbMask.clone();

    //************  Looking for Mask of Barbs
    vector<Vec4f> vecLines;
    ApplyFLD(input, vecLines, nLength_threshold, nCanny_th1, nCanny_th2);
    int nLinesCount = vecLines.size();

    // ******************* Sort Edge (barb or edge)
    for (int i = 0; i < nLinesCount; i++) {
        Vec4f line = vecLines[i];
        CEdgeLace* pEl = new CEdgeLace(line);
        if (pEl->IsBarb(fLength_critera)) {
            CBarbLace* b = (CBarbLace*)pEl;
            // Decrease barb length
            //b->Reduce_SegmentLength(fLength_decr);
            // Draw the new reduced edge in white with a tchickness = 10;
            b->Draw(input, 3, Scalar(255, 255, 255));
        }else {
            //pEl->Increase_SegmentLength();
            //// Draw the new reduced edge in white with a tchickness = 10;
            //pEl->Draw(EdgeMask, 30, Scalar(0, 0, 0));
        }
    }
    // Merge the two mask with the input image
    //ApplyInversion(BarbMask, BarbMask);
    //ApplyMask(input, BarbMask);
    //ApplyMask(input, EdgeMask);
    //OutputMat = input.clone();   OutputMat = input.clone(); }

    BOOL CEdgeLace::IsBarb(float fLength) {
    //BOOL bCritera0 = FALSE;
    BOOL bCritera1 = FALSE;
    BOOL bResult = FALSE;
    // Test Length
    //if (m_fLength >= fLength && m_fLength>=0.0f) { bCritera0 = TRUE; }
    // Test Orientation angle
    if (m_fSlope_Degree >= -40.0f && m_fSlope_Degree <= 40.0f) { bCritera1
= TRUE; }
    // Validate Critera
    if (/*bCritera0 && */bCritera1) {bResult = TRUE;}

    return bResult; }

my goal is to remove the line between the red line on the enhanced contrast image below or retrieve the redline only if possible (i drawed the redline with paint, i must retrieve it on histogramm equalization image or on the original image itself):

original image my result

histogramm equalisation image : histogramm equalisation image

image ... (more)

edit retag flag offensive close merge delete

Comments

1

your question is still not clear! What do you want to remove? Please add minimum complete, reproducible code.

Balaji R gravatar imageBalaji R ( 2018-03-05 23:29:04 -0500 )edit