Ask Your Question
0

Remove white noise between white horizontal line

asked 2019-02-20 08:39:06 -0600

updated 2019-02-20 08:58:31 -0600

I currently have an image with white horizontal lines. between those lines, there is some noise that I would like to remove. I've already done Morphological Opening on the original image and the current one.

image description

Does someone have an idea on how I could remove some of this noise between the lines?

original image: image description

Tom

edit retag flag offensive close merge delete

Comments

If you have threshold. Then increasing value between 50 to 127. Then another one is dilate and erode.If you could post orignal image.

supra56 gravatar imagesupra56 ( 2019-02-20 08:46:52 -0600 )edit

The current image uses dilate en erode and it does work as you could see the noise isn't that bad between the lines, I'm wondering if there is a way so I could remove the remaining noise between the lines

Tom_ColdenhoffVMT gravatar imageTom_ColdenhoffVMT ( 2019-02-20 08:51:06 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2019-04-20 10:04:52 -0600

supra56 gravatar image

updated 2019-04-20 13:40:55 -0600

There are 2 steps. In cv.GaussianBlur, You can change odd number btween 15 to 21, but not even numbers to suit our needed. Step 1:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)
img = cv.bitwise_not(gray)
adp_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,15,-2)

horizontal_inv = cv.bitwise_not(adp_thresh.copy())
masked = cv.bitwise_and(img, img, mask=horizontal_inv)

inv_masked = cv.bitwise_not(masked)
cv.imshow('Masked', inv_masked)
cv.imwrite('masked.jpg', inv_masked)
cv.waitKey(0)
cv.destroyAllWindows()

Output: block.jpg

Step 2:

#!/usr/bin/env python3
#OpenCV 4.0.1
#Date: 20th April, 2019

import cv2 as cv
import numpy as np

img = cv.imread('lines.jpg')
img=cv.cvtColor(img, cv.COLOR_BGR2GRAY)
gray = cv.GaussianBlur(img, (19, 19), 0)

img = cv.bitwise_not(gray)
adapt_thresh = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 15, -2)
cv.imshow('adapt_thresh', adp_thresh)
#cv.imwrite('adapt_thresh.jpg', adp_thresh=)
cv.waitKey(0)
cv.destroyAllWindows()

Output:

Adapt_thresh

edit flag offensive delete link more
0

answered 2019-02-20 08:55:29 -0600

kbarni gravatar image

updated 2019-02-20 09:01:27 -0600

Well, that's an ugly image!

I suggest to clean up the original (RGB) image, it's much easier than the binary image.

Try also to improve the binarization (e.g. work on HSV or LAB color space, use several channels, combine the RGB channels) to get a cleaner result. If you post the original image, you could get better ideas.

If you must work with the binary image, a directional diffusion (Perona&Malik method, ~~not part of OpenCV~~ correction: see below) could be a solution.

[EDIT] I was wrong, Perona-Malik is part of the Extended image processing module: cv::ximgproc::anisotropicDiffusion

edit flag offensive delete link more

Comments

Thank you for your reaction. I've also add the original image right now. I've to make the edges between the items on the stack clearer so that the edge recognition is able to see them better

Tom_ColdenhoffVMT gravatar imageTom_ColdenhoffVMT ( 2019-02-20 08:59:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-02-20 08:39:06 -0600

Seen: 1,690 times

Last updated: Apr 20 '19