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

  • 2
    $\begingroup$ Can you post some pictures? You might want to try dilation with a square shaped structuring element followed by a thresholding. $\endgroup$ 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
    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
    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
    Jun 11, 2014 at 8:24
  • $\begingroup$ is your input image (or the characters) always axis aligned? $\endgroup$
    – Micka
    Jun 11, 2014 at 8:45

2 Answers 2


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::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::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);

        return 0;

with these results for given thresholds:


enter image description here


enter image description here


enter image description here


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


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.


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.