ViktorG
ViktorG

Reputation: 515

Remove outliers in an image after applying treshold

Here`s the deal. I want to create a mask that visualizes all the changes between two images (GeoTiffs which are converted to 2D numpy arrays).

For that I simply subtract the pixel values and normalize the absolute value of the subtraction:

Formula

Since the result will be covered in noise, I use a treshold and remove all pixels with a value below a certain limit.

def treshold(array, thresholdLimit):
      print("Treshold...")
      result = (array > thresholdLimit) * array
      return result

This works without a problem. Now comes the issue. When applying the treshold, outliers remain, which is not intended:

enter image description here

What is a good way to remove those outliers? Sometimes the outliers are small chunks of pixels, like 5-6 pixels together, how could those be removed?

Additionally, the images I use are about 10000x10000 pixels.

I would appreciate all advice!

EDIT:

Both images are landsat satelite images, covering the exact same area. The difference here is that one image shows cloud coverage and the other one is free of clouds. The bright snakey line in the top right is part of a river that has been covered by a cloud. Since water bodies like the ocean or rivers are depicted black in those images, the difference between the bright cloud and the dark river results in the river showing a high degree of change.

I hope the following images make this clear:

Source tiffs : enter image description here enter image description here

Subtraction result: enter image description here

I also tried to smooth the result of the tresholding by using a median filter but the result was still covered in outliers:

from scipy.ndimage import median_filter

def filter(array, limit):
        print("Median-Filter...")
        filteredImg = np.array(median_filter(array, size=limit)).astype(np.float32)
        return filteredImg

Upvotes: 0

Views: 2938

Answers (1)

Florian Drawitsch
Florian Drawitsch

Reputation: 715

I would suggest the following:

  1. Before proceeding please double check if the two images are 100% registered. To check that you should overlay them using e.g. different color channels. Even minimal registration errors can render your task impossible
  2. Smooth both input images slightly (before the subtraction). For that I would suggest you use standard implementations. Play around with the filter parameters to find an acceptable compromise between smoothness (or reduction of graininess of source image 1) and resolution
  3. Then try to match the image statistics by applying histogram normalization, using the histogram of image 2 as a target for the histogram of image 1. For this you can also use e.g. the OpenCV implementation
  4. Subtract the images
  5. If you then still observe obvious noise, look at the histogram of the subtraction result and see if you can relate the noise to intensity outliers. If you can clearly separate signal and noise based on intensity, apply again a thresholding (informed by your histogram). Alternatively (or additionally), if the noise is structurally different from your signal (e.g. clustered), you could look into morphological operations to remove it.

Upvotes: 0

Related Questions