Shifting pixel to dewarped position

2 views (last 30 days)
Max
Max on 27 May 2014
Edited: Matt J on 28 May 2014
Hi ,I am attaching a text image which i need to dewarp.. I have written codes till now to convert the image to binary , dilate it to find the words in it. Also i used the regionprops to find the centroid, orientation of the words. . The problem I am facing is next step is to go for interpolation to shift the pixels to dewarped position. I am unable to do that . Here are my codes
close all
clear all
clc
I=imread('sc2.png');
grid on
imagesc(I)
lev=graythresh(I);
ibw=im2bw(I,lev);
imshow(ibw);
xx=size(ibw);
for i=1:xx(1)
for j=1:xx(2)
if ibw(i,j)==0
ibw(i,j)=1;
else if ibw(i,j)==1
ibw(i,j)=0;
end
end
end
end
figure,imshow(ibw);
se = strel('line',4,0);
bw2 = imdilate(ibw,se);
bw2=bwareaopen(bw2,170);
figure,
imagesc(bw2), title('Original'); hold on
grid on
stats=regionprops(bw2,'BoundingBox','Centroid','Extrema','Orientation');
for object =1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
be=stats(object).Extrema;
bo=stats(object).Orientation
bo;
xmin=min(be(:,1));
xmax=max(be(:,1));
ymax=max(be(:,2));
ymin=min(be(:,2));
width=max(be(:,1))-min(be(:,1));
height=max(be(:,2))-min(be(:,2));
be=round(be);
a1=be(4,:);
b1=be(7,:);
del_y=a1(2)-b1(2);
del_x=a1(1)-b1(1);
ang_deg=atan2(del_y,del_x)*180/pi; % to find the angle of orientation of words
r(object)=ang_deg
plot(bo,'-m+')
a=text(bc(1),bc(2),strcat('Ang :',num2str(round(bo))))
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 10, 'Color', 'green');
end
Also the angle of orientation of the words are not accurate in some words as i saw in results.. The rest of the process i need just guidance. Thanking you

Accepted Answer

Matt J
Matt J on 27 May 2014
  2 Comments
Max
Max on 28 May 2014
Thanking you Matt.. I read those articles.. The thing is I want a very basic methodology like interpolation.. OR probably something like I have an angle of tilt calculated ,so just something like a masked filter to rotate them on the centroid axis and lifting the pixel up or down ..
Matt J
Matt J on 28 May 2014
Edited: Matt J on 28 May 2014
The warping in the figure you posted looks much more complicated than a simple tilt. You can see that the text is curved, not merely rotated. It is not even a general projective transformation.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!