How to calculate local maximum point from a derivative of a function?

Hi. I am working with border irregularity of lesion. So I have determined the derivative of the border irregularity function to get the local maximums.We know the local maximum is detected when the derivative of the function crosses the zero point and the slope changes sign from + to −. I want to divide the curve in 8 region and count the abrupt cut off in every region so that I can have the final decision.
I found out upto this:
And what I wanted is to point out the local maximums like this and count the abrupt cut off in each region:

 Accepted Answer

TRY THIS SIMPLE EXAMPLE
x = 1:50;
y = sin(x);
[xc,yc] = polyxpoly(x,y,[0 50],[0 0]);
plot(x,y)
hold on
for i = 1:3
ix = 15*(i-1) < xc & xc < 15*i;
plot(xc(ix),yc(ix),'*','color',rand(1,3))
end
hold off

14 Comments

I don't understand the code.
My code is like this:
figure
plot(distance)
I=imgaussfilt(distance,15);
figure
plot(I)
j=diff(I);
figure
plot(j)
I have used your code but got no output that means there was no change in the curve:
j=diff(I);
figure
plot(j)
z=1:length(j);
[xc,yc] = polyxpoly(z,j,[0 4000],[0 0]);
hold on
for i = 1:3
ix = 15*(i-1) < xc & xc < 15*i;
plot(xc(ix),yc(ix),'*','color',rand(1,3))
end
hold off
Here I have attached the matfile and image.
Try this
z=1:length(distance);
[xc,yc] = polyxpoly(z,distance,[0 4000],[0 0]+20);
hold on
for i = 1:4
ix = 1000*(i-1) < xc & xc < 1000*i;
plot(xc(ix),yc(ix),'*','color',rand(1,3))
end
hold off
Thank you very much! It has worked!
I have a question. You have given the code for finding point for this image:
If I want the same for this image what should I write?
where there is a problem that in previous picture for consequent positive and negative number there was a zero crossing. So from your code,it was easy to detect them. But now there are only points,not a curve.So how can I detect the zero crossing?
Here are coordinates of crossing zero points:
x = 1 2 3 4 5 6 7 8
But when I used this,it didn't work. There is an error saying- ''Function POLYXPOLY expected its first and second input arguments, X1 and Y1, to match in size or NaN locations''
I have written this:
z=1:length(iwant');
[xc,yc] = polyxpoly(z,iwant',[1 8],[0 0]);
hold on
for i = 1:8
ix = 1*(i-1) < xc & xc < 1*i;
plot(xc(ix),yc(ix),'*','color',rand(1,3))
end
hold off
iwant' is this:
Why do you need intersections of the points you already know? It's pretty obvious that intersections are: 1 2 3...
You can plot them easily
x = 1:5;
plot(x,x*0,'or')
And like I asked in my answer, why do you even need the derivatives at all, since you can simply find the maxima more directly with imregionalmax() or findpeaks(), rather than taking the derivative and seeing where the derivative (slope) is zero?
darova
Earlier you have helped me to find out the intersection point of the curve with the positive x axis. Then I had to divide the curve in 8 region and find if minimum one intersection point is there and if so then I would count the region of value 1 otherwise 0. But after finding the intersection points,I couldn't divide it. So I am trying after interchanging the steps. That I have divided the points and now I want the intersection point.
As in my image you can see that there are 2 regions(1 and 8) where no zero crossing is happened.So its value will be 6:
Image Analyst
I have used findpeaks but it gave me both maxima and minima.

Sign in to comment.

More Answers (1)

Why not simply call imregionalmax()?
You can smooth the data with a sliding quadratic if you want to before that with sgolayfilt().

3 Comments

Actually I wanted the the zero crossings.Thats why.
You wanted the zero crossings of the derivative, because you want to know where the maxima (peaks) are, and the derivative is zero when the signal is at a max and the slope is zero. But if you simply use imregionalmax() you don't need to even deal with the derivative at all. It's much simpler and more direct.
Image Analyst
I understood your point. I have tried it but failed. See I have got this:
form this after dividing the points into 8 region:
Now if I want the local maxima from the first image what should I do?
My code is given below:
figure
plot(distance)
I=imgaussfilt(distance,20);
figure
plot(I)
n = 8 ;
d=I';
a=length(I);
% check whether data needed to be appended to reshape into n
b = n * ceil(a / n)-a ;
%
d = [d NaN(1,b)] ;
iwant = reshape(d,[],n);
% plot
figure
plot(iwant','b*')

Sign in to comment.

Categories

Asked:

on 9 Jun 2020

Edited:

on 9 Jul 2020

Community Treasure Hunt

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

Start Hunting!