How to remove lines from captcha image which are acting as noise using java?

The images are attached here. I first converted the sample image to grayscale and then binarized it.

Finally i applied median filter to remove the dots from the image. However i am unable to remove the lines which are acting as noise in the image. Kindly help me out.

Original Image:

Processed Image:

• @ gabonator @Andrea :I could not implement dilation and erosion as I know the concept of it but I couldn't find the java code nor the algorithm which I can follow regarding this topic. I seriously need help and if someone can give me the complete code or the algorithm with which i can extract all the characters from the captcha image that would be wonderful. Also I could not comment as I do not have enough reputation. I tried implementing whatever you mentioned but it did not work for this case. Please help me out. – hdhj May 24 '18 at 5:21
• @hdhj This seems to be your question, but created using a different account. Please merge your accounts first. Then, please update this question with any new information you have that might help us to give you the sort of answer you are asking for. Please do not post a duplicate question again..... – Peter K. May 24 '18 at 12:43

I worked on this problem some time ago, my solution was to compress the image with wavelet transform with an opportune coefficient that depends on captcha type that I choose with some expermients. Then I saturate the compressed image from mean value to 0 and 1 in order to create a mask. Next I multiply mask to the original image and I get the image without lines or noise. I post a picture example where I use also a derivative filter on the result but in reality you don't need it.