approximate derivative of array

1 view (last 30 days)
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

Accepted Answer

Matt J
Matt J on 1 Mar 2013
Edited: Matt J on 1 Mar 2013
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 Comments
Matt J
Matt J on 2 Mar 2013
Edited: Matt J on 2 Mar 2013
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 on 4 Mar 2013
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!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!