Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing outliers from a grey-scale image

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

like image 381
Atcold Avatar asked Apr 04 '13 23:04

Atcold


People also ask

What is the best way to remove outliers?

When you decide to remove outliers, document the excluded data points and explain your reasoning. You must be able to attribute a specific cause for removing outliers. Another approach is to perform the analysis with and without these observations and discuss the differences.

Does removing outliers increase accuracy?

The outlier detection and removal method reduced the variance of the training data. Test accuracy was improved from 63% to 76%, matching the accuracy of clinical judgment of expert burn surgeons, the current gold standard in burn injury assessment.

Should I remove outliers before classification?

It's best to remove outliers only when you have a sound reason for doing so. Some outliers represent natural variations in the population, and they should be left as is in your dataset.


3 Answers

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!

like image 87
tmpearce Avatar answered Sep 26 '22 07:09

tmpearce


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

like image 27
JustinBlaber Avatar answered Sep 25 '22 07:09

JustinBlaber


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

like image 42
Darkmoor Avatar answered Sep 26 '22 07:09

Darkmoor