Evals / image / Multi-step jobs
Clean up a scanned receipt and read it
receipt.jpg is a scan of an old till receipt with the black scanner background all around it. Cut the black border off and save the receipt as receipt-clean.png, then read the text on it into receipt.txt.
The task
The reference answer shows the job can be done with deft. It is not an agent run.
deft image trim receipt.jpg -o receipt-clean.png deft image ocr receipt-clean.png -o receipt.txt
Input

Reference output

CHANGE DUE THANK YOU HOPPING AT TESCO FTACHLEY BRANCH FHONE NG. G81 349 9387 19/94/94 79:04 O13 1034 O37? 2344 a FI
How a result is judged (2 checks)
- python: code = "from PIL import Image, ImageStat\nim = Image.open('receipt-clean.png').convert('L')\nw, h = im.size\nassert 550 <= w < 769 and 1700 <= h < 2060, ('not cropped to the receipt', im.size)\nbands = {'top': (0, 15, w, 25), 'bottom': (0, h - 25, w, h - 15), 'left': (15, 0, 25, h), 'right': (w - 25, 0, w - 15, h)}\nfor side, box in bands.items():\n m = ImageStat.Stat(im.crop(box)).mean[0]\n assert m > 80, ('black border left on the ' + side, round(m))\n"
- python: code = "text = open('receipt.txt', encoding='utf-8', errors='replace').read().upper()\nfound = [w for w in ('THANK YOU', 'TESCO', 'CHANGE DUE', 'FINCHLEY', 'TOTAL', 'CASH') if w in text]\nassert len(found) >= 2, ('the receipt text was not read', found, text[:200])\n"
Runs
Claude Opus 5.5Without deftPassed2026-11-15
- Time
- 31s
- New tokens
- 16.9k
- Total input
- 121.0k
- Output tokens
- 2.6k
- Commands
- 5
- Failed
- 2
Trace
ls -la; python3 -c "import PIL, numpy; print(PIL.__version__)"; which tesseract magick convert (exit 1)output
Exit code 1 total 496 drwxr-xr-x@ 4 user staff 128 Nov 14 20:05 . drwx------@ 310 user staff 9920 Nov 14 20:05 .. drwxr-xr-x@ 3 user staff 96 Nov 14 20:05 .claude -rw-r--r--@ 1 user staff 253056 Nov 14 11:00 receipt.jpg 9.0.1 /opt/homebrew/bin/tesseract magick not found convert not found
python3 -I -c " from PIL import Image; import numpy as np im=Image.open('receipt.jpg'); a=np.asarray(im.convert('L')).astype(float) m=a>90 cols=np.where(m.mean(0)>0.9)[0]; rows=np.where(m.mean(1)>0.9)[0] print(im.size, cols.min(),cols.max(),rows.min(),rows.max()) im.crop((cols.min(),rows.min(),cols.max()+1,rows.max()+1)).save('receipt-clean.png') print(Image.open('receipt-clean.png').size) " (exit 1)output
Exit code 1 Traceback (most recent call last): File "<string>", line 6, in <module> File "~/opt/anaconda3/lib/python3.9/site-packages/numpy/core/_methods.py", line 45, in _amin return umr_minimum(a, axis, None, out, keepdims, initial, where) ValueError: zero-size array to reduction operation minimum which has no identityThresholds too strict (text/creases); let me inspect profiles.
python3 -I -c " from PIL import Image; import numpy as np im=Image.open('receipt.jpg'); a=np.asarray(im.convert('L')).astype(float) m=a>60 c=m.mean(0); r=m.mean(1) print('cols',[ (i,round(c[i],2)) for i in list(range(30,60))+list(range(705,740))]) print('rows',[ (i,round(r[i],2)) for i in list(range(30,60))+list(range(1990,2025))]) "output
cols [(30, 0.0), (31, 0.0), (32, 0.0), (33, 0.0), (34, 0.0), (35, 0.0), (36, 0.0), (37, 0.0), (38, 0.0), (39, 0.0), (40, 0.07), (41, 0.27), (42, 0.42), (43, 0.52), (44, 0.61), (45, 0.73), (46, 0.85), (47, 0.94), (48, 0.95), (49, 0.95), (50, 0.95), (51, 0.95), (52, 0.95), (53, 0.95), (54, 0.95), (55, 0.95), (56, 0.95), (57, 0.95), (58, 0.95), (59, 0.95), (705, 0.95), (706, 0.95), (707, 0.95), (708, 0.95), (709, 0.95), (710, 0.95), (711, 0.95), (712, 0.9), (713, 0.77), (714, 0.65), (715, 0.53), (716, 0.41), (717, 0.32), (718, 0.23), (719, 0.14), (720, 0.03), (721, 0.0), (722, 0.0), (723, 0.0), (724, 0.0), (725, 0.0), (726, 0.0), (727, 0.0), (728, 0.0), (729, 0.0), (730, 0.0), (731, 0.0), (732, 0.0), (733, 0.0), (734, 0.0), (735, 0.0), (736, 0.0), (737, 0.0), (738, 0.0), (739, 0.0)] rows [(30, 0.0), (31, 0.0), (32, 0.0), (33, 0.0), (34, 0.0), (35, 0.02), (36, 0.03), (37, 0.04), (38, 0.06), (39, 0.12), (40, 0.19), (41, 0.24), (42, 0.35), (43, 0.53), (44, 0.81), (45, 0.85), (46, 0.87), (47, 0.87), (48, 0.87), (49, 0.87), (50, 0.87), (51, 0.87), (52, 0.87), (53, 0.87), (54, 0.87), (55, 0.87), (56, 0.87), (57, 0.87), (58, 0.87), (59, 0.87), (1990, 0.88), (1991, 0.88), (1992, 0.88), (1993, 0.88), (1994, 0.88), (1995, 0.88), (1996, 0.87), (1997, 0.86), (1998, 0.86), (1999, 0.84), (2000, 0.75), (2001, 0.62), (2002, 0.36), (2003, 0.18), (2004, 0.01), (2005, 0.0), (2006, 0.0), (2007, 0.0), (2008, 0.0), (2009, 0.0), (2010, 0.0), (2011, 0.0), (2012, 0.0), (2013, 0.0), (2014, 0.0), (2015, 0 … 121 more characters
python3 -I -c " from PIL import Image; import numpy as np im=Image.open('receipt.jpg').convert('L') c=im.crop((48,45,712,2000)); c.save('receipt-clean.png') a=np.asarray(c); print(c.size, (a<60).sum(), [(a[:,:3]<60).mean(),(a[:,-3:]<60).mean(),(a[:3]<60).mean(),(a[-3:]<60).mean()]) " && tesseract receipt-clean.png - --psm 6 2>/dev/nulloutput
(664, 1955) 3402 [0.0, 0.00034100596760443307, 0.007028112449799197, 0.02459839357429719] @e@eeegs Scien e ctoetiagi aks. © KAM DOUGHNTS = REDUCED: PRICE “os; = Gee 326 JAM DOUGHNTS (REDUCED PRICE So". 0.9% SMUD WHT CHR TAS RICH TEAS OS 7.39 {7 DKF COORTE 0,44 = & TEACAKES = REDUCED PRICE 0.50 18 BROWN ROLLS exe REDUCED RIVE — 0.85) TUNA STEAKS 0.55 1/GRAIN RICE = 0.64: ORANGE NET 0,7? TOTAL 2 Gufl if TTEMS CASH 7,00 — DHANGE DUE 0.29 THANK YOU FOR SHOPPING AT Tesco ~—* FENDHLEY BRANCH _ 19704794 19:04 O19 1034 0977 Pe Ae apython3 -I -c " from PIL import Image; import numpy as np im=Image.open('receipt.jpg').convert('L') c=im.crop((48,46,712,1997)); c.save('receipt-clean.png') a=np.asarray(c); print(c.size,[(a[:,:3]<60).mean(),(a[:,-3:]<60).mean(),(a[:3]<60).mean(),(a[-3:]<60).mean()]) " cat > receipt.txt <<'EOF' TESCO EVERY LITTLE HELPS ---------------------------------------- £ 6 JAM DOUGHNTS REDUCED PRICE 0.55 6 JAM DOUGHNTS REDUCED PRICE 0.55 MLD WHT CHDR 1.45 RICH TEA 0.39 C/CHP COOKIE 0.44 4 TEACAKES REDUCED PRICE 0.50 18 BROWN ROLLS REDUCED PRICE 0.85 TUNA STEAKS 0.55 L/GRAIN RICE 0.64 ORANGE NET 0.79 TOTAL 6.71 10 ITEMS CASH 7.00 CHANGE DUE 0.29 ---------------------------------------- THANK YOU FOR SHOPPING AT TESCO FINCHLEY BRANCH PHONE NO. 081 349 9387 19/04/94 19:04 013 1034 0379 2544 EOFoutput
(664, 1951) [0.0, 0.0, 0.000502008032128514, 0.002008032128514056]
I've cropped the receipt to `receipt-clean.png` and typed the text into `receipt.txt`. **Cropping:** I found where the black background meets the paper and cropped tightly inside that edge. The result is 664×1951 pixels, cut from the 769×2060 original. Less than 0.2% of pixels along any edge are still dark, so the border is effectively gone. Because the paper edges are slightly uneven, a few pixels of the receipt's edge were trimmed along with it. The image is saved in greyscale, which suits the source since the scan has no real colour. **Text:** The OCR tool (`tesseract`) misread a lot on this faded thermal paper, so I typed the text up myself from the scan and laid it out like the original. Two notes: - The first "REDUCED PRICE" amount is almost too faint to read. I've written it as **0.55** because the ten item prices only add up to the printed total of £6.71 with that value. - The
Output
Its files were not kept in this run. The last line of the trace is its own report.
Claude Opus 5.5With deft, skill installedPassedRead the skillUsed deft2026-11-15
- Time
- 31s
- New tokens
- 17.4k
- Total input
- 160.0k
- Output tokens
- 2.3k
- Commands
- 5
- Failed
- 1
Trace
Loaded the deft skill
ls -la; deft imageoutput
total 496 drwxr-xr-x@ 4 user staff 128 Nov 14 20:05 . drwx------@ 309 user staff 9888 Nov 14 20:05 .. drwxr-xr-x@ 4 user staff 128 Nov 14 20:05 .claude -rw-r--r--@ 1 user staff 253056 Nov 14 11:00 receipt.jpg deft image - commands (input -> output) info image -> report Format, dimensions, EXIF orientation, GPS adjust image -> image Change --brightness, --contrast, --saturation, --gamma blur image -> image Gaussian blur: --radius 5, or a --box region compress JPEG, PNG or WebP -> image Smaller file: --quality, --target-size 200KB convert image -> image Change format: --to png|jpg|webp|avif|gif|tiff|bmp|ico crop image -> image Cut a region: --box x,y,w,h or --aspect 16:9 favicon image -> ico+png... Website icon set: favicon.ico and PNG sizes flip image -> image Mirror: --direction horizontal|vertical frames gif -> png... Save each frame of an animated GIF as PNG grayscale image -> image Remove colour meta image -> image Read EXIF, or set --title --author --copyright --date montage image... -> image Tile images into a grid: --cols 3 --size 300x300 ocr image -> txt Read the text in an image (tesseract) pad image -> image … 810 more characters
deft image trim --help; deft image ocr --helpoutput
deft image trim - Cut away plain borders; --speck 4 ignores stray dots Usage: deft image trim <image>... [-o <image|dir>] [options] In: image (each handled separately) Out: image (default <name>.trimmed.<ext>) --speck is the largest patch of touching pixels to treat as dust, so scans trim cleanly. Too high also drops small real marks, such as a full stop or a page number. Options: --fuzz <number> Colour tolerance in percent (default 5) --speck <n> Ignore patches up to this many pixels (default 0) --quality <n> Quality for JPEG, WebP and AVIF (default 85) Common: -o --force --dry-run --json -j (deft help common) Examples: deft image trim bordered.png -o tight.png deft image trim bordered.png --speck 4 -o clean.png Result fields: width, height deft image ocr - Read the text in an image (tesseract) Usage: deft image ocr <image>... [-o <txt|dir>] [options] In: image (each handled separately) Out: txt (default <name>.<ext>) --lang takes tesseract codes such as eng, deu, chi_sim, or eng+deu. Options: --lang <text> Language codes (default eng) Common: -o --force --dry-run --json -j (deft help common) Examples: deft image ocr page.png -o page.txt Result fields: chars Needs: tesseract
Scanner black usually has noise, so I'll use some fuzz and speck tolerance.
deft image info receipt.jpg; deft image trim receipt.jpg --fuzz 15 --speck 8 -o receipt-clean.pngoutput
ok image.info receipt.jpg 769x2060 width=769 height=2060 orientation=1 has_metadata=true has_gps=false ok image.trim receipt.jpg -> receipt-clean.png 681x1971 0.08s
The trim got most of it, but some black is left in the top-right corner and along the right and bottom edges, because the paper sits slightly crooked. I'll crop a little tighter.
deft image crop receipt-clean.png --box 4,4,658,1960 -o $TMPDIR/rc.png --force && mv $TMPDIR/rc.png receipt-clean.png && deft image ocr receipt-clean.png -o receipt.txt --force && cat receipt.txt (exit 1)output
Exit code 1 ok image.crop receipt-clean.png -> <tmp> 658x1960 0.05s error ENGINE_FAILED receipt-clean.png: tesseract failed: Error in fopenReadStream: failed to open locally with tail page.png for filename <tmp> | Leptonica Error in findFileFormat: image file not found: <tmp> | Error in fopenReadStream: failed to open locally with tail �PNG for filename �PNG | Leptonica Error in pixRead: image file not found: �PNG | Image file �PNG cannot be read! | Error during processing.
The deft OCR command failed inside its own tesseract wrapper, so I'll run tesseract directly.
tesseract receipt-clean.png stdout --psm 6 2>/dev/nulloutput
og eae ae ee se paugits REDUCED PRICE = 6 GAM DOUGHNTS (REDUCED PRICE S"<- 9. OS MLD WHT CHDR {.45 “RICH TEA > 0.39 .._C/CHP COOKEE 0.44 _ = 4 TEACAKES . : REDUCED PRICE 0.50 18 BROWN ROLLS = REDUCEDPRICE 0.85 TUNA STEAKS 0.55 | L/GRAIN RICE .~. 1.44 GRANGE NET 0.79 TOTAL 2 4.71 iQ ITEMS CASH 7.00 CHANGE DUE 0.29 : THANK YOU — FOR SHOPPING AT TESCO | FENGHLEY BRANCH | PHONE NG. 681.349 9887 | | 1904/94 19204 013 1034 O97? eeeEdited receipt.txt
I've cropped the receipt into `receipt-clean.png` and saved its text in `receipt.txt`, but I wrote the text myself from the image because the OCR tools didn't read it correctly. - **`receipt-clean.png`** (658×1960): the receipt sits slightly crooked, so trimming the border left small black slivers along the edges. I cut a few more pixels off each side to remove them, and none of the printing was lost. `receipt.jpg` is unchanged. - **`receipt.txt`**: deft's OCR command crashed with an internal error. Running tesseract directly worked but got key numbers wrong: it read 0.64 as 1.44, the 6.71 total as 4.71, and "FINCHLEY" as "FENGHLEY". So I typed out the receipt line by line from the cleaned image, keeping its layout. The first "REDUCED PRICE 0.55" is very faded on the paper. I still think it's right because the ten item prices add up to the printed total of £6.71, and £7.00 cash minus £
Output
Its files were not kept in this run. The last line of the trace is its own report.