Borrar filtros
Borrar filtros

extract text from image

62 visualizaciones (últimos 30 días)
ahmed
ahmed el 21 de Dic. de 2013
Comentada: Image Analyst el 23 de Nov. de 2019
this code extract object random i want to extract letter line by line sequential
%%Image segmentation and extraction
%%Read Image
imagen=imread('image_a.jpg');
%%Show image
figure(1)
imshow(imagen);
title('INPUT IMAGE WITH NOISE')
%%Convert to gray scale
if size(imagen,3)==3 % RGB image
imagen=rgb2gray(imagen);
end
%%Convert to binary image
threshold = graythresh(imagen);
imagen =~im2bw(imagen,threshold);
%%Remove all object containing fewer than 30 pixels
imagen = bwareaopen(imagen,30);
pause(1)
%%Show image binary image
figure(2)
imshow(~imagen);
title('INPUT IMAGE WITHOUT NOISE')
%%Label connected components
[L Ne]=bwlabel(imagen);
%%Measure properties of image regions
propied=regionprops(L,'BoundingBox');
hold on
%%Plot Bounding Box
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
hold off
pause (1)
%%Objects extraction
figure
for n=1:Ne
[r,c] = find(L==n);
n1=imagen(min(r):max(r),min(c):max(c));
imshow(~n1);
pause(0.5)
end
  1 comentario
Image Analyst
Image Analyst el 13 de Ag. de 2016
ahmed hasn't been here in 3 years. You'll have to do it without him. Why not use text() or line()?

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Dic. de 2013
It's not random, though you don't know the algorithm it uses (it's top left to bottom right, column by column).
You will need to find each line and extract it before you label. See attached demo, which will produce this:
There is not OCR package built in to MATLAB. You'll have to find one or do it yourself.
  20 comentarios
Walter Roberson
Walter Roberson el 12 de Mzo. de 2017
Can it handle what you asked before? No.
oza san
oza san el 12 de Mzo. de 2017
ok.sorry for the mistake and thank you for your constructive comments but i test it with some images with multilingual texts and works fine with some errors.what i face is when the fonts are different it is too much poor.is there anyway that helps me to handle it?

Iniciar sesión para comentar.

Más respuestas (3)

deeksha h r
deeksha h r el 13 de Ag. de 2016
respected sir,the code used is displaying segmented letter but we need segmented line to be displayed ie each text line from the image is to be displayed.can you please help us with this code

Arvinder singh
Arvinder singh el 1 de Nov. de 2017

https://www.youtube.com/watch?v=qzjE-4yRMCA


Sharad Sirsat
Sharad Sirsat el 23 de Nov. de 2019
You dont need to used "imagen = bwareaopen(imagen,30);" over here, Simply after converting image into binary,Use " bwlabel" to count number of character/objects in an image,After that in an image you can find the centroid of each character and then using Regionprops find their Length, Width to create a bounding box around character.Once you have done bounding box you can crop character individually by giving original image input.
Note: For centroid, bounding box(regionprops) and for imagecrop apply forloop till the counted no of objects/characters.
  1 comentario
Image Analyst
Image Analyst el 23 de Nov. de 2019
But if you don't use bwareaopen(), you'll get a lot of small noise specks that are not letters. Who wants to deal with those????
Plus, if you don't do it like I did, line-by-line, then you'll have labels that are randomly (almost) chosen from each line. To avoid that you'd have to go through some special code, like get the y coordinates of each blob, and use something like kmeans() to find out which blobs are in the same line of text.

Iniciar sesión para comentar.

Categorías

Más información sobre Language Support en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by