4

I 'm trying to get a code that can delete what I wrote with a pen on my hand.

enter image description here

I created a mask to delimit the area where I wanted to change the colors.

This was my first attempt :

i = Import["C:\\Users\\Leandro\\Desktop\\Hand.jpg"]; mask = Graphics[{Black, Rectangle[{0, 0}, {2176, 1624}], White,Rectangle[{709, 575}, {1345, 854}]}]; bbb = ColorReplace[i, mask -> Blue]; ChanVeseBinarize[bbb];

This was my second attempt :

mask2 = Graphics[{Black, Rectangle[{0, 0}, {2176, 1624}], White, Rectangle[{753.112, 638.37}, {757.227, 642.485}]}]; ColorReplace[i, mask2 -> Black]

I could highlight the word , but I can not treat it so that it disappears from the original image.

LCarvalho
  • 9,233
  • 4
  • 40
  • 96

2 Answers2

8

This is a first pass without refinement. Note: after deleting small components there were 4 components. The last 3 were the letters. It is ugly but a start:

i = Import["https://i.stack.imgur.com/NgJUB.jpg"];
cs = ColorSeparate[i];
is = DeleteSmallComponents[
  b = ColorNegate[Binarize[ImageSubtract[cs[[1]], cs[[3]]]]]]; 
m =DeleteSmallComponents[ImageSubtract[b, is]];
cc = ComponentMeasurements[m, "Mask"];
MatrixPlot[m = Total[Range[2, 4] /. cc]]
mask = Dilation[Image[m], 10];
Inpaint[i, mask]

enter image description here

ubpdqn
  • 60,617
  • 3
  • 59
  • 148
7

The procedure you are looking for is called "inpainting" and there is an implementation in Mathematica called 'Inpaint'. Using your mask:

i = Import["https://i.stack.imgur.com/NgJUB.jpg"]; 
mask = Graphics[{Black, Rectangle[{0, 0}, {2176, 1624}], White, 
   Rectangle[{709, 575}, {1345, 854}]}]; 
Inpaint[i, mask]

enter image description here

bill s
  • 68,936
  • 4
  • 101
  • 191