matlab/matlab-agentic-toolkit / skills-catalog/image-processing-and-computer-vision/matlab-recognize-text
matlab-recognize-text
VerifiedBuild OCR pipelines in MATLAB using the ocr() function. Use this skill when the user wants to read text from images, documents, signs, meters, displays, license plates, gauges, receipts, or seven-segment displays. Covers image preprocessing, text detection (CRAFT, MSER), ROI-based recognition, multi-language OCR, and custom model training. Use when: OCR, text recognition, extract text from image, character recognition, document scanning, meter reading, gauge reading, receipt scanning, digitize text from photo.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 20.5 KB |
| manifest.yaml | config | 485 B |
| reference/batch-pipeline.md | markdown | 2.3 KB |
| reference/detection-methods.md | markdown | 3.6 KB |
| reference/function-reference.md | markdown | 3.8 KB |
| reference/limitations.md | markdown | 2.4 KB |
| reference/preprocessing-guide.md | markdown | 8.1 KB |
| reference/supported-languages.md | markdown | 2.9 KB |
| reference/training-guide.md | markdown | 5.6 KB |
reference/function-reference.md
View on GitHub# OCR Function Reference
## Key Functions
| Function | Purpose | Toolbox |
|----------|---------|---------|
| `ocr` | Recognize text in image | Computer Vision |
| `ocrText` | OCR results object (Text, Words, Confidences) | Computer Vision |
| `detectTextCRAFT` | Deep learning text detection | Computer Vision |
| `detectMSERFeatures` | MSER-based text region detection | Computer Vision |
| `imsegsam` | SAM segmentation for challenging binarization | Computer Vision |
| `imbinarize` | Binarize image (Otsu or adaptive) | Image Processing |
| `imtophat` | Remove non-uniform background | Image Processing |
| `imcomplement` | Invert image (ensure dark-on-light) | Image Processing |
| `imresize` | Scale image for better recognition | Image Processing |
| `imerode` / `imdilate` | Thin/thicken characters | Image Processing |
| `imreconstruct` | Morphological reconstruction | Image Processing |
| `bwareaopen` | Remove small noise from binary image | Image Processing |
| `padarray` | Add border padding | Image Processing |
| `medfilt2` | Remove salt-and-pepper noise | Image Processing |
| `adapthisteq` | Local contrast enhancement (CLAHE) | Image Processing |
| `imrotate` | Deskew rotated text | Image Processing |
## LayoutAnalysis Parameter
Choose based on content structure:
| Value | Use When |
|-------|----------|
| `"auto"` | Default; let OCR decide (works for full documents) |
| `"page"` | Multi-column document pages |
| `"block"` | Single block of multi-line text |
| `"word"` | ROI contains a single word |
| `"line"` | ROI contains a single text line |
| `"character"` | ROI contains a single character |
| `"none"` | Disable layout analysis (use with manual ROIs) |
**Gotcha:** When providing ROI bounding boxes from detection, set `LayoutAnalysis` to `"Word"` or `"none"` — the default `"auto"` often fails on small regions.
## Common Patterns
### CRAFT + OCR for Natural Scenes
```matlab
I = imread("streetSign.jpg");
% Detect text regions
bbox = detectTextCRAFT(I, CharacterThreshold=0.3);
% Preprocess for OCR
Igray = im2gray(I);
BW = imbinarize(Igray);
% Always check polarity — ensure dark text on light background
BW = imcomplement(BW);
% Recognize with word-level layout
results = ocr(BW, bbox, LayoutAnalysis="Word");
recognizedWords = cat(1, results(:).Words);
```
### ROI-Based with Region Filtering
```matlab
% Find text-like connected components
BW = imbinarize(im2gray(I));
cc = bwconncomp(BW);
stats = regionprops(cc, "BoundingBox", "Area");
roi = vertcat(stats(:).BoundingBox);
area = vertcat(stats(:).Area);
% Filter by area and aspect ratio
aspectRatio = roi(:,3) ./ roi(:,4);
keep = area > 100 & aspectRatio > 0.25 & aspectRatio < 1.25;
roi = double(roi(keep, :));
% Pad ROIs slightly for better polarity detection
roi(:,1:2) = roi(:,1:2) - 5;
roi(:,3:4) = roi(:,3:4) + 10;
results = ocr(I, roi, LayoutAnalysis="none");
```
### Recognition Patterns
```matlab
% Basic OCR on full image
results = ocr(I);
disp(results.Text)
% OCR with ROI — ALWAYS specify LayoutAnalysis
results = ocr(I, bbox, LayoutAnalysis="word");
% OCR with character constraint
results = ocr(BW, CharacterSet="0123456789");
% Seven-segment display
results = ocr(I, roi, Model="seven-segment", LayoutAnalysis="word");
% Non-English language
results = ocr(I, Model="french");
```
### Validation Patterns
```matlab
% Check confidence scores — low confidence indicates problems
lowConfIdx = results.CharacterConfidences < 0.5;
if any(lowConfIdx)
suspectChars = results.Text(lowConfIdx);
suspectBoxes = results.CharacterBoundingBoxes(lowConfIdx, :);
end
% Use word confidences for filtering
validWords = results.WordConfidences > 0.7;
cleanText = results.Words(validWords);
% Mean confidence for overall quality check
meanConf = mean(results.WordConfidences, "omitnan");
fprintf("Mean word confidence: %.2f\n", meanConf);
```
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |