Can anyone please help me with this code, this should correct a skewed image using principal component analysis. The output image somehow corrected but it is not perfect because it still have a small skew
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
clear;
img = imread('test3.jpg');
if length(size(img))>2
img = rgb2gray(img);
end
%applying sobel edge detector in the horizontal direction
fx = [-1 0 1;-1 0 1;-1 0 1];
Ix = filter2(fx,img);
% applying sobel edge detector in the vertical direction
fy = [1 1 1;0 0 0;-1 -1 -1];
Iy = filter2(fy,img);
Ix2 = Ix.^2;
Iy2 = Iy.^2;
Ixy = Ix.*Iy;
clear Ix;
clear Iy;
%applying gaussian filter on the computed value
h= fspecial('gaussian',[7 7],2);
Ix2 = filter2(h,Ix2);
Iy2 = filter2(h,Iy2);
Ixy = filter2(h,Ixy);
height = size(img,1);
width = size(img,2);
result = zeros(height,width);
R = zeros(height,width);
ModifyCorner = 100; %Value for number of corner plots that will be detected
GetCornerPoints = corner(img,ModifyCorner)
imshow(img); hold on;
%plotting of corner points
plot(GetCornerPoints(:,1), GetCornerPoints(:,2), 'g*');
newpca= pca(GetCornerPoints) %getting the pca of the cornerpoints plotted
PcaCol1= sum(newpca(:,1)) %the sum of Pca column 1
PcaCol2= sum(newpca(:,2)) %the sum of Pca column 2
NewHigh = max(newpca(:)) %getting the highest pca value
%this if-else statement is used to determine the ange of rotation for the image
if PcaCol1>PcaCol2
%getting the angle of rotation
GetTempo=acos(abs(NewHigh))*(180/3.14)
GetAngle=-abs(GetTempo) %converts the angle into a negative value
RotateImage = imrotate(img, GetAngle,'bilinear'); %rotation of the image
imshow(img)
figure, imshow(RotateImage)
else
%getting the angle of rotation
GetTempo=acos(abs(NewHigh))*(180/3.14)
GetAngle=abs(GetTempo)
RotateImage = imrotate(img, GetAngle,'bilinear'); %rotation of the image
imshow(img)
figure, imshow(RotateImage)
end
2 Kommentare
Antworten (1)
Image Analyst
am 21 Feb. 2016
Bearbeitet: Image Analyst
am 21 Feb. 2016
Try using hough() to identify lines and find the angle that most of them are at. See the "gantry crane" demo in the help for hough.
By the way, this is not skew, which would be more like a shear. It's more like just an ordinary rotation.
It might not be necessary to rotate the image to find the license plate letters and numbers, which is what I think you're after. Are you 100% sure it is?
4 Kommentare
Image Analyst
am 21 Feb. 2016
They all make different assumptions, or I guess I should say that each method will work best for images that have certain kinds of content in them. So try them all against a known image that you've skewed and compute ssim, psnr, or mse.
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!