Photoshop: Why does resizing a document without a background layer causes transparent pixels on edges?

  • 5
  • Question
  • Updated 4 years ago
  • Answered
  • (Edited)
Resizing a document without a background layer causes transparent pixels on edges [see screenshot]. Currently to workaround the problem, I have to create a background layer before resizing image. Can this be fixed?

BTW: This screenshot is using default bicubic resizing. But it may also happen to other resizing options.

Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes

Posted 8 years ago

  • 5
Photo of Ping

Ping, Employee

  • 28 Posts
  • 4 Reply Likes
What's your product? PSE or PS? How about the version?
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
i'm on PS CS5.1
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1402 Posts
  • 232 Reply Likes
That’s to be expected with interpolation, I guess.
Nearest Neighbor might avoid that.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
i suggest to add some intelligence to document resizing so this problem doesn't happen
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1402 Posts
  • 232 Reply Likes
I don’t think you have given this enough thought.
I assume that that with a non-background layer a pixel on the image’s edge is just a pixel as it may well have neighboring pixels inside and beyond the canvas, therefore special consideration might be a problem.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
i suggest to add an option to the resize dialog, such as "maintain edges". so edges are maintained when checked.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Official Response
Yes, and that is entirely expected. Outside of your layer there are transparent pixels. When you resample, those transparent pixels get mixed with the pixels on your layer. This is a natural result of the math of resampling and that fact that Photoshop allows layer data outside of the document bounds.

As for intelligence: Photoshop is not all knowing. It can't guess at what you intend, and it really should not treat pixels at one location different from pixels at another location. If you had color pixels beyond the document bounds - then your suggestion would resample them incorrectly, and would lose data when the image was resized.

And the same "problem" can occur for shapes that don't cover the entire canvas, but exist on layers smaller than the canvas.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
it may be a current limitation but it's definately not what we want when resizing a full image. the worst part is a lot of users will not notice this issue until it's too late and their images are ruined by it.

can't adobe implement some kind of intelligence behind this to avoid the problem? such as if image equals canvas size, temporarily stretch the edge pixels beyond the borders of the canvas, then resize and crop.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Read my previous answer: it's not that simple.
Photo of Moses Journey

Moses Journey

  • 1 Post
  • 0 Reply Likes
After Effects has a "repeat edge pixels" option in many of its effects for this exact reason. Why can't the Photoshop team implement a similar option?
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Photoshop already repeats edge pixels for operations that have an actual edges. But layers can extend beyond the document boundary, and don't have an actual edge (until you hit the 300,000 pixel width or height limit).
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
to workaround this problem, i suggest to add a checkbox option in the resize dialog to "maintain solid edges"
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Adding a checkbox doesn't change the nature of math and pixels.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
but how does it manage to do it the way we want when the layer is set to background?
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Because the background has no transparency, and has nothing outside of it. The background is special because it is the background.
Photo of Dmitri Medvedev

Dmitri Medvedev

  • 8 Posts
  • 1 Reply Like
This is a big problem for web and game developers. (one that did not exist in CS4) I understand that this may be the "correct" way to resize layers in PS but we need a solution. Perhaps have an option to interpolate the alpha channel of the layer differently than the color. It should also be relatively easy to differentiate between a fully transparent pixel and one that does not exist.
Photo of Dmitri Medvedev

Dmitri Medvedev

  • 8 Posts
  • 1 Reply Like
Or how about resize as a smart object?
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
This same issue has existed since transparency/layers were added back in Photoshop 3.0.
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
I'm getting this artifact with smart objects currently.

It does not matter that Photoshop is behaving as designed — that's an engineer's excuse. The expectation from a designer's point of view is that there's not going to be artifacts on the edges of down-sampled images. Adobe needs to adapt the technology to the needs of the user, not the other way around.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
The nature of math does not change, no matter how many times you ask it to.
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
As I and others have noticed, this was not a problem in older versions of photoshop.

The solution has nothing to do with the "nature of math": Either figure out how or why it was working in older versions and restore that functionality, or figure out a way to solve a real problem for many users using whatever graphics techniques will work best.

I mean, surely a company that can provide advance functionality like content-aware replacement can figure out how to avoid pixel artifacts on resized images.

No other graphics technology I use has this problem. I've never seen it in AfterEffects or Illustrator (or older versions of photoshop) nor in CoreGraphics on OS X.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
The problem being discussed here has existed since transparency and layers were added in Photoshop 3.0.

Yes, it has to do with the nature of math, and resampling kernels -- transparency exists outside of the layer. If you resample with a kernel that is wider than a pixel, then transparency can get mixed in on the edges, just the same way colors can blend when resampling.

Any resampling that uses a bilinear or higher order resampling kernel will have this same problem when transparency is involved.
Photo of Dmitri Medvedev

Dmitri Medvedev

  • 8 Posts
  • 1 Reply Like
Wow, the community asks for a feature and we get a smartass reply by an employee. "The nature of math does not change, no matter how many times you ask it to." Are you serious?

There are many ways to implement this feature. Many ways to interpret and resample alpha channels. (Check out repeat edge pixels in AE) We are requesting a feature, we are not attacking you, please pass it along to the appropriate channels.
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1388 Posts
  • 225 Reply Likes
»Wow«, »smartass reply«?
What good luck that that employee usually seems to have oodles of patience and restraint ...
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
There are no good ways to implement this request - because it is asking for incompatible concepts to happen simultaneously (sort of like saying "I want it much hotter and colder at the same time").

If you resample the pixels with any method other than nearest neighbor, some blending must occur. That means that edges against transparency are going to have some transparency leak in (or opacity leak out, depending on your view).
You can't resample (other than nearest neighbor) and keep all edges sharp against transparency.

Different resampling kernels (other than the trivial nearest neighbor) won't help.

Analyzing edges might help, but would lead to more pathological cases and problems than you might imagine, and could still be thrown off by antialiased edges. (it would also be much, much slower) I've been following research that tries to do things like this, and the results aren't too good.

Trying to handle rectangles that fit the full document size as "special cases" also leads to problems (like position and size dependent results), and would not always work in ways that most users would have a difficult time understanding (ie: a single non-opaque pixel would prevent the special case, or a single pixel offset, or data off the side of the document, etc.).
Photo of Dmitri Medvedev

Dmitri Medvedev

  • 8 Posts
  • 1 Reply Like
Those are all good points but a checkbox would solve these problems (or an option to not interpret selection edge pixels' alpha). The importance of this feature comes into play when you're creating a multi-layered file from images with various resolutions. The result is an image with a pixel border. This is especially evident when creating (or combining) seamless textures.

Thank you for your replies and patience.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
No, a checkbox would just add a checkbox.

There is no option that would handle all the cases correctly, except using nearest neighbor resampling or resampling a flattened document. So adding a checkbox for an option that does not exist would not be a good use of anyone's time.
Photo of Dmitri Medvedev

Dmitri Medvedev

  • 8 Posts
  • 1 Reply Like
Another sassy comment. Nice.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
currently, only the background layer resizes without the transparent edge problem. i suggest to make a optional resize option that behaves like resizing the background layer.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
That only works if you want your layers to have no transparency and all act like background layers (no transparency, must be exactly the size of the document).
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
The left image shows a Smart Object in Photoshop that's been resized to 75%. There's bad artifacts around the edges of the paper.

The right image shows the a PSD document—with the same transparent background—that's been brought into Illustrator, resized to 75%, then rasterized to screen resolution. There are no appreciable artifacts.

If we can at least admit that there's a problem with Photoshop's resizing, I think that's a step toward getting this fixed.

Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Please read the existing posts here. What is described is not a bug, not a problem, just a consequence of math and having layers.
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
It's very unfortunate that Adobe won't see this is a problem. As a computer graphics developer, I know that there are alternative resampling algorithms that would look better and give users what they want. For instance, CoreGraphics uses Lanczos resampling which is much higher quality than Bicubic interpolation. There's never issues downsizing graphics with transparency apps that use CoreGraphics.

And again, I will repeat these two points:

1) This wasn't an issue in older versions of Photoshop.
2) This artifact does not show up in other Adobe products such as AfterEffects.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
2 + 2 = 4
Is that a problem, or is that the way things work?

Lanczos weighted sinc would make the edge artifacts much worse, and is visually worse than bicubic (I know, I've done the testing).

This has been an issue for as long as Photoshop has supported transparency.
And you get identical artifacts in AE if you use the same resampling kernel.
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
http://cargobay.tinrocket.com/public/...



Chris, I don't see this at all. This is a screenshot of the same image reduced 75% in Preview.app. Preview.app uses CoreGraphics (and is most likely using Lanczos because it's the highest quality)—but even if it's not, there's no transparency artifacts in this image.

Even if Photoshop is working as designed, as you say, that doesn't mean it's working as it ought to.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Again, Lanczos (and other weighted sinc filters) are some of the worst quality for image resampling because of the ringing artifacts. They really aren't used that often because of the artifacts.

Now, you might be looking at something other than what this topic is about (edges get some transparency where they had none to start with).
If you're using CS6, then you may be seeing the sharpening from the bicubic automatic / bicubic sharper resampling, and may want to choose bicubic or bicubic smoother for this image.
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
OK, now we are moving forward. Yes, I tried the other sample settings. Only nearest neighbor solved the problem—but that introduced other artifacts.

Thank you,
John Balestrieri
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
Chris, I just wanted to follow up again. I tested this image in After Effects and there are no artifacts when it's down sampled to 75%:

http://cargobay.tinrocket.com/public/...



I know you've done your research, and I don't mean any disrespect, but PhotoShop's transparency downsampling is lower quality than it can be and I've been backing up my claims with concrete examples.

Let's step back a second: There are two issues here that are entirely unrelated:

1) What users expect transparency downsampling to produce. I think that After Effects and CoreGraphics meet user expectations here. Folks are not happy because Photoshop is not living up to these expectations with regards to transparency downsampling.

2) Your arguments that PhotoShop's artifacts are the "natural result of the math of resampling" may be true, but I clearly it can be done better. Earlier you said,

"2 + 2 = 4
Is that a problem, or is that the way things work?"

But that wasn't quite right, it should be, "2 + 2 = 5" and that's what everyone is trying to point out — we expect a 4, but PhotoShop is producing a 5, so to speak.

Users want better. That's the only important thing here. Make Photoshop work the way we see other software working. Please make Photoshop help us do our jobs without getting in the way.

John
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Yes, I've done my research.

You are expecting that 2+2 = 6, while Photoshop correctly produces an answer of 4. I keep trying to explain the concepts, but that's a little difficult to do in this space (and we don't have time for a full image processing class).
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
Chris, I think you are missing the point in the samples that I'm posting. Other software, including Adobe's, is doing it better. I want better too. I do not want artifacts.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
I've done my research, you're going to get artifacts everywhere unless you flatten the image first (which AE would do in some cases, BTW) or use nearest neighbor resampling -- that's all you can get because that's how the math works.
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
Chris, I would love to continue this discussion over video chat or the phone. I think it would be much better for communication.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
yes this may be how resizing works when photoshop treats all layers as being surrounded by transparency. therefore, i suggest adding an option to workaround this problem. perhaps such an option can make photoshop temporarily think there are no additional pixels around the layer during the resizing. this would be for layers that have no transparency along the edges. that way, we can get results like resizing a background layer.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Only by flattening the layer (into the background). As long as there is any transparency, then it can get mixed into the edge pixels. Think about the letter "O": what is an edge? And the most correct way to resample it will include transparency at the edges.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
but this problem is concerning rectangular pixel groups. not roundness or abstract shapes.

example: if you were to resize layers of photographs [that all have the same dimensions of the document], you wouldn't want their edges to be turned semi-transparent.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
No, it affects all shapes that are bounded by transparency (aka all layers).
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1387 Posts
  • 225 Reply Likes
I suspect Allen W wants Photoshop to always perform an analysis of the transparency before transformation.
Which might lead to the question: What about a Layer with more than one rectangular non-transparent area?
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
not really concerned about whole areas, just the edges of the layer--in which case makes the pixel area rectangular. if layer has 100% opaque pixels along the edge of the layer [and that layer is the same size of document], my proposed "smart edge resizing" would not bleed in transparency to those edge pixels.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
And that would mean you get different behavior depending on the shape and location of the layer contents. That's not a good idea.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
And you're showing a screen preview in AE, the final resampling won't happen until you render the image/animation.

Facts: resampling with anything beyond a nearest neighbor kernel will blend nearby values.
Fact: if you have transparency outside the shape, that is going to get blended with the edges of the shape if you use a resampling kernel more complex than nearest neighbor.
Fact: bicubic kernels do some sharpening when they resample (which improves on the blurriness of things like bilinear).
Fact: if you use a bicubic kernel for resampling, you will get some sharpening on edges that depends on the exact values of the colors involved.
Fact: Photoshop is giving you exactly the result that the math leads to.
Fact: you are expecting a result other than what the math would lead to.

I can imagine computers working in ways that they cannot work (positronic brains!), but that will not make them work that way.
I can imagine that image processors can do that stuff they show on CSI - but in reality we can't violate the laws of mathematics or physics.
Photo of John Balestrieri

John Balestrieri

  • 10 Posts
  • 5 Reply Likes
Chris, the I think one of the points we are all trying to make is that other software is doing downsampling better than Photoshop and that's what we want. We want the highest possible quality that we can get. Since we get those results other software it doesn't matter that your algorithms are doing what they are designed to do—they're not producing the desired results.

We're asking for Photoshops transparency downsampling to be on par with other professional image software—no visually-distrating halos.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Other software isn't resampling layers, or else it is going to get the exact same artifacts. Again, we've done this investigation.

You're already getting the highest possible quality that you can get.
But you're demanding something that the math does not support.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
or add an option that "preserve hard pixel edges"
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1399 Posts
  • 230 Reply Likes
As in »Nearest Neighbor«?
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
edges ... in this case edges of the layer
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
"smart edge resizing" -- that's what photoshop needs
Photo of Dmitri Medvedev

Dmitri Medvedev

  • 8 Posts
  • 1 Reply Like
Yeah, all we're asking for is an option (or a toggle) to resize a layer without photoshop resampling the alpha outside the selection.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
You have 2 such options: flatten the image before resampling, or use nearest neighbor resampling.

Beyond that, there is no math that will give what you are asking for, and thus no option or toggle.
Photo of poulpi

poulpi

  • 2 Posts
  • 0 Reply Likes
Then why don't you make an option that internally copy the layer to a flatten document, resize it, and then copy it back to the layer ? That way it will have the result everyone expect while keeping layers.
The only drawback is we have to be aware that it will clip outside pixels and won't allow transparency for layers which have this option checked, but that should be obvious if the option is called "Flattened layer".
It should affect everything, like filters too, not only resize.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Your "drawbacks" explain exactly why that isn't done.
Photo of poulpi

poulpi

  • 2 Posts
  • 0 Reply Likes
Hello Chris,
I don't understand why the fact that it would not support transparency and outside pixels is a reason to not do it. A flattened layer already have theses limitations.
Could you develop your answer ?
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Photoshop does support transparency - that's why it is doing what it does, because there are values beyond the document edges, and they default to transparent.
And the same thing happens when you resample something that is not touching the document bounds. As long as you use a resampling kernel wider than a single pixel, values will be mixed, and that includes transparency.

A flattened document has no transparency (and no values outside the document bounds).
Photo of Jose Fuentes

Jose Fuentes

  • 2 Posts
  • 0 Reply Likes
PS CS6 is adding 1pixel trans border to any image that i scale by 50%, is there a setting that i have to turn off for this to stop?

This reply was created from a merged topic originally titled
PS CS6 adds transparent border when scaling images, how can i get it to stop.
Photo of Jose Fuentes

Jose Fuentes

  • 2 Posts
  • 0 Reply Likes
thanks, its good to know that there is nothing that can be turned on or off to fix this issue, I guess I'll have to manually fix the images
Photo of jmarzano

jmarzano

  • 2 Posts
  • 1 Reply Like
This 1pixel transparent border on resize is a pain in the butt. I frequently build 50+ layered files where each later gets saved out as a separate PNG icon. I'm doing mobile development where the file needs to be saved out in various resolutions, like retina and non-retina. Now I can't simply rescale the one file and export layers to files as the smaller versions all have 1pixel trans borders.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
It's not a case of "now" -- it has worked that way for layers since Photoshop 4.0 (that allowed layer data to exist outside the document bounds).
Photo of jmarzano

jmarzano

  • 2 Posts
  • 1 Reply Like
Just because it was happening in earlier versions does not make it right for users. My point is that I'm now aware that this is happening and I have to change my workflow because I never expected 1 pixel artifacts to be introduced in groups of images that were scaled down.
Photo of Bryan Johnston

Bryan Johnston

  • 1 Post
  • 0 Reply Likes
When I down sample from the "save for web" option it doesn't create transparent pixels. Why is it different? The bad thing is that I can't access the save for web percentage through the API so automating this way is not possible.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Because it has flattened the image into just a background layer, and doesn't have to deal with transparency.
Photo of PECourtejoie

PECourtejoie, Champion

  • 848 Posts
  • 306 Reply Likes
Maybe the free interpolate filters found on the Adobe Labs could be helpful: http://labs.adobe.com/technologies/in...
Photo of Ray Giarratana

Ray Giarratana

  • 6 Posts
  • 4 Reply Likes
Dear Chris Cox, Sr. Computer Scientist,

This is crap. You're correct in theory, but not in practice.

To the end user, the edge of the document is the edge of the document. And if the edge of my document is opaque at one size, it should be opaque after scaling to any size.

Period.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
If you want layers to have data beyond the bounds of the document (which they do), then the layer really does exist beyond the bounds of the document and that will show when you resample the layer (i.e.: resize). This is a direct consequence of having layers and transparency.

The background is the only thing that does not extend beyond the edges of the document, and the background does not have this problem.

I'm sorry that you don't understand all the issues involved, but if you take some time to think through the implications of having transparent layers, and having layer data exist beyond the document bounds, then you will see that the current result is the only way it could work correctly.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
adobe should add a new resize option that can workaround this problem. perhaps the new resize option can involve temporarily expanding the layer by 1px all around the layer before resizing, then cut off that 1px expansion when done resizing. this would only apply to layers that perfectly touch all 4 edges of the document.
Photo of Ray Giarratana

Ray Giarratana

  • 6 Posts
  • 4 Reply Likes
Chris, actually, I do understand the issues involved. As I said, you're correct in theory, but not in practice. Most of the time, users don't want to see transparent edge pixels. That's why this issue keeps coming up.

I think Allen's idea is a viable one. Put an option box in the resize window that lets the user choose (for resizing only) between: A) layers that extend beyond the edge of the document at the expense of transparent edge pixels, or B) the edge of the document really is the edge of the document, and I'd bet that the B option is chosen 99% of the time.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
What you want here doesn't come into it. Basic math says it is already working the way it has to.

Even with an option to incorrectly ignore data outside the document bounds (which leads to artifacts if you have any data beyond the bounds other than transparency), anything smaller than the document bounds would still get some transparency mixed in.
Photo of Allen W

Allen W

  • 86 Posts
  • 10 Reply Likes
chris, we know the reasoning behind why it happens. but fact remains, there exists this very visible problem that users don't want. so it's adobe's job and your job as a "computer scientist" to find a clever solution. math isn't the answer to all problems, ingenuity is.
Photo of Chris Cox

Chris Cox

  • 20280 Posts
  • 853 Reply Likes
Part of my job is also trying to explain that sometimes things work the way they do for a reason (or many reasons in this case), and that they are highly unlikely to change.