Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How do I get rid of blurry transitions between pixels of the background image below. It's the fault of Texture[], previously discussed in this answer.

I haven't been able to get good results with ImageCompose[] or the other answers in this question. I'd like to avoid manual white margins that have to be adjusted if the image size changes or the font size of tick marks changes.

The best solution I've found so far is to manually scale a up using ImageResize[] before using it as Texture. It reduces blurry transitions, but does not get rid of them.

a = Import["http://i.imgur.com/PiLKV6S.png"];
Show[ParametricPlot[{20 + 1.4 x - 40 y, x}, {x, 0, 200}, {y, 0, 1},
  BoundaryStyle -> Directive[Purple, Thick], 
  PlotRange -> {{0, 201}, {0, 144}},
  Prolog -> {Texture[a],
    Polygon[{Scaled[{0, 0}], Scaled[{1, 0}], Scaled[{1, 1}], Scaled[{0, 1}]},
     VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]
    }]]

enter image description here

share|improve this question
    
Try using Resampling -> "Nearest" in the ImageResize. –  Simon Woods May 18 '13 at 20:39
    
I tried that. It reduces blurry transitions, but does not get rid of them. –  Frank May 18 '13 at 20:47

2 Answers 2

up vote 12 down vote accepted

I don't think you can control the interpolation used by Texture. One option might be to embed the image as a Raster primitive instead.

Show[ParametricPlot[{20 + 1.4 x - 40 y, x}, {x, 0, 200}, {y, 0, 1}, 
  BoundaryStyle -> Directive[Purple, Thick], 
  PlotRange -> {{0, 201}, {0, 144}}, 
  Prolog -> {Raster @ Reverse @ ImageData @ a}]]

enter image description here

Zoomed in:

enter image description here

share|improve this answer

Using a combination of nearest resampling and a large size (e.g. 2000 pixels) should do the trick.

a = ImageResize[Import["http://i.imgur.com/PiLKV6S.png"], {2000}, 
Resampling -> "Nearest"];
Show[ParametricPlot[{20 + 1.4 x - 40 y, x}, {x, 0, 200}, {y, 0, 1}, 
 BoundaryStyle -> Directive[Purple, Thick], 
 PlotRange -> {{0, 201}, {0, 144}}, 
 Prolog -> {Texture[a], 
 Polygon[{Scaled[{0, 0}], Scaled[{1, 0}], Scaled[{1, 1}], 
  Scaled[{0, 1}]}, 
 VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]]

enter image description here

share|improve this answer
    
It reduces blurry transitions, but does not get rid of them. There are now over 30 different colors in this tiny part of the image: i.imgur.com/NLfmoyi.png –  Frank May 18 '13 at 20:57
    
The image, when uploaded to stack exchange, does show some blurring. However, from what I can see, the image output in Mathematica shows no such blurry transitions. Try for yourself and let us know. –  David Carraher May 18 '13 at 21:03
    
When I export the image created with ImageResize 2000, and then zoom in using Acrobat or MS Paint, I see exactly the image I uploaded. –  Frank May 18 '13 at 21:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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