Hi Selva
please find attached script to straighten the small corrugations caused by small amount of pixels
1.
acquiring image
clear all; close all;
A=imread('031.jpg');
figure(1);imshow(A)
2.
amplifying image
d1=10
B2=imresize(A,d1);
figure(2);imshow(B2)
3.
binaryzing
B2=B2(:,:,1);
B3=imbinarize(B2);
figure(3);imshow(B3)
4.
capturing contour
B4=del2(double(B3));
figure(4);imshow(B4)
[x,y,v]=find(B4);
5.
directly amplifying and reducing with different pairs of factors doesn't work
6.
checking the points to process are all contour and only contour points
figure(4);hold all;plot(y,x,'g*')
d2=20;
x2=x([1:d2*d1:end]);y2=y([1:d2*d1:end]);
figure(4);hold all;plot(y2,x2,'r*')
P2=[x2,y2]'
Now all points are available in P2
7.
there is a problem encountered when attempting to directly apply golay or spline directly as explained in the following links respectively:
IA example has 2 wonderful scripts using spline and golay polynomials interpolation
.
such scripts assume points acquired consecutively, but it doesn't happen with all points of interest in this question
Following some of the curves obtained when attempting to directly apply spline or golay as shown in the link above
Adjacent points in variable to process are not necessarily nearest points measuring euclidean distance.
8.
Rearranging points according to proximity
P2c=P2;
s=1;p=1;
P3=P2c(:,s)
figure(4);plot(P3(2,end),P3(1,end),'bo');plot(P3(2,end),P3(1,end),'b*')
while length(P3)<length(P2)
D=zeros(1,length(P2c));
for s1=1:1:length(P2c)
D(s1)=((P2c(1,s1)-P3(1,end))^2+(P2c(2,s1)-P3(2,end))^2)^.5;
end
DL=D(s,:)
p=find(DL==min(nonzeros(DL)))
P3=[P3 P2c(:,p)]
if p==2
P2c(:,s)=[]
end
if p>2
P2c(:,s)=[]
LS=P2c(:,p-1)
P2c(:,p-1)=[]
P2c=[LS P2c]
end
end
figure(4);plot(P3(2,:),P3(1,:),'y','LineWidth',2)
figure(5);imshow(B4)
hold all; plot(P3(2,:),P3(1,:),'y','LineWidth',.7)
Now, without spline or higher order polynomials needed, just plot, it already shows straight edges.
d1=3 d2=20
.
.
.
.
Now one can use spline or golay polynomials interpolation, once the points have been ordered according to proximity.
Selva
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG