Removing outliers from a grey-scale image
Asked Answered
A

3

5

Question

I have an images sequence representing depth information which I'd like to clean. There are some outliers (values with intensity below 25, for a 0-255 range) which I would like to be filled with an acceptable alternative (an average value localised to that specific area could be a good guess).

Can someone see a simple way to do this? I've tried to use a median filter (filter size of 10) substituting the undesired values with NaN, but it did worsen the situation, which improves instead by substituting them with a general average value.

Basic trial

P.S. Someone has already suggested me to use a fast wavelet reconstruction, but I would not really know where to start...

Implemented solution (so far)

The solution I implemented (before reading about inpaint_nans suggested by tmpearce) is:

  1. duplicate the original image;
  2. filling the invalid pixels with a general average value;
  3. use a circular disk of ray 10 for blurring it;
  4. replacing the invalid values in the original image with what I got from point 3.
  5. run a median filter of size 10.
img2 = img;                                       
img2(img < .005) = mean(img(:));                  
H = fspecial('disk',10);                          
img3 = imfilter(img2,H,'symmetric');              
img4 = img;                                       
img4(img < .3) = img3(img < .3);                  
filterSize = 10;                                  
padopt = {'zeros','indexed','symmetric'};         
IMG = medfilt2(img4, [1 1]*filterSize, padopt{p});

Second trial

Aeriel answered 4/4, 2013 at 23:30 Comment(0)
R
7

I recommend the inpaint_nans contribution from the MATLAB File Exchange - start as you've already done by replacing outliers with NaN and use the link to go from there.

From the description of the function:

Interpolate NaN elements in a 2-d array using non-NaN elements. Can also extrapolate, as it does not use a triangulation of the data. Inpaint_nans offers several different approaches to the interpolation, which give tradeoffs in accuracy versus speed and memory required. All the methods currently found in inpaint_nans are based on sparse linear algebra and PDE discretizations. In essence, a PDE is solved to be consistent with the information supplied.

Hooray for reusable code!

Racketeer answered 4/4, 2013 at 23:56 Comment(1)
my thoughts exactly, only 20 seconds too late. +1Luca
S
4

Use a function called roifill. You need to mess with it a little bit. I had to use imdilate because it interpolates from the boundary.

Code:

testimage = imread('BAPz5.png');
testimage = double(rgb2gray(testimage));
testimage_filt = roifill(testimage,imdilate(testimage<100,true(4)));
figure(1);
subplot(1,2,1);
imshow(testimage,[]);
subplot(1,2,2);
imshow(testimage_filt,[]);

Output:

enter image description here

Sidedress answered 5/4, 2013 at 0:35 Comment(0)
B
1

The post is answered but just for the record, in [1], the author based on a basic principle of natural shapes, i.e., the objects follow a second order smoothness, he suggests an in-painting method that minimize curvature in a least-squares sense. He also offers code. Good luck.

[1] Α Categoty-Level 3-D Object Database: Putting the kineckto Work (ICCV)

enter image description here

Broadcloth answered 25/12, 2013 at 13:25 Comment(2)
Note that link-only answers are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference.Nilsanilsen
This is awesome! Thanks Darkmoor for your note! It's always nice to get someone else opinion, supported by a paper!Aeriel

© 2022 - 2024 — McMap. All rights reserved.