approximate derivative of array

1 次查看(过去 30 天)
Hey there, I have a profile of an edge region within an image that is in edge:(<1x29 uint32>). I have a second array of same type and length, that I want to store an approximate derivative in by subtracting each element with the following one (and disregarding the last element). The array produced does somehow only contain ones and twos and definately not what I am looking for. This might be easy, but I can't find it.
The loop I used was:
for i = 1:(xwidth)
lsf(i) = abs(edge((i+1)) - edge(i));
end
lsf(xwidth+1) = 0;
xwidth is the actual length minus one to not fall off the edge at the end. The iteration works so its not about the idizes.
Yurie

采纳的回答

Matt J
Matt J 2013-3-1
编辑:Matt J 2013-3-1
The DIFF command would be quicker than the for-loop, but the for loop should have worked and it's not clear (without seeing the contents of "edge") why lsf shouldn't contain ones and twos.
  3 个评论
Matt J
Matt J 2013-3-2
编辑:Matt J 2013-3-2
Make sure that you convert edge to double first
hhist=diff(double(edge))
Otherwise, hhist will also be uint32 and won't be able to assume negative values. From your plots, though, the positive values of hhist look plausible, i.e., we can't tell from the plots that the positive transitions in edge are actually ever greater than 2.
Yurie Breschnef
Yurie Breschnef 2013-3-4
In the middle of it there has to be one peak in the derivative. I checked and it was not there, otherwise yes the noise is not higher than +-2. I tried to convert to double first and that works fine. Thanks!

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by