7
$\begingroup$

Let us consider the following image file.

enter image description here

Is there a way to use Mathematica in order to "read-scan" the image file and then obtain three new images, one containing the computer text, one containing the hand-written text, and one containing the drawing (ship)?

$\endgroup$
1
  • 2
    $\begingroup$ What, if anything, have you tried? $\endgroup$
    – C. E.
    Aug 30, 2021 at 18:39

2 Answers 2

9
$\begingroup$

For this one example, a start might be to extract the different colour layers.

masks = (ColorReplace[#, {Red -> Black, _ -> White}, .2] &) /@ (ImageRecolor[
     i, {# -> Red}] & /@ Rest[DominantColors[i]])

This gives us back two images:

enter image description here

and then we can use these as masks on the original image:

ImageAdd[#, i] & /@ masks

enter image description here

It may be possible to use ImageBoundingBoxes or (more likely) another neural network based approach to separate the text and the boat - ImageBoundingBoxes is apparently not trained on pictures of text.

(The "test text" example makes me think this is one of hundreds of images, and it seems unlikely that you will find a blanket solution for this class of problem that doesn't require a fair bit of hand-tweaking per image.)

$\endgroup$
2
  • $\begingroup$ Nice. Is there a way to retain the blue color of the hand-written text and the boat? $\endgroup$
    – Vaggelis_Z
    Aug 30, 2021 at 20:01
  • $\begingroup$ @Vaggelis_Z Yes, using those as masks - I've updated the answer. $\endgroup$
    – Carl Lange
    Aug 30, 2021 at 20:25
7
$\begingroup$

Let's use the color scheme:

colors = DominantColors[img];
detects = ColorDetect[img, #] & /@ Rest[colors];
Binarize /@ detects

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.