I have interference images, and I have to calculate the visibility. For this I have to find the minimum and the maximum values of the intensity "oscillations".
我有干涉图像,我必须计算可见度。为此,我必须找到强度“振荡”的最小值和最大值。
I've already found the maximums with the FindPeaks function, but I don't know how to find the minimums.
我已经找到FindPeaks函数的最大值,但我不知道如何找到最小值。
img = Import["/home/martin/Dokumentumok/Egyetem/4. félév/Modern fizika labor/15. Kvantumradír/Képek/1a.JPG"];
dat = ParallelSum[ImageData[img, "Byte"][[n]], {n, 3456}];
peaks = N[FindPeaks[dat, 1.2, 1.2, 90000]];
Show[{ListLinePlot[dat, AxesLabel -> {"Pixel", "Intenzitas"},ImageSize -> Full, PlotTheme -> "Classic"], ListPlot[Tooltip[peaks], PlotStyle -> {PointSize[0.006], Red}]}]
If I hover over the red dots, it shows the intensity value, and the position. It would be very good, if I could do the same thing with the minimum values, but unfortunately I can't find a function like FindPeaks.
如果我将鼠标悬停在红点上,则会显示强度值和位置。如果我能用最小值做同样的事情,那将是非常好的,但不幸的是我找不到像FindPeaks这样的函数。
Is there any way to do this?
有没有办法做到这一点?
1 个解决方案
#1
An old trick used to find the minimum is to find the max of -1 times the data.
用于找到最小值的旧技巧是找到数据的最大值-1倍。
data = {1, 3, 1, 3};FindPeaks[data]
which gives
{{2, 3}, {4, 3}}
To get the minimum use negate the data
为了最小化使用否定数据
FindPeaks[-data]
which gives
{{1, -1}, {3, -1}}
The x position is correct, but the y is negated. So multiply -1 times those y values.
x位置是正确的,但y被否定。因此,将这些y值乘以-1倍。
Map[({x, y} = #; {x, -y}) &, FindPeaks[-data]]
which gives
{{1, 1}, {3, 1}}
Note: That # and & is a Mathematica shorthand for defining a tiny little function with argument named #. For new users that can be a little confusing, but once understood it is quick to write and simple to use.
注意:#和&是Mathematica的简写,用于定义一个名为#的参数的小函数。对于可能有点混乱的新用户,但一旦理解,它编写起来快速且易于使用。
#1
An old trick used to find the minimum is to find the max of -1 times the data.
用于找到最小值的旧技巧是找到数据的最大值-1倍。
data = {1, 3, 1, 3};FindPeaks[data]
which gives
{{2, 3}, {4, 3}}
To get the minimum use negate the data
为了最小化使用否定数据
FindPeaks[-data]
which gives
{{1, -1}, {3, -1}}
The x position is correct, but the y is negated. So multiply -1 times those y values.
x位置是正确的,但y被否定。因此,将这些y值乘以-1倍。
Map[({x, y} = #; {x, -y}) &, FindPeaks[-data]]
which gives
{{1, 1}, {3, 1}}
Note: That # and & is a Mathematica shorthand for defining a tiny little function with argument named #. For new users that can be a little confusing, but once understood it is quick to write and simple to use.
注意:#和&是Mathematica的简写,用于定义一个名为#的参数的小函数。对于可能有点混乱的新用户,但一旦理解,它编写起来快速且易于使用。