WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

TextRecognize [image]

recognizes text in image and returns it as a string.

TextRecognize [image,level]

returns a list of strings at the specified structural level.

TextRecognize [image,level,prop]

returns prop for text at the given level.

TextRecognize [video,]

recognizes text in frames of video.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Basic Uses  
Levels  
Properties  
Options  
Language  
Masking  
Method  
RecognitionPrior  
Applications  
Properties & Relations  
Possible Issues  
See Also
Related Guides
Related Links
History
Cite this Page

TextRecognize

TextRecognize [image]

recognizes text in image and returns it as a string.

TextRecognize [image,level]

returns a list of strings at the specified structural level.

TextRecognize [image,level,prop]

returns prop for text at the given level.

TextRecognize [video,]

recognizes text in frames of video.

Details and Options

  • Text recognition, also known as OCR, is the process of detecting text in an image and converting it to text. It is typically used to extract text from scanned books, pictures of documents and more.
  • TextRecognize works with arbitrary grayscale and multichannel images, operating on the intensity value of each pixel.
  • TextRecognize [{image1,image2,}] returns recognition for all imagei.
  • By default, the recognized text is returned as a single string for the whole image. Recognized text can be split into levels.
  • Structural elements specified in level include:
  • Automatic text found in the whole image as a single string (default)
    "Block" a list of results for each block of text
    "Line" a list of results for each line
    "Word" a list of results for each word
    "Character" a list of results for each character
  • TextRecognize [image,level,prop] computes prop at the given level and returns the result as a list {val1,val2,}.
  • Possible settings for prop include:
  • "BoundingBox" bounding box around the text as a Rectangle
    "Confidence" strength of the recognized text
    "Image" cropped image containing the recognized text
    "Text" recognized text (default)
    {prop1,prop2,} a list of properties
  • The following options can be specified:
  • Language $Language the language to recognize
    Masking All the region of interest that includes text
    Method Automatic the method to use
    RecognitionPrior Automatic assumption about text in each masked area
  • TextRecognize accepts a Language option. By default, Language :>$Language is used. Using Language ->{lang1,lang2,} can be used to perform multi-language recognition.
  • The following Language settings can be used:
  • By default, the text found anywhere in the image is returned. Use Masking to specify the region of interest. Possible settings include:
  • All all of the image
    mask a single region of interest
    {mask1,mask2,} multiple regions of interest
  • Possible settings for Method , specifying the type of document, include:
  • Automatic automatic choice of the method
    "Document" optimized for detection in scanned documents
    "NaturalScene" optimized for detection in natural scene images
  • Possible settings for Method , specifying the engine, include:
  • Automatic automatic choice of the method
    "EasyOCR" optimized for scanned documents
    "OperatingSystem" using the operating system (macOS only)
    "Tesseract" optimized for scanned documents
  • RecognitionPrior makes an assumption about the kind of text present in the whole image or in each masked area. Possible settings include:
  • Automatic automatic structure recognition (default)
    "Column" a single column of text
    "Line" a single line of text
    "Word" a single word
    "Character" a single character
    "SparseText" text in no particular structure
  • TextRecognize uses machine learning. Its methods, training sets and biases included therein may change and yield varied results in different versions of the Wolfram Language.
  • TextRecognize may download resources that will be stored in your local object store at $LocalBase , and that can be listed using LocalObjects [] and removed using ResourceRemove .

Examples

open all close all

Basic Examples  (2)

Recognize text in an image:

Wolfram Language code: TextRecognize[[image]]

Recognize lines of text and their corresponding bounding boxes:

Wolfram Language code: i = [image];
Wolfram Language code: res = TextRecognize[i, "Line", "BoundingBox"]

Highlight the bounding box of each recognized line:

Wolfram Language code: HighlightImage[i, {"Boundary", res}]

Scope  (14)

Basic Uses  (5)

Recognize dark text on a bright background:

Wolfram Language code: TextRecognize[[image]]

Bright text on a dark background:

Wolfram Language code: TextRecognize[[image]]

Color image:

Wolfram Language code: TextRecognize[[image]]

Recognize a two-column text:

Wolfram Language code: i = [image];
Wolfram Language code: TextRecognize[i]//Pane[...]&

OCR of a list of images:

Wolfram Language code: TextRecognize[{[image], [image]}]

Levels  (5)

The default recognition is performed on the whole image:

Wolfram Language code: TextRecognize[[image]]

Recognize the text on the image per block:

Wolfram Language code: TextRecognize[[image], "Block"]//Column[...]&

Recognize the text on the image per line:

Wolfram Language code: TextRecognize[[image], "Line"]//Column[...]&

Recognize the text on the image per word:

Wolfram Language code: TextRecognize[[image], "Word"]

Recognize the text on the image per character:

Wolfram Language code: TextRecognize[[image], "Character"]

Properties  (4)

By default, the recognized text is returned as a string:

Wolfram Language code: i = [image];
Wolfram Language code: TextRecognize[i]

The bounding box containing the recognized text:

Wolfram Language code: TextRecognize[i, "BoundingBox"]

The strength of the recognition:

Wolfram Language code: TextRecognize[i, "Confidence"]

The image containing the recognized text:

Wolfram Language code: TextRecognize[i, "Image"]

The subimages containing each word:

Wolfram Language code: Framed /@ TextRecognize[i, "Word", "Image"]

Get the recognized text and its strength for each word:

Wolfram Language code: TextRecognize[[image], "Word", {"Text", "Confidence"}]//Dataset

Get the images of the recognized text per line:

Wolfram Language code: Framed /@ TextRecognize[[image], "Line", "Image"]

Construct a dataset from multiple properties of the recognized text per word:

Wolfram Language code: TextRecognize[[image], "Word", {"Text", "Confidence", "BoundingBox", "Image"}]//Dataset

Options  (11)

Language  (4)

The default recognition language is $Language :

Wolfram Language code: $Language
Wolfram Language code: TextRecognize[[image]]

Specify the language of the text to recognize:

Wolfram Language code: TextRecognize[[image], Language -> "German"]

Use an entity to specify the language:

Wolfram Language code: TextRecognize[[image], Language -> Entity["Language", "German"]]

Recognize text containing multiple languages:

Wolfram Language code: TextRecognize[[image], Language -> {"German", "Russian", "Spanish"}]

Masking  (1)

By default, using Masking ->All , text in the whole image is recognized:

Wolfram Language code: i = [image];
Wolfram Language code: TextRecognize[i]

Specify the region of interest:

Wolfram Language code: TextRecognize[i, Masking -> Rectangle[{60, 200}, {145, 240}]]

Use an image to specify the mask:

Wolfram Language code: TextRecognize[i, Masking -> [image]]

Use a mask specifying multiple regions of interest:

Wolfram Language code: TextRecognize[i, Masking -> [image]]

Use separate masks for each region of interest:

Wolfram Language code: TextRecognize[i, Masking -> {[image], [image]}]

Method  (3)

By default, the most suitable method is used:

Wolfram Language code: TextRecognize[[image]]

Specify the document type:

Wolfram Language code: TextRecognize[[image], Method -> "Document"]

Specify the engine to use:

Wolfram Language code: TextRecognize[[image], Method -> "Tesseract"]

RecognitionPrior  (3)

Specify that the image contains a single character:

Wolfram Language code: TextRecognize[[image], "Character", RecognitionPrior -> "Character"]

Without the prior, multiple characters may be returned:

Wolfram Language code: TextRecognize[[image], "Character"]

Without the correct prior, the text may be unrecognized:

Wolfram Language code: TextRecognize[[image]]

Specify the prior:

Wolfram Language code: TextRecognize[[image], RecognitionPrior -> "Character"]

Recognize text formatted in two columns:

Wolfram Language code: TextRecognize[[image], RecognitionPrior -> "Block"]

Replace double new lines with a single new line:

Wolfram Language code: StringReplace[%, " " -> " "]

Applications  (7)

Perform a frequency analysis on the recognized text:

Wolfram Language code: TextRecognize[[image]]
Wolfram Language code: WordFrequencyData[TextWords[%]]

Visualize the result, highlighting the less frequent words:

Wolfram Language code: WordCloud[%, ScalingFunctions -> (1 / #&)]

Use LanguageIdentify to identify the language of some recognized text:

Wolfram Language code: img = [image]; TextRecognize[img]
Wolfram Language code: lang = LanguageIdentify[%]

Use the identified language to improve the OCR result:

Wolfram Language code: TextRecognize[img, Language -> lang]

Format the recognized text to interactively show the definition of each word:

Wolfram Language code: text = TextRecognize[[image]];

Split the text to have all the words separated:

Wolfram Language code: words = StringSplit[#, Except[WordCharacter]]&@text;

Keep the text content structure, including spaces and punctuation signs, for further reconstruction:

Wolfram Language code: contentList = StringSplit[text, {" " -> " ", " " -> " ", x : PunctuationCharacter :> x}];

Write a function to look up a word's definition in the dictionary:

Wolfram Language code: findDefinition[s_String] := Module[{word, defs}, word = DictionaryLookup[s, IgnoreCase -> True]; If[word === {}, Return[Missing["NotAvailable"]]]; defs = WordData[Pluralize[First[word], 1], "Definitions"]; If[Head[defs] === WordData, Return[Missing["NotAvailable"]]]; Grid[Transpose[{defs[[All, 1, 2]], defs[[All, 2]]}], Alignment -> Left] ]

Apply the function to the words present in the extracted text:

Wolfram Language code: def = Normal@DeleteMissing[AssociationMap[Tooltip[#, findDefinition[#]]&, words], 1, 2];

Recombine the text in a single cell:

Wolfram Language code: TextCell[Row[contentList /. def], FontSize -> 11]

Recognize characters in a geometrical diagram:

Wolfram Language code: image = [image];

Specify the regions that contain text:

Wolfram Language code: mask = [image];
Wolfram Language code: TextRecognize[image, "Character", Masking -> mask, RecognitionPrior -> "Character"]

Extract some properties and highlight them on the image:

Wolfram Language code: res = TextRecognize[image, "Character", {"Text", "BoundingBox", "Confidence"}, Masking -> mask, RecognitionPrior -> "Character"];

Highlight each character with the recognized text and strength:

Wolfram Language code: HighlightImage[image, MapThread[Tooltip[#1, {#2, #3}]&, {res[[All, 2]], res[[All, 1]], res[[All, 3]]}]]

Recognize lines of text and their corresponding bounding boxes:

Wolfram Language code: i = [image];
Wolfram Language code: res = TextRecognize[i, "Line", {"Text", "BoundingBox"}]

Highlight the bounding box of each recognized line using a tooltip for each box:

Wolfram Language code: HighlightImage[i, {"Boundary", MapThread[Tooltip[#1, #2]&, {res[[All, 2]], res[[All, 1]]}]}]

Recognize, group and highlight all occurrences of a single word in an image:

Wolfram Language code: image = [image];
Wolfram Language code: result = TextRecognize[image, "Word", {"Text", "BoundingBox"}]
Wolfram Language code: res2 = Normal[GroupBy[result, (#[[1]]&) -> (#[[2]]&)]][[All, 2]]
Wolfram Language code: HighlightImage[image, Riffle[res2, RandomColor[Length[res2] - 1]]]

Synthesize audio corresponding to the text in an image:

Wolfram Language code: SpeechSynthesize[TextRecognize[[image]]]//Normal

Read from a book cover:

Wolfram Language code: TextRecognize[[image]]//Speak

Properties & Relations  (2)

Recognize warped text:

Wolfram Language code: TextRecognize[[image], Language -> "Russian"]

By default, the whole image is assumed to be the region of interest:

Wolfram Language code: TextRecognize[[image]]

Remove all the new lines:

Wolfram Language code: TextRecognize[[image]]//StringReplace[#, " " -> " "]&

Replace extra new lines with a single new line:

Wolfram Language code: TextRecognize[[image]]//StringReplace[#, " " -> " "]&

Possible Issues  (8)

Rotated text may not be recognized correctly:

Wolfram Language code: i = ImageRotate[[image], 0.15, Background -> White]
Wolfram Language code: TextRecognize[i]

Text of different colors may not be recognized:

Wolfram Language code: TextRecognize[[image]]

The quality of recognized text may improve by processing the image:

Wolfram Language code: Closing[LocalAdaptiveBinarize[[image], 1], 1]
Wolfram Language code: TextRecognize[%]

Fonts smaller than a certain size cannot be recognized:

Wolfram Language code: TextRecognize[[image]]

The quality of recognized text may improve by enlarging the image:

Wolfram Language code: TextRecognize[ImageResize[[image], Scaled[3.5]]]

When recognizing formatted numbers, whitespace may cause OCR errors:

Wolfram Language code: TextRecognize[[image]]

Text of different colors may not be fully recognized:

Wolfram Language code: img = [image];
Wolfram Language code: TextRecognize[img]

Some color adjustments and upsampling might help improve the recognition result:

Wolfram Language code: adjusted = ImageResize[ColorNegate[ImageRecolor[img, ColorsNear[Red, .5] -> White]], Scaled[3]]
Wolfram Language code: TextRecognize[adjusted]

Text given as outlines cannot be recognized properly:

Wolfram Language code: img = [image];
Wolfram Language code: TextRecognize[img]

Fill the background to improve the result:

Wolfram Language code: DeleteSmallComponents@Binarize@RemoveAlphaChannel[RemoveBackground[img], Black]
Wolfram Language code: TextRecognize[%]

Text surrounded by some non-textual content may not be properly recognized:

Wolfram Language code: i = [image];
Wolfram Language code: TextRecognize[i]

Specifying the content type might improve the recognition result:

Wolfram Language code: TextRecognize[i, RecognitionPrior -> "Word"]

Sometimes small text in a large image is not recognized:

Wolfram Language code: i = [image];
Wolfram Language code: TextRecognize[i, "Line"]

Specify the regions that contain text to improve recognition:

Wolfram Language code: TextRecognize[i, "Line", Masking -> [image]]
Wolfram Research (2010), TextRecognize, Wolfram Language function, https://reference.wolfram.com/language/ref/TextRecognize.html (updated 2025).

Text

Wolfram Research (2010), TextRecognize, Wolfram Language function, https://reference.wolfram.com/language/ref/TextRecognize.html (updated 2025).

CMS

Wolfram Language. 2010. "TextRecognize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/TextRecognize.html.

APA

Wolfram Language. (2010). TextRecognize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TextRecognize.html

BibTeX

@misc{reference.wolfram_2026_textrecognize, author="Wolfram Research", title="{TextRecognize}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TextRecognize.html}", note=[Accessed: 13-August-2026]}

BibLaTeX

@online{reference.wolfram_2026_textrecognize, organization={Wolfram Research}, title={TextRecognize}, year={2025}, url={https://reference.wolfram.com/language/ref/TextRecognize.html}, note=[Accessed: 13-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /