1
$\begingroup$

I have a list of x- and y-values associated with a measured height (z-values). Part of the list is plotted below. As you can see, there is a periodic arranged structure, namely a cross. Now I would like to determine the distance (dx and dy) between neighboring characteristics of the crosses. Any hints how I could solve my problem?

To do so, first I was thinking to force Mma to search for a distinct characteristic within every cross (any outer corner, the center, whatever is usefull) But the dataset offers some roughness and I got stucked.

So determining the "mass center point" of each cross will be the best I guess. But again: any hints how to do that?

Thanks for any help!

enter image description here

EDIT

some example data are now provided, just download here

EDIT2

Thanks to Sjoerd C. de Vries, I made some more precise comments regarding the feature and the characteristic I'm looking for...

$\endgroup$
  • $\begingroup$ Difficult to say with no code and no data to play with... $\endgroup$ – MarcoB Apr 20 '16 at 17:10
  • $\begingroup$ true! data are now available... $\endgroup$ – Kay Apr 20 '16 at 17:49
6
$\begingroup$

This can be done using image processing like I did here.

Get the data:

data = Import["https://upload.uni-jena.de/data/5717c0b1b79268.74729920/data.dat"];

Convert to an image:

img = Image@ListDensityPlot[data, AspectRatio -> Automatic, PlotRange -> All, 
                                  ColorFunction -> "Rainbow", Frame -> False, 
                                  ImageSize -> 1200];

Interactively select the feature you're interested in:

pt = {ImageDimensions[img]/4, ImageDimensions[img]/2};
LocatorPane[
  Dynamic[pt], 
  Dynamic[
    Show[
      img, 
      Graphics[{EdgeForm[Black], FaceForm[], Rectangle @@ pt}]
    ]
  ], 
 Appearance -> Graphics[{Red, AbsolutePointSize[5], Point[{0, 0}]}]
]

Mathematica graphics

Find matching features:

res = ComponentMeasurements[
  MorphologicalComponents[
   ColorNegate[
    Binarize[
     ImageCorrelate[img, ImageTrim[img, pt], 
      NormalizedSquaredEuclideanDistance], 0.27]]], "Centroid"]

{1 -> {666.747, 964.006}, 2 -> {415.396, 886.665}, 3 -> {165.456, 807.965}, 4 -> {997.775, 788.42}, 5 -> {745.466, 709.964}, 6 -> {494.535, 631.51}, 7 -> {243.714, 554.783}, 8 -> {1075.23, 533.22}, 9 -> {824.081, 457.244}, 10 -> {569.194, 376.724}, 11 -> {901.547, 203.704}}

Show the results:

Show[img, 
 Graphics[{Green, FaceForm[], EdgeForm[Black], 
   Rectangle @@@ (TranslationTransform[# - Mean[pt]][pt] & /@ 
      res[[All, 2]])}]]

Mathematica graphics

Find the distances between all the features that were found:

Outer[EuclideanDistance, res[[All, 2]], res[[All, 2]], 1]
(* {{0., 262.981, 525.015, 374.713, 265.958, 374.447, 588.575, 593.661, 530.623, 595.329, 795.732}, 
    {262.981, 0., 262.037, 590.608, 374.392, 267.146, 373.658, 748.533, 592.812, 532.629, 838.319}, 
    {525.015, 262.037, 0., 832.548, 588.231, 373.402, 265., 950.352, 746.185, 590.739, 952.344}, 
    {374.713, 590.608, 832.548, 0., 264.225, 527.135, 789.427, 266.695, 373.961, 594.285, 592.581}, 
    {265.958, 374.392, 588.231, 264.225, 0., 262.91, 525.201, 374.141, 264.665, 376.989, 529.774}, 
    {374.447, 267.146, 373.402, 527.135, 262.91, 0., 262.294, 588.952, 372.786, 265.499, 590.488}, 
    {588.575, 373.658, 265., 789.427, 525.201, 262.294, 0., 831.794, 588.507, 371.002, 745.654}, 
    {593.661, 748.533, 950.352, 266.695, 374.141, 588.952, 831.794, 0., 262.387, 529.68, 372.486}, 
    {530.623, 592.812, 746.185, 373.961, 264.665, 372.786, 588.507, 262.387, 0., 267.303, 265.11}, 
    {595.329, 532.629, 590.739, 594.285, 376.989, 265.499, 371.002, 529.68, 267.303, 0., 374.692}, 
    {795.732, 838.319, 952.344, 592.581, 529.774, 590.488, 745.654, 372.486, 265.11, 374.692, 0.}} *)

Now you only need to convert these distances in image coordinates in the original coordinates...

$\endgroup$
  • $\begingroup$ Looks nice, I will definitely have a look on this. However, here I just selected a tiny amount of data for a MWE. Finally, I do not want to go over the data manually, but I was hoping for some sort of automatic algorithm. Looks like it isn't that simple though. $\endgroup$ – Kay Apr 20 '16 at 18:55
  • $\begingroup$ @kay Well, at least you need to define what makes up a feature, otherwise this problem seems underdetermined. $\endgroup$ – Sjoerd C. de Vries Apr 20 '16 at 18:59
  • $\begingroup$ As I wrote above, maybe: [...] determining the "mass center point" of each cross [...] but, that is just an example. In principle it can be any feature linked to the cross (any outer corner, the center, whatever, ...). Finally I want to know, if there are some artificial modulations on that (feature-)distances. Hope that was somehow clearer... $\endgroup$ – Kay Apr 20 '16 at 19:08
  • $\begingroup$ In your question you seemed to suggest that the cross was just an example of something to look for: "there are some periodic features (in this case a cross)". That was what I was referring to when I wrote "defining the feature". I wasn't referring to a characteristic of this feature (such as center or bounding box). $\endgroup$ – Sjoerd C. de Vries Apr 20 '16 at 19:15
  • $\begingroup$ Sorry for any missleading explanations from my side... I'm not a native speaker, as you might have guessed already. $\endgroup$ – Kay Apr 20 '16 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.