필터 지우기
필터 지우기

Text skew detection and correction in image

조회 수: 6 (최근 30일)
Yahya
Yahya 2022년 11월 19일
댓글: Image Analyst 2022년 11월 22일
clc;clear all; close all;
a=imread('eq2.jpg');
figure;
imshow(a)
if size(a,3)==3
a=rgb2gray(a);
end
b=im2bw(a);
ar=imrotate_white(b,30);
figure
imshow(ar);
br=~(ar);
figure
imshow(br)
[r c]=size(b);
X=[];
for i=1:r
for j=1:c
if br(i,j)==1;
X=[X; i j];
end
end
end
size(X);
[coeff, score, latent]=pca(X);
figure;
biplot(coeff(:,1:2),'Scores',score(:,1:2),'VarLabels',{'v_1','v_2'});
r=sqrt((coeff(1,1))^2+(coeff(1,2))^2);
th=real(double(vpa(acos(coeff(1,1)/r)*180/pi)))
syms x
th=real(double(vpa(solve(x==th-90))))
rotatedImage=imrotate(br,-th);
figure
imshow(rotatedImage)
function rotated_image = imrotate_white(image, rot_angle_degree)
RA = imref2d(size(image));
tform = affine2d([cosd(rot_angle_degree) -sind(rot_angle_degree) 0; ...
sind(rot_angle_degree) cosd(rot_angle_degree) 0; ...
0 0 1]);
Rout = images.spatialref.internal.applyGeometricTransformToSpatialRef(RA,tform);
Rout.ImageSize = RA.ImageSize;
xTrans = mean(Rout.XWorldLimits) - mean(RA.XWorldLimits);
yTrans = mean(Rout.YWorldLimits) - mean(RA.YWorldLimits);
Rout.XWorldLimits = RA.XWorldLimits+xTrans;
Rout.YWorldLimits = RA.YWorldLimits+yTrans;
rotated_image = imwarp(image, tform, 'OutputView', Rout, 'interp', 'cubic', 'fillvalues', 255);
end
The output is
Rotate orgin image angle= 30
The answer is angle = 25.1508 !!!!
The angle must be 30 .
How do I solve this problem?
This problem appears to me in the rational equations only, but in the linear equations the angle is shown with high accuracy.

답변 (1개)

cr
cr 2022년 11월 19일
편집: cr 2022년 11월 19일
In general, pattern maching is used. See estimateGeometricTransform()
But the result may not be exactly the angle it's rotated to.
  댓글 수: 2
Yahya
Yahya 2022년 11월 22일
Not useful :( ,thanks for answering
Image Analyst
Image Analyst 2022년 11월 22일
@Yahya Then why did you accept the answer?
In general, for an arbitrary, random set of blobs, there is no way to determine what is the "correct" skew and orientation angle.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by