Skip to main content
added 149 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1 = Binarize[ImageCrop[#, 37], .5] & /@ Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2 = Select[d1, Min@ImageData@# == 0 &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)

Edit

The following will reassemble youyour original image (but cleaner)

tr    = TextRecognize@ImageAssemble@d2;
posd2 = Flatten@Position[d1, x_ /; Min@ImageData@x == 0, {1}];
tp2   = Thread@List[posd2, Characters@tr];
(d1[[#[[1]]]] = Graphics[Text[Style[#[[2]], Large]], ImageSize -> 37]) & /@ tp2;
GraphicsRow[{
ia    = ImageAssemble@Partition[ImageCrop[#, 39] & /@ d1, 9]9]; 
ia1   = Map[ImageCrop[#, ImageDimensions@ia/3 + 3] &, 
            ImagePartition[ia, ImageDimensions@ia/{3, 3}], {2}];

GraphicsRow[{ImageAssemble@ia1, ImageAssemble@digits}]

enter image description hereenter image description here

(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1 = Binarize[ImageCrop[#, 37], .5] & /@ Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2 = Select[d1, Min@ImageData@# == 0 &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)

Edit

The following will reassemble you original image (but cleaner)

tr    = TextRecognize@ImageAssemble@d2;
posd2 = Flatten@Position[d1, x_ /; Min@ImageData@x == 0, {1}];
tp2   = Thread@List[posd2, Characters@tr];
(d1[[#[[1]]]] = Graphics[Text[Style[#[[2]], Large]], ImageSize -> 37]) & /@ tp2;
GraphicsRow[{
   ImageAssemble@Partition[ImageCrop[#, 39] & /@ d1, 9], 
   ImageAssemble@digits}]

enter image description here

(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1 = Binarize[ImageCrop[#, 37], .5] & /@ Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2 = Select[d1, Min@ImageData@# == 0 &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)

Edit

The following will reassemble your original image (but cleaner)

tr    = TextRecognize@ImageAssemble@d2;
posd2 = Flatten@Position[d1, x_ /; Min@ImageData@x == 0, {1}];
tp2   = Thread@List[posd2, Characters@tr];
(d1[[#[[1]]]] = Graphics[Text[Style[#[[2]], Large]], ImageSize -> 37]) & /@ tp2;
ia    = ImageAssemble@Partition[ImageCrop[#, 39] & /@ d1, 9]; 
ia1   = Map[ImageCrop[#, ImageDimensions@ia/3 + 3] &, 
            ImagePartition[ia, ImageDimensions@ia/{3, 3}], {2}];

GraphicsRow[{ImageAssemble@ia1, ImageAssemble@digits}]

enter image description here

added 470 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1 = Binarize[ImageCrop[#, 37], .5] & /@ Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2 = Select[d1, Min@ImageData@# == 0 &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)

Edit

The following will reassemble you original image (but cleaner)

tr    = TextRecognize@ImageAssemble@d2;
posd2 = Flatten@Position[d1, x_ /; Min@ImageData@x == 0, {1}];
tp2   = Thread@List[posd2, Characters@tr];
(d1[[#[[1]]]] = Graphics[Text[Style[#[[2]], Large]], ImageSize -> 37]) & /@ tp2;
GraphicsRow[{
   ImageAssemble@Partition[ImageCrop[#, 39] & /@ d1, 9], 
   ImageAssemble@digits}]

enter image description here

(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1 = Binarize[ImageCrop[#, 37], .5] & /@ Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2 = Select[d1, Min@ImageData@# == 0 &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)
(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1 = Binarize[ImageCrop[#, 37], .5] & /@ Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2 = Select[d1, Min@ImageData@# == 0 &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)

Edit

The following will reassemble you original image (but cleaner)

tr    = TextRecognize@ImageAssemble@d2;
posd2 = Flatten@Position[d1, x_ /; Min@ImageData@x == 0, {1}];
tp2   = Thread@List[posd2, Characters@tr];
(d1[[#[[1]]]] = Graphics[Text[Style[#[[2]], Large]], ImageSize -> 37]) & /@ tp2;
GraphicsRow[{
   ImageAssemble@Partition[ImageCrop[#, 39] & /@ d1, 9], 
   ImageAssemble@digits}]

enter image description here

deleted 20 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1     = Flatten@Map[Binarize[ImageCrop[#Binarize[ImageCrop[#, 37], .5] &, digits,/@ {2}];Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2     = Select[d1, (Min[ImageData[#]]Min@ImageData@# == 0) &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)
(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1     = Flatten@Map[Binarize[ImageCrop[#, 37], .5] &, digits, {2}];

(* Keep only images with content (blanks affect the OCR) *)
d2     = Select[d1, (Min[ImageData[#]] == 0) &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)
(* Get your image *)
digits = ImagePartition[Import["https://i.sstatic.net/cLncR.png"], 50];

(* Remove Borders and Binarize *)
d1 = Binarize[ImageCrop[#, 37], .5] & /@ Flatten@digits;

(* Keep only images with content (blanks affect the OCR) *)
d2 = Select[d1, Min@ImageData@# == 0 &];

(* Assemble as a line and "read" *)
TextRecognize@ImageAssemble@d2
(*
-> "64776958729385431752328231"
*)
added 152 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading
deleted 17 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456
Loading