I have this image that I'd like to get the vertical and diagonal lines only. I use morphologyEx in OpenCV. However, the result I get doesn't meet up my requirement as I still these unwanted noises. Unfortunately, these noises have the same intensity as the lines, hence when I apply the Opening to get rid of the noise, the lines will also disappear. Can anyone please help me solve this problem?
int main() {
Mat dst, dst1, dst2, dst3;
Mat src = imread("cau3.png", IMREAD_GRAYSCALE);
imshow("source", src);
Mat kernel1 = getStructuringElement(MORPH_RECT, Size(45, 1), Point(-1, -1));
Mat kernel2 = getStructuringElement(MORPH_ELLIPSE, Size(11, 11), Point(-1, -1));
Mat kernel3 = getStructuringElement(MORPH_RECT, Size(21, 21), Point(-1, -1));
// Apply opening operation
morphologyEx(src, dst1, MORPH_OPEN, kernel1);
morphologyEx(src, dst2, MORPH_OPEN, kernel2);
morphologyEx(src, dst3, MORPH_OPEN, kernel3);
dst = src - (dst1 + dst2 + dst3);
imshow("Vertical and Diagonal lines with noise", dst);
waitKey(0);
return 0;
}
This is my original image:
This is my result image: