detected Image and text in document.

0 down vote favorite
I have a binary image (image1). Now I want to detection where is the figure ( may be include big text) in original image. I use haar wavelet transform and detec a image B include some position may be the figure of A. (image 2). If I use image A - image B = image C (image 3) it may be not good be cause we have some boundary. Now I want remove the boundary or detect exactly the figure in image A? how to do that ?. I try use conected component but it run over time.
There is my image: Image A:
Image B:
Image C:
Image A- imageB =Image C ( that mean if A(i,j)==1 and B(i,j)==1 then C(i,j)=0;)
Please help me. Thank you so much

回答(2 个)

Image Analyst
Image Analyst 2014-5-23
编辑:Image Analyst 2014-5-23
Take the image, call imfill(), then erode it enough to make the letters disappear. Then use imreconstruct. See attached demos.

6 个评论

In my purpose, Generally we want to detect in the image where is the figure, where is the text, rule line, table... and my algorithms is detect where is non text, remove that and cut the image smaller. After that base on structure we can use the periodicity of text and detect it is the text. This program may by auto. that mean we input an image, and output is where is the text, where is the figure.
If we use erode that mean we need the threshold and similar for the imreconstruct. I try with your code but it run not good. I have a boundary when we use A-B again. We need there is only text after we minus image. This is the paper that i folowed (attached below)
OK, that's fine. You don't have to use my algorithm. If you have some algorithm from a paper that's working will for you, then that's fine.
Thank for your answer. but I mean, when I follow this paper, the result is the image B ( use MRA and haar wavelet transform like in this paper) but when I try to code it I just received the figure B, it not all figure, and I think when I have image B, I can connect the position of figure in image A and check all connected component of this position in A. I try this but it run overtimes. Could you help me ?. Or if it's not a good way to solve my problem, you can guide me some way? thank you so much.
It looks like B gets all the large blobs. There are a few small scattered dots around the big blobs and it's not picking those up. As far as it's concerned if it's small it could be text. If you want to capture the small surrounding dots, call imclose(). It will dilate the large blobs to engulf the small blobs or connect to nearby blobs, then it will erode to shrink it back down to the original size but without breaking any connections that were made during dialation.
closedImage = imclose(binaryImage, true(9)); % Use whatever window size you want.
Thank you for your answer, I will try it. In another hand I have a problem too in haar wavelet tranforms. I try with a binary image and use this algorithm to detect LL, LH, HL, HH: (all information just in my paper post above - page 8-9)
And I base on this to detect where is the text,image,horizontal,vertical:
I follow this but there is some problem, I can't detect the text, that mean if I use the pixel has high coefficient in LH and high coefficient in HL, they will give me a bad result. I will post my code below in answer, could you help me if there is something wrong? Thank you so much, it very important with me.

请先登录,再进行评论。

There is my code to find haar wavelet tranforms:
function [LL,LH,HL,HH] = haar01(f)
eps=0.00000000000001;
[m,n]=size(f);
for i=1:m/2
for j=1:n/2
if(2*i+2>m||2*j+2>n)
f(2*i,2*j+2)=1;
f(2*i+2,2*j)=1;
end
LL(i,j)=((f(2*i,2*j)|f(2*i+2,2*j))&(f(2*i,2*j)|f(2*i,2*j+2)));
end
end
for i=1:m/2
for j=1:n/2
if(2*i+2>m||2*j+3>n||2*j+1>n)
f(2*i,2*j+3)=0;
f(2*i,2*j+1)=0;
f(2*i+2,2*j)=0;
end
LH(i,j)=((f(2*i,2*j)|f(2*i+2,2*j)) & xor(f(2*i,2*j+1),f(2*i,2*j+3)));
end
end
for i=1:m/2
for j=1:n/2
if(2*i+3 > m ||2*i+1>m||2*j+2>n)
f(2*i+1,2*j)=0;
f(2*i,2*j+2)=0;
f(2*i+3,2*j)=0;
end
HL(i,j)=(xor(f(2*i+1,2*j),f(2*i+3,2*j)) & ((f(2*i,2*j)|f(2*i,2*j+2))));
end
end
for i=1:m/2
for j=1:n/2
if(2*i+1>m||2*i+3>m||2*j+1>n||2*j+3>n)
f(2*i+1,2*j)=0;
f(2*i+3,2*j)=0;
f(2*i,2*j+1)=0;
f(2*i,2*j+3)=0;
end
HH(i,j)=(xor(f(2*i+1,2*j),f(2*i+3,2*j)) & xor(f(2*i,2*j+1),f(2*i,2*j+3)));
end
end
subplot(2,2,1);imshow(LL);title('LL image');
subplot(2,2,2);imshow(LH);title('LH image');
subplot(2,2,3);imshow(HL);title('HL image');
subplot(2,2,4);imshow(HH);title('HH image');
end
There is my main function:
f=imread('testtext1.png');
f=rgb2gray(f);
f=im2bw(f);
[LL,LH,HL,HH] = haar01(f);
[m n]=size(LH);
M=zeros(size(LH));
testext=M;
testimage=M;
testvertical=M;
testhorizontal=M;
testbackground=M;
for i=1:m
for j=1:n
if ((1-abs(HL(i,j)))<eps && (1-abs(LH(i,j))) < eps )
M(i,j)=1000.5; %text
testext(i,j)=1000.5;
end
if (abs(0-HL(i,j))<eps && abs(0-LH(i,j)) < eps && abs(0-LL(i,j)) < eps)
M(i,j)= 500.5; % image
testimage(i,j)=500.5;
end
if (abs(1-HL(i,j))<eps && abs(0-LH(i,j)) < eps )
M(i,j)=7.5; %horizontal line
testhorizontal(i,j) = 100.5;
end
if (abs(0-HL(i,j))<eps && abs(1-LH(i,j)) < eps )
M(i,j)=8.5; %horizontal line
testvertical(i,j)= 200.5;
end
if (abs(0-HL(i,j))<eps && abs(0-LH(i,j)) < eps && abs(1-LL(i,j)) < eps)
M(i,j)= 5.5; % back ground
testbackground(i,j)=50.5;
end
end
end
maskIT=[0 0.5 0;0.5 1 0.5;0 0.5 0];
maskH=[0 0 0;1 1 1;0 0 0];
maskV=[0 1 0; 0 1 0; 0 1 0];
%---------------------------------
restext=imfilter(double(testext),maskIT);
%figure;imshow(restext,[]);
%----------------------------------
resimage=imfilter(double(testimage),maskIT);
%figure;imshow(resimage,[]);
%----------------------------------
resvertical=imfilter(double(testvertical),maskV);
%figure;imshow(resvertical,[]);
%-------------------------------------
reshorizontal=imfilter(double(testhorizontal),maskH);
%figure;imshow(reshorizontal,[]);
%figure;imshow(reshorizontal,[]);
figure,imshow(testext);
V1=resvertical;
V2=resimage;
V3=reshorizontal;
V4=restext;
[a b]=size(V2);
D=zeros(size(V4));
for i=1:a
for j=1:b
if V4(i,j)>=1000.5;
D(i,j)=V4(i,j);
end
end
end
figure,imshow(D,[]);
There is my test image ( take from the paper) but reslut look so bad ( reslut very good in the paper)
Or this image:
Once a gain, thanks for your help

6 个评论

You may have to have some sort of first pass to detect what kind of figure might be present and then use a different algorithm for each kind of figure.
I can't understand what you mean, soory but can you explain this more clearly?
Let's say you have algorithm1 that does a good job at spotting gray scale images on the page, and algorithm2 that does a good job handling line art. You might have some algorithm that recognized, just roughly and approximately, what kind of figure is there, and then apply algorithm1 or algorithm2 for better extraction of the figure, depending on what was found in the first pass.
I'm sorry, may be I don't understand it clearly, My purpose is how to detect the region of text, image, table , and line in the binary image.
I want to cut the image to some homogenous region and base on thi region I will detect where is text, but some time cutting may be wrong because the figure overlap the text ( two figure above), and in this case I must be detect where is non text and remove this. After that I will continue to cut again. So the kind of figure I don't know what kind of figure ( in paper doesn't show it too). I think there is only one algorithm to detect where is non text (by haar wavelet) but I'm not sure my understand here is accurate or have something wrong?
Why don't you just threshold and find the areas of all the blobs? All the text will be in a narrow range. Any outliers (bigger or smaller) will be non-letters and might be considered as noise (if smaller) or part of a figure (if bigger).
Could you show me more detail a bout this way ? and I will try this. I have try a lot in haar but, the result still not good. I think I will try another way, Thank you so much,

请先登录,再进行评论。

类别

Community Treasure Hunt

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

Start Hunting!

Translated by