0
$\begingroup$

I have several Images of shape H, F, I, L.. which have curved corners. How do I process them to give sharp right-angled corners? I tried approximating them with inner rectangles, but this takes a LOT of time.. How do I proceed with it?

This is the sample Image. I want to process it such that I get rid of rounded corneres.

Sample Image

$\endgroup$
7
  • 2
    $\begingroup$ Can you post some pictures? You might want to try dilation with a square shaped structuring element followed by a thresholding. $\endgroup$ Commented Jun 10, 2014 at 14:16
  • $\begingroup$ I tried dilation and erosion, both on this and its inverted image, but I am not able to remove the inner corners, those rounded ones. you can see from the sample Image I have added. $\endgroup$
    – shreelock
    Commented Jun 11, 2014 at 5:23
  • $\begingroup$ did you try to use line detection (for example houghLinesP together with some heuristic to connect the detected lines? $\endgroup$
    – Micka
    Commented Jun 11, 2014 at 8:13
  • $\begingroup$ Houghlines won't work on the completely curved ends of T,H, etc. I was thinking of approximating the contours of each object with rectangles if different size, but that is too much time consuming. $\endgroup$
    – shreelock
    Commented Jun 11, 2014 at 8:24
  • $\begingroup$ is your input image (or the characters) always axis aligned? $\endgroup$
    – Micka
    Commented Jun 11, 2014 at 8:45

2 Answers 2

3
$\begingroup$

here's how houghLinesP would look like. Not a solution yet, but maybe you can work with that:

    int main()
    {

        cv::Mat image = cv::imread("SharpenCorners.jpg");

        cv::imshow("image", image);

        cv::Mat gray;
        cv::cvtColor(image,gray,CV_BGR2GRAY);

        cv::imshow("gray", gray);

        cv::Mat output; image.copyTo(output);

        // gradient:
        cv::Mat gx, gy;
        cv::Sobel(gray, gx, CV_32F, 1, 0, 3 );
        cv::Sobel(gray, gy, CV_32F, 0, 1, 3 );
        cv::Mat gm;
        cv::magnitude(gx,gy,gm);

        //cv::Mat g_thres = gray < 100;
        cv::Mat g_thres = gm > 100;

        //int lineThres = 5;    // 1st image
        //int lineThres = 10;// 2nd image
        //int lineThres = 25;// 3rd image
        int lineThres = 50;// 4th image

        std::vector<cv::Vec4i> lines;
        cv::HoughLinesP( g_thres, lines, 1, CV_PI/(4*180.0), lineThres, 10, 10 );

        for( size_t i = 0; i < lines.size(); i++ )
        {
            cv::line( output, cv::Point(lines[i][0], lines[i][1]),
                    cv::Point(lines[i][2], lines[i][3]), cv::Scalar(155,255,155), 2, 8 );
        }

        cv::imwrite("houghpSharpen4.png", output);
        cv::imshow("g thres", g_thres);
        cv::namedWindow("output"); cv::imshow("output", output);
        cv::waitKey(-1);

        return 0;
    }

with these results for given thresholds:

1st:

enter image description here

2nd:

enter image description here

3rd:

enter image description here

4th:

enter image description here

Additional idea:

Giving your own comment, that you might try to approximate each contour with rectangles, you could start with houghLinesP results (with a pretty high threshold to get at least all "long" line elements) and try to create the rectangles based on those lines

$\endgroup$
-1
$\begingroup$

It is easy to find the contour for each character. You can analyze the contour to find the points at the corners. Using one line to connect two adjacent points can produce right angle corners.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.