Skip to main content

image processing - Measure a DensityHistogram[] pair similarity


I study human vision and more specifically eye-movements.


"If we display 2 symmetrical patterns (20 min one after the other), will our gaze distribution be symmetric is my research question."



The 2 figures at the bottom row below is what is displayed to subjects for 3 seconds. One pattern, then, later in the experiment, its symmetrical transform.


Above are their respective Gaze Density histograms. That is the distribution of where their eyes were while observing the stimuli. The Blue square is the Center Of Gravity of the stimuli.


How can I measure their similarity ? If I have some ideas, I think Mathematica offers great means of image analysis that could be used here.


enter image description here


You could find here the data : allSymFix : 93 sublist for the 93 stimuli pairs I present, along with a manipulate to see all the histograms


allSymFix[[1,1]] are all the gaze observed on stimuli 1 original version.
allSymFix[[1,2]] on its symmetrical transform


enter image description here


How can I measure the similarity within each allSymFix[[original stimuli]].


I will then compare it with the similarity computed on random pairs assembled




Answer



We'll use SmoothKernelDistribution. Correlated pair with left data set reflected around y-axis:


lefTimagE = SmoothKernelDistribution[{-1, 1} # & /@ allSymFix[[3, 1]]];
righTimagE = SmoothKernelDistribution[allSymFix[[3, 2]]];

Visualize in 3D:


  Row@Plot3D[Evaluate[#], {x, -13, 13}, {y, -13, 13}, PlotRange -> All,
MeshFunctions -> {#3 &}, Mesh -> 15, PlotPoints -> 50] & /@
{PDF[lefTimagE, {x, y}], PDF[lefTimagE, {x, y}] PDF[righTimagE, {x, y}],
PDF[righTimagE, {x, y}]}


enter image description here


The middle is overlap - notice small values. Integrate to find total characteristic


NIntegrate[Evaluate[PDF[lefTimagE, {x, y}] PDF[righTimagE, {x, y}]], 
{x, -13, 13}, {y, -13, 13}, Method -> "AdaptiveMonteCarlo"]

Answer: 0.00549086


Random pair:


lefTimagE = SmoothKernelDistribution[{-1, 1} # & /@ allSymFix[[3, 1]]];
righTimagE = SmoothKernelDistribution[allSymFix[[15, 2]]];


Visualize in 2D this time for verity:


Row@ContourPlot[Evaluate[#], {x, -13, 13}, {y, -13, 13},PlotRange -> All, 
Mesh -> 15, PlotPoints -> 50] & /@ {PDF[lefTimagE, {x, y}], PDF[lefTimagE,
{x, y}] PDF[righTimagE, {x, y}], PDF[righTimagE, {x, y}]}

enter image description here


The middle is overlap. Integrate to find total characteristic


NIntegrate[Evaluate[PDF[lefTimagE, {x, y}] PDF[righTimagE, {x, y}]], 
{x, -13, 13}, {y, -13, 13}, Method -> "AdaptiveMonteCarlo"]


Answer: 0.0038788


I liked Andy's analysis of the whole set for his metric. I ran it for my integral metric too:


Correlated pairs:


coRdaT = Table[NIntegrate[Evaluate[PDF[SmoothKernelDistribution[{-1, 1} 
# & /@ allSymFix[[k, 1]]], {x, y}] PDF[SmoothKernelDistribution[
allSymFix[[k, 2]]], {x, y}]], {x, -13,13}, {y, -13, 13},
Method -> "AdaptiveMonteCarlo"] , {k, 1, 93}];

Random pairs:



uNcoRdaT = Table[NIntegrate[Evaluate[PDF[SmoothKernelDistribution[{-1, 1} 
# & /@ allSymFix[[k, 1]]], {x, y}] PDF[SmoothKernelDistribution[
allSymFix[[RandomInteger[{1, 93}], 2]]], {x, y}]], {x, -13, 13},
{y, -13, 13}, Method -> "AdaptiveMonteCarlo"] , {k, 1, 93}];

Analysis:


SmoothHistogram[{coRdaT, uNcoRdaT}, Filling -> Axis, 
PlotStyle -> {{Thick, Blue}, {Thick, Red}}]

enter image description here



Conclusion: on average integral of overlap for correlated pairs almost order of magnitude greater than for random pairs.


======= ARCHIVE: less reliable, needs-polishing approach =======


Here is a very simple take on this. If my understanding is correct, @500 wishes to see spatial correlation between left and right 2D patterns. I'll use SmoothDensityHistogram because it IMO gives better data representation in this case, but you can use your original approach too. The idea is to use ImageMultiply to "amplify" overlapping regions. Midle image is the overlap for a specific set of your data. Note it was ImageAdjust-ed for better visual perception. As numeric measure you have red number (computed before ImageAdjust for uniform scale) The red number is total "intensity" of overlap which could be some sort of correlation measure. BTW we also need to reflect one of the images around vertical axis, otherwise overlap will be meaningless. Here is correlated pair - data set 3, left and right images. As you can see the red number is high and the overlap does look like originals.


ili = SmoothDensityHistogram[#, Background -> Black, 
ColorFunction -> GrayLevel, ImageSize -> 300,
PlotRange -> {{-13, 13}, {-13, 13}}, ImagePadding -> 0,
ImageMargins -> 0, PlotRangePadding -> 0, Mesh -> 0] & /@
allSymFix[[3]];
il = {ImageReflect[ili[[1]], Left -> Right], ili[[2]]};
Framed@Labeled[GraphicsRow[Riffle[il, (cori =

ColorConvert[ImageMultiply @@ il, "Grayscale"]) //
ImageAdjust], Spacings -> 1], ImageData[cori] // Total // Total,
Top, LabelStyle -> Directive[Red, Bold, 20]]

enter image description here


And here is random pairing of set 3 left image and set 15 right image. As you can see the red number is much less and the overlap does not look like originals.


ili = SmoothDensityHistogram[#, Background -> Black, 
ColorFunction -> GrayLevel, ImageSize -> 300,
PlotRange -> {{-13, 13}, {-13, 13}}, ImagePadding -> 0,
ImageMargins -> 0, PlotRangePadding -> 0,

Mesh -> 0] & /@ {allSymFix[[3, 1]], allSymFix[[15, 2]]};
il = {ImageReflect[ili[[1]], Left -> Right], ili[[2]]};
Framed@Labeled[GraphicsRow[Riffle[il, (cori =
ColorConvert[ImageMultiply @@ il, "Grayscale"]) //
ImageAdjust], Spacings -> 1], ImageData[cori] // Total // Total,
Top, LabelStyle -> Directive[Red, Bold, 20]]

enter image description here


A word of caution: Andy's good comment made me realize there are a few things to worry about here. Most impotently, in most cases our graphics resales the data before it passes them to ColorFunction. This means that for these different data sets their maximums will look same bright on the plots:


Max /@ {allSymFix[[3, 1]], allSymFix[[15, 2]]}

*Answer:* {10.466, 11.172}

This affects correct overlap estimates.


Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

equation solving - Invert and fit implicitly defined curve

I need to fit an implicitly defined curve. I thought I could get some data out of Solve , and then using FindFit . Therefore, I would like to find the relation the parametric curve defined by $F(x,y)=0$: Solve[-(1/2) + 1/2 (0.41202 BesselK[0, 0.1 Sqrt[x^2 + y^2]] + (0.101483 x BesselK[1, 0.1 Sqrt[x^2 + y^2]])/Sqrt[x^2 + y^2]) == 0, y] But I can't get an output: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >> Edit: In particular, I would like to fit the data coming from the curve with the expression of another curve, and not with a function $f(x)$. In particular, since this clearly looks like a cardioid , I would like it to fit to something like it. What other strategies could I try?

dynamic - How can I make a clickable ArrayPlot that returns input?

I would like to create a dynamic ArrayPlot so that the rectangles, when clicked, provide the input. Can I use ArrayPlot for this? Or is there something else I should have to use? Answer ArrayPlot is much more than just a simple array like Grid : it represents a ranged 2D dataset, and its visualization can be finetuned by options like DataReversed and DataRange . These features make it quite complicated to reproduce the same layout and order with Grid . Here I offer AnnotatedArrayPlot which comes in handy when your dataset is more than just a flat 2D array. The dynamic interface allows highlighting individual cells and possibly interacting with them. AnnotatedArrayPlot works the same way as ArrayPlot and accepts the same options plus Enabled , HighlightCoordinates , HighlightStyle and HighlightElementFunction . data = {{Missing["HasSomeMoreData"], GrayLevel[ 1], {RGBColor[0, 1, 1], RGBColor[0, 0, 1], GrayLevel[1]}, RGBColor[0, 1, 0]}, {GrayLevel[0], GrayLevel...