I want to remove the noise of the image and also filled all the shape in black (show as rectangle). This is the orignal image original image. As it can be see, there is a lot of noise outlines of the rectangle shape. To remove noise I tried the following
//This image is the original
Mat imgRaw = new Mat(new OpenCvSharp.Size(opencv_image_x, opencv_image_y), MatType.CV_8UC3, Scalar.White);
Mat imgt1 = new Mat(new OpenCvSharp.Size(opencv_image_x, opencv_image_y), MatType.CV_8UC1, Scalar.White);
Mat imgt2 = new Mat(new OpenCvSharp.Size(opencv_image_x, opencv_image_y), MatType.CV_8UC1, Scalar.White);
Mat kernel2 = new Mat();
kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(5, 5));
Cv2.MorphologyEx(imgRaw3, imgt1, MorphTypes.Erode, kernel);
Cv2.CvtColor(imgt1, image_grayC, ColorConversionCodes.BGR2GRAY);
Cv2.ImWrite("Erode.jpg", imgRaw3);
Cv2.MorphologyEx(imgRaw3, imgt2, MorphTypes.Dilate, kernel);
Cv2.ImWrite("dilate.jpg", imgRaw3);
Then as a result I got this erode+dilate. Some of the noise appear to be gone, at the begginig left of the image there are lines that can be considering as noise too. how It can be removed?
How can I join all the vertical lines, in order to filled the rectangle as this? fullfilled example
I tried dilating the image, but not works as it should be, any other method, or way to accomplish this