2

I have the following image, in which every pixel is the result of another segmentation algorithm. There are 3 classes here, but in theory there could be more.

enter image description here

I would like to remove the noise, meaning I want to get nice straight lines, and clean areas.

I thought about doing something similar to knn, meaning:

Each pixel will get the most popular vote by its neighbors (at some radius)

I could program this easily with for loops, but was wondering if anything like this can be done with numpy?


If there is a better way to do this, I would love to hear it.

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • You might find useful https://scikit-image.org/docs/0.14.x/auto_examples/filters/plot_denoise.html – yatu Jun 05 '20 at 21:36
  • 1
    For the majority vote implementation, here's an example use case https://stackoverflow.com/questions/61197364/smoothing-a-2-d-numpy-array-with-a-kernel/61197888#61197888 – yatu Jun 05 '20 at 21:37
  • Have you tried a bilateral filter? https://uk.mathworks.com/help/images/ref/imbilatfilt.html – Mark Setchell Jun 05 '20 at 21:57
  • @MarkSetchell Why is a bilateral filter a good choice here? Asking because this is the 1st time I hear about it – Gulzar Jun 06 '20 at 07:31
  • It's an edge-preserving, noise-reducing filter which is what I perceive to be what you need. I may be wrong... I have been before! I haven't tried it on your image, hence I just made a comment rather than a full abswer. – Mark Setchell Jun 06 '20 at 07:40
  • Have you considered using morphological transformations such as opening/closing? They do require binary images, but i think your endeavour would greatly benefit if you used some form of erosion... Another idea would be to use a median blur, but since you didn't include the original image i can't verify that. – code-lukas Jun 10 '20 at 09:43
  • @code-lukas This result is already after the median blur on the original image. opening didn't do the trick with several parameters. I thought of maybe using some hough-like voting method to keep in a class only pixels that are on enough lines containing that class. This does seem a bit complicated though. – Gulzar Jun 10 '20 at 10:04

0 Answers0