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.

I have a problem where Column will occasionally cut off a single pixel from the top of images.

To reproduce the problem, evaluate this:

image = Import["http://i.stack.imgur.com/2dEty.png"]
Column[{"text", Image[image, Magnification -> 1], "text"}]

The output I get looks like this in the front end:

Mathematica graphics

Note that in Out[2] a single pixel wide row is cut off from the top of the image. It does not occur with all images, but it does with this particular one.

How can I work around this problem? This is on Win7. Can you reproduce on other platforms?

I need this for the image uploader palette (SOUploader`uploadWithPreview[] function to be specific).


It is interesting to note that if I wrap the image in a Pane, and set a pane-size explicitly (as in the original code of the palette), whether the row is cut off depends on whether the size is even or odd (I suspect a rounding issue):

Try this and notice that the cropping happens for even k only:

Table[
 Column[{"text", 
   Pane[Image[image, Magnification -> 1], 
    ImageDimensions[image] + {0, k}], "text"}],
 {k, 0, 5}
 ]
share|improve this question
    
Possibly related: The gaps in the Grid here: mathematica.stackexchange.com/a/753/12 –  Szabolcs Jan 26 '12 at 17:46
    
Everything's fine in my frontend, stupidname.org/files/temp/temp_2012_01/… –  David Jan 26 '12 at 18:00
    
@David Probably Windows-only. –  Szabolcs Jan 26 '12 at 18:12
    
seems to work fine on os x as well. If it's just for uploading, can't you pad the image with one pixel using ImagePad? –  Heike Jan 26 '12 at 22:47
    
Playing with Magnification, the cropping is eliminated if you use Image[image, Magnification -> 1.000001] or higher magnification. An alternative is adding 1 or more to the vertical range in both PlotRange and ImageSize in the rasterized image like so: Graphics[Raster@Reverse@ImageData[image], PlotRange -> {{0, ImageDimensions[image][[1]]}, {0, 1 + ImageDimensions[image][[2]]}}, ImageSize -> {{0, ImageDimensions[image][[1]]}, {0, 1 + ImageDimensions[image][[2]]}}]. All this on Windows Vista. –  kguler Jan 27 '12 at 0:00

2 Answers 2

This seems to be due to a small rounding issue on Windows.

Here is a test Manipulate:

Manipulate[
 matrix = ArrayFlatten[Table[DiamondMatrix[size], {x}, {y}]];
 image = Image[matrix /. {0 -> {0, 0, 0}, 1 -> {255, 255, 255}},
  "Byte", ColorSpace -> "RGB", Interleaving -> True];
 Column[{"test", Image[image, Magnification -> 1], "test"}],
 {size, 1, 20, 1},
 {x, 1, 20, 1},
 {y, 1, 20, 1}
]

Under certain settings the top row of pixels in the image is cut off:

Mathematica graphics

share|improve this answer

Since I cannot reproduce the error I can only guess. Maybe setting the Spacings option for Column helps? This is what Spacing -> 0 looks like:

enter image description here

You can see the gray dividers above the image appearing and then not making it to the middle because of the overlap. Increasing spacing solves this problem, here's Spacing -> 1:

enter image description here

The lines are now visible, and nothing is clipped.

share|improve this answer
    
Thanks for the suggestion. Unfortunately Spacings doesn't change the incorrect rounding behaviour (and the cropping). –  Szabolcs Jan 27 '12 at 8:20

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.