# How to proceess Image with curved corners and edges to give sharp Corners?

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.

• Can you post some pictures? You might want to try dilation with a square shaped structuring element followed by a thresholding. – geometrikal Jun 10 '14 at 14:16
• 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. – shreelock Jun 11 '14 at 5:23
• did you try to use line detection (for example houghLinesP together with some heuristic to connect the detected lines? – Micka Jun 11 '14 at 8:13
• 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. – shreelock Jun 11 '14 at 8:24
• is your input image (or the characters) always axis aligned? – Micka Jun 11 '14 at 8:45

## 2 Answers

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:

2nd:

3rd:

4th:

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.