# Why is inpainting worse in grayscale than in RGB image?

img = Import /@ {"http://i.stack.imgur.com/klqh9.png",
"http://i.stack.imgur.com/zCjXN.png"};
mask = Dilation[Binarize[First@img, {0, .15}], 2]


Then we get

result=Inpaint[#,mask,Method->"TextureSynthesis"]&/@img


As you see that arrow point out.The effect is very bad.We get some thing look like a blob,especially that grayscale image have a obvious situation.So how to get a better result with that grayscale image?

update

Since the @bill s's comment and the @Berg's answer think we can convert the RGB image convert to grayscale image.So I update this question to specify maybe this is not good methed.And you can see the last image is the worst.

ImageAssemble[{Last@img, Last@result,
ColorConvert[First@result, "Grayscale"]}]


• Could you expand on what you are trying to achieve, why exactly the result you obtained is not very good, and what would be a better result? – MarcoB Apr 11 '16 at 21:33
• @MarcoB If there are other place seem to be not clear just tell me please.But I think if you run the code you can see the effect of that grayscale image. – yode Apr 12 '16 at 12:15
• yode -- when I run your code I get an error: "Expecting an image, a graphics object, or a matrix of the size {161,81} instead of (graphics)" – bill s Apr 12 '16 at 16:48
• Look at the contents of img after your import. The second image is not found. – bill s Apr 12 '16 at 16:52
• @bills These two picture have a same dimension.But the dimension have been changed when I upload it to SE. – yode Apr 12 '16 at 16:59

There's not much information about what "TextureSynthesis" does in the documentation, but it probably does something roughly like this:

1. Look at the pixels at the border of each inpainting region.
2. Look for nearby similar pixels.
3. Generate a texture based on the pixels found in (2)

Let's look at one region in detail:

The border of the inpainting mask is marked red in the image on the right.

If you look at the pixels near that border, they're mostly orange, some slightly darker orange.

Now if I look for similar pixels in the neighborhood, I will find (almost exclusively) bright orange pixels. There are darker pixels in the neighborhood, but they have a different color, so they're not very similar.

And that's most likely the reason you get different results for the gray scale image: In the gray scale image, if there are darker pixels at the mask border, Inpaint will find "similar" pixels (in gray value) in the neighborhood - so it will generate an inpainting texture based on these pixels too. And that means you get a darker inpainted region.

• Hello,@nikie .If you can get more better image you can use other method,don't strictly use the method of TextureSynthesis.Or my post title misled you? – yode Apr 18 '16 at 10:48
• I hate it when people change the point of their question after they get an answer... Short version: You probably can't get the same result with a grayscale image that you get from and RGB image, because the color similarity information is lost. – Niki Estner Apr 18 '16 at 10:53
• Feel so sorry when I found the people misunderstood what I want to convey.Actually I never change my point.I'm just have some difficult to express in English.As your comment,"when the information losing how to get a better result by a grayscale image?" maybe is my target. – yode Apr 18 '16 at 11:05
• @yode I suggest you to rollback the question to the original title and create new question with the new title. It is really bad idea to change the essence of the question when you already got answers. – Alexey Popkov Apr 18 '16 at 13:23
• @AlexeyPopkov Thanks for your suggestion. – yode Apr 18 '16 at 13:28

According to the documentation Inpaint uses each color seperately, so a colored picture should be easier for Mathematica to process. Especially, since your original colored picture is considerably larger (288 kB) than the grayscale one (120 kB). So, I would say that better results for the former are to be expected.

Now, you may use your colored picture and convert the result to a grayscale picture (if this is what you need). If you dislike ColorConvert you may need to use other software that is better suited to image processing, for example the software used to generate the grayscale image in the first place.

• Actually, it says "Inpaint operates separately on each color channel, except with the setting Method->"TextureSynthesis"." – Niki Estner Apr 18 '16 at 10:17