# Detecting meandering rivers in images

I have $n$ surfaces: $z_i(x,y)$ with a measured attribute (variable) on each surface: $a_i(x,y)$. Most of the surfaces will have a random distribution of the attribute across the surface, but some surfaces (the interesting ones) will show a meandering river pattern: I need your help in coming up with a measure that will tell us which of the $n$ surfaces are most likely to have such a pattern.

There are many possible maps with the same histogram as shown below; so the measure needs to "reward" spatial continuity. To illustrate this I have created a random image with nearly the same histogram as the river image: So image statistics ala entropy may only be part of the solution.

Here is an example of an image without a meandering river pattern: My images are synthetic (made in Matlab). In real life the image without the pattern may have somewhat more spatial continuity in the form of small blobs of similar value.

Here are the images in grayscale:  • Can you post actual images (without axis, palette, histogram, so we can try different algorithms?). Also: Is the "meandering river" actually a sine, or can it have any shape? – Niki Estner Jun 1 '12 at 9:28
• Hi nikie. In my example (synthetic data made in Matlab) the river is a sine. In real life it is "sine like"; sometimes it goes wide from the centerline, sometimes not. – Andy Jun 1 '12 at 11:17

## 2 Answers

A very simple measure would be to compare each row in the image with the row above it, allowing some horizontal shift.

I've hacked together this simple algorithm in Mathematica:

Mean[MapThread[
Function[{line1, line2},
Min[Table[Norm[line1 - RotateLeft[line2, shift]], {shift, -5, 5}]]
], {s[[2 ;;]], s[[;; -2]]}]]


It simply takes each pair of adjacent rows, rotates one of the rows by -5..5 pixels, and takes the smallest euclidean distance. This yields one euclidean distance for each row pair. I simply take the mean (but depending on your actual data, a truncated mean or median might be more robust).

These are the results I get for artificially generated samples (Formula: Normalize(random noise * (1-factor) + signal * factor)) If I plot the result against the signal strength, the algorithm seems to measure the "meandering river signal strength" quite well: EDIT: I forgot to normalize the input samples. Fixed that an uploaded new result images

• Good answer. However, I think that your measure can be fooled by another continuous curves, like straight line. I would improve that a little bit by changing the last step to fitting a sine to the (x,y) points you've found, with some amplitude, phase and frequency. Then, the amplitude can serve as measurement to "river strength". – Andrey Rubshtein Oct 6 '12 at 10:58

You seem to be on the right track with that histogram. If this is a representative image from your sample then that histogram shows that the images where the meandering pattern is present could be detected just by examining if they contain values above a certain threshold.

Other than this, you can try obtaining the entropy of each image. That will give you one number per image that characterises its randomness. After that you can obtain a histogram of the entropies of your images. If you are sure that the images are distinctly divided into "totally-random" and "random-with-a-meander" (i.e. less random), then the histogram of the entropies will be bimodal. The left mode will correspond to images with lower entropy and therefore less randomness (more likely to contain a meandering pattern) and vice versa for the right mode.

(BTW MATLAB includes a relevant function)

EDIT: As a response to the OP comments and subsequent uploading of more information about the problem, here is an additional point to this answer:

Entropy would still work but not the plain simple memory-less case described by Shannon's formula (where each sample of a time series is assumed to be independent of the previous ones).

As a simpler alternative then you could try examining features of the image's autocorrelation.

• Hi A_A. I think image statistics is part of the solution but one needs to weight in the neighbour pixels somehow to reward spatial continuity (see the Map of random attribute above). – Andy Jun 1 '12 at 11:24
• Hello, i agree and have augmented the answer. – A_A Jun 1 '12 at 11:51