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

Mathematica graphics

Then we get


Mathematica graphics

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?


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"]}]

Mathematica graphics

  • $\begingroup$ 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? $\endgroup$ – MarcoB Apr 11 '16 at 21:33
  • $\begingroup$ @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. $\endgroup$ – yode Apr 12 '16 at 12:15
  • $\begingroup$ 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)" $\endgroup$ – bill s Apr 12 '16 at 16:48
  • $\begingroup$ Look at the contents of img after your import. The second image is not found. $\endgroup$ – bill s Apr 12 '16 at 16:52
  • $\begingroup$ @bills These two picture have a same dimension.But the dimension have been changed when I upload it to SE. $\endgroup$ – 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:

enter image description here

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.

|improve this answer|||||
  • $\begingroup$ 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? $\endgroup$ – yode Apr 18 '16 at 10:48
  • $\begingroup$ 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. $\endgroup$ – Niki Estner Apr 18 '16 at 10:53
  • $\begingroup$ 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. $\endgroup$ – yode Apr 18 '16 at 11:05
  • 2
    $\begingroup$ @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. $\endgroup$ – Alexey Popkov Apr 18 '16 at 13:23
  • $\begingroup$ @AlexeyPopkov Thanks for your suggestion. $\endgroup$ – 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.

|improve this answer|||||
  • 3
    $\begingroup$ Actually, it says "Inpaint operates separately on each color channel, except with the setting Method->"TextureSynthesis"." $\endgroup$ – Niki Estner Apr 18 '16 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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