Photoshop: Edge pixels are duplicated when transforms don't land on pixel boundaries

  • 1
  • Question
  • Updated 6 years ago
  • Answered
  • (Edited)
I drew this + shape to a new unfilled layer. (the image here is zoomed in at 1600%, the colored squares are one pixel each)
If I zoom to 200%, Cmd-T to invoke transform mode, then nudge once to the right, and once down, and commit the transform by pressing enter, I get the second image here as a result. The left and top pixels are removed, and the bottom and right pixels are duplicated. The interior pixels are not changed.

The transform has to land perfectly between pixels for this to happen. It happens by chance quite often when I am using smart objects. Scaling can also cause the issue.


Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes

Posted 6 years ago

  • 1
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 766 Reply Likes
Which version of Photoshop are you using?

And yes, that would be expected if the image landed on fractions of a pixel, especially if you were using nearest neighbor interpolation.

That's part of why the snap transforms to pixels feature was added in Photoshop CS6.
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
CS6 13.0.1

It's not set to nearest neighbor, it's set to bicubic. There is no way that a translation should result in the results I showed.

The thing is, it doesn't happen at any fraction of a pixel, only when it's at exactly (or maybe very close) to 50%, and only on edge pixels.

It looks like snap transforms to pixel grid will fix it, but that requires snapping vector tools to the grid, which I don't really like.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 765 Reply Likes
If you are on a fractional boundary (not on exact pixel boundaries) -- what you showed is entirely expected. The location of the resampled pixels fall on fractional locations, which will be interpolated, and in some cases repeat edge pixels to deal with interpolated values from outside the original sample bounds (because the interpolation has a non-zero width).

If you want pixel perfect transforms, you need to make sure that your transform bounds fall on pixel boundaries - which is what the preference in CS6 is designed to do.
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
Why are edge pixels treated differently than interior pixels?

I can't believe that this is the best results that can be expected when the pixel snapping preference is off. This is a black circle translated .5 pixels in the x and y.

Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 764 Reply Likes
Because beyond the edge of the defined data, nothing exists. You either duplicate the edge pixels, or use a default value for all "outside" pixels. Either one would give artifacts in some cases.

Yes, again, you're showing exactly what is expected...
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
The interior and the boundary are following different rounding rules.

It's like the pixels on the inside are following the rule (if > 0.5 then round up) while the boundary is (if >= 0.5 then round up)
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 764 Reply Likes
No, they're following the same rules. But the data beyond the edges is a replication of the data at the edges.
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
Image is transformed 0.1 pixels down - insides and edge don't move.
.2 - insides and edge don't move
.3 - insides and edge don't move
.4 - insides and edge don't move
.5 - insides stay in the same place, edge moves down one pixel
.6 - insides and edge move down one pixel
.7 - insides and edge move down one pixel
.8 - insides and edge move down one pixel
.9 - insides and edge move down one pixel

which of these doesn't fit with the others?
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 764 Reply Likes
Again, ALL the pixels follow the same rules for resampling. But the edge pixels have to be replicated to handle the edges (because there is nothing beyond the edges). Translating it up and left by 0.5 pixels would produce exactly what you show.
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
I've run into a very similar issue even when the pixel snapping preference is on.
The image on the left is the smart object scaled down in a document, the image on the right is the contents of the smart object.
In the first group, some of the antialiasing is cut off (along the top, bottom, left and right). In the second version I just drew the two small blue dots inside the smart object. The antialiasing on the big circle has now returned.

Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 765 Reply Likes
Because the edges were snapped to pixel boundaries. the antialiasing isn't necessarily cut off so much as reduced because the edges of the shape fall on pixel boundaries -- which is exactly what UI designers asked for in that feature.
Photo of David Jensen

David Jensen

  • 131 Posts
  • 46 Reply Likes
It does it whether or not pixels are snapped to boundaries.
I am working with photos, not UI design.
What should I do to avoid these issues? It is essential that Smart Objects are used.

Here's a 1:1 scale of the issue above. This happens whether it is snapped to the grid or very slightly off.