approximate derivative of array

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일

0 개 추천

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

Yurie Breschnef
Yurie Breschnef 2013년 3월 2일
편집: Yurie Breschnef 2013년 3월 2일
I tried the diff() and if I used it with manualy defined arrays it does exactly what I want. It does not however with the profile that I have stored in the array edge. It confuses me deeply because they were of the same data type.
for x = 1:((xwidth+1)) %filling histogram array
hhist(x) = (255 - I(ymin,(xmin+(x-1))));%retrieving the NEGATIVE (255-I(y,x))
end
edge = hhist; % It works until here. edge is fine.
hhist = diff(edge);
Can I upload .mat files somehow so that people can have a look into it? Here is the screenshot of my problem. The left plot is the edge, and the right should be the approx. derivative.
Thanks in advance!
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개)

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by