How to eliminate noise in an image?

Asked

Viewed 376 times

2

In relation to the image presented, I want to leave only visible the main trunk and the (secondary) branches of the plant (tomato).

Tomateiro

Depending on my attempts, what seems to me to give more encouraging results is the reduction of the image area, followed by the application of the Canny edge detector.

But there’s still a lot of what I think you might call noise. If I can eliminate those many small white "spots" (noise), I would be practically only with the shapes (edges) of the branches of the plant as intended.

What’s the best way to do that?

Code:

import numpy as np 
import cv2

imagem = cv2.imread("tomat.jpg")

print(imagem.shape)

for y in range(0, 360):
   for x in range(0, 120):
       imagem[y, x] = (0,0,0)

for y in range(0, 360):
   for x in range(250, 480):
       imagem[y, x] = (0,0,0)

gris = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY)     

# Aplicar suavizado Gaussiano
gauss = cv2.GaussianBlur(gris, (5,5), 0)

# Detectamos los bordes con Canny
canny = cv2.Canny(gauss, 50, 150)

cv2.imshow("canny", canny)
cv2.waitKey(0)
  • opencv has a function called normalize I use it in facial recognition and solved much of the problem

  • You don’t just want to "eliminate the noise". You need to pass the image through several stages so that at the end, you have in prominence, the characteristics that interest you. The best is to read some theoretical text, or a course on image processing, and in the study you discover the sequence of filters that will be more interesting to apply to get to where you want.

  • Alternatively, you can open an image editor with a graphical interface, like GIMP, and see, if through interactive manipulations with multiple filters, you can separate only what interests you- then annotate the steps, and write a script that does this, calling the same filters.

1 answer

1

Opencv provides 4 techniques to remove noise, one of which is the function cv.fastNlMeansDenoisingColored().

The parameters are: (original,destino,7,21,h,hColor), in which h is the parameter that regulates the filter, large values of h remove the noise well, but the image loses detail. For the hColor is the same idea as h.

imagem_dst = cv2.fastNlMeansDenoisingColored(imagem,None,7,21,7,21)
cv2.imshow("Teste",imagem_dst)

You can better see the parameters here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.