# Photoshop General Discussion

Currently Being Moderated

## Correcting perspective

### Aug 28, 2012 12:31 AM

What happens to the image pixels within the crop when you correct perspective with the crop tool or free transform?

Replies
• Currently Being Moderated
Aug 28, 2012 12:41 AM   in reply to Lundberg02

The pixels are interpolated, I guess, but you probably understood that, so I’m not sure I understand the question.

Are you after the mathematics for the perspectival transformations?

|
Mark as:
• Currently Being Moderated
Aug 28, 2012 2:08 AM   in reply to Lundberg02

Interpolation is a complex issue, as far as I can tell.

My understanding is that (with Bicubic Automatic at least) all the pixels are re-calculated.

The image in the screenshot is 100px by 100px.

Edit: But I have to admit that the Math and computational approach are beyond my understanding, so hopefully someone else can explain the issue.

|
Mark as:
• Currently Being Moderated
Aug 28, 2012 5:22 AM   in reply to Lundberg02

rectification:

http://www.fho-emden.de/~hoffmann/persprect13052005.pdf

The new image is of course a rectangle. Its (destination) pixels

are filled row by row, referring to source pixels in the original

image. The source pixel addresses x and y are normally non-

integer. For bicubic interpolation one needs 16 nearest pixels.

For those pixels at the boundary which don't have enough source

pixels one may use a simpler interpolation, finally one gets

nothing, beyond the original boundary.

http://www.fho-emden.de/~hoffmann/bicubic03042002.pdf

Bicubic - p.8

Best regards --Gernot Hoffmann

|
Mark as:
• 22,319 posts
Dec 23, 2006
Currently Being Moderated
Aug 28, 2012 6:33 AM   in reply to c.pfaffenbichler

Resampling implies sampling, and that's just what's happening.

Each pixel in the output image is derived by combining RGB values from one or more pixels sampled from the input image.

Imagine resampling a row of pixels to make 8 pixels out of 5 (for example to accomplish a keystoning correction).  Think of it from the perspective of the pixels in the output you're creating.  Each output pixel is made up by the proportional combination of samples of color from one or more input pixels.  Simple math is used to determine how much the proportions are.

This quick diagram shows an overview:

-Noel

|
Mark as:
• Currently Being Moderated
Aug 28, 2012 9:10 AM   in reply to Noel Carboni

Noel,

Simple math is used to determine how much the proportions are.

Didn't know before that it's as simple!

But joking apart, bicubic interpolation isn't threatening.

Best regards --Gernot Hoffmann

|
Mark as:
• Currently Being Moderated
Aug 28, 2012 9:13 AM   in reply to Gernot Hoffmann

The pdf you linked to looks plenty interesting, but somewhat over my head …

|
Mark as:
• 22,319 posts
Dec 23, 2006
Currently Being Moderated
Aug 28, 2012 9:26 AM   in reply to Gernot Hoffmann

Gernot Hoffmann wrote:

Didn't know before that it's as simple!

Well, just between us chickens, it's really not "simple" in a grand definition of the word - everything's relative.  And we haven't even begun discussing the sharpening component of resampling as found in real implementations.

But the concepts are fairly simple.

And with my background, anything that is a deterministic algorithm that must just operate on a few specific pixels is simple, because a computer CPU or GPU can blaze through it.  It's when bunches of analysis are required at multiple scales (for example, to recognize patterns in an image) that I kind of stop using the term "simple".

-Noel

|
Mark as:
• Currently Being Moderated
Aug 28, 2012 10:54 PM   in reply to Noel Carboni

Far from the original topic, Noel, but how do you rank the Puppet Warp complexity-wise?

|
Mark as:
• 22,319 posts
Dec 23, 2006
Currently Being Moderated
Aug 29, 2012 5:49 AM   in reply to c.pfaffenbichler

c.pfaffenbichler wrote:

Far from the original topic, Noel, but how do you rank the Puppet Warp complexity-wise?

The whole concept of using a mesh, where the resampling is done not by a fixed algorithm, but by an algorithm that varies from point to point in an image based on a multi-dimensional dataset of position information, actually doesn't raise the complexity level too much computationally, but wow does it ever lead to interesting applications!  The complexity comes in when defining tools to create and manipulate the mesh - we see Liquify, Transform-Warp, Puppet Warp, Perspective, and no doubt more I'm not thinking about right now.  Making tools for users to define/refine these datasets easily yet powerfully is where the challenge lies.  And I'd have to say Adobe has done quite well so far.

Thing is, this concept - that of pre-defining a "mesh" or "mask" or dataset that feeds parameters to a flexible image processing algorithm - has application well beyond just resampling or layer masking.  I believe it's where we're going to see more development in the near future.  Imagine <your favorite filter here>, instead of being driven by a few fixed controls, being driven by a flexibly editable database, so that locally every pixel operation is independently controlled.  Indeed we've already seen a lot of development along these lines - lens profile databases, of course layer masks and even layer combination with blending modes, spot and brush editing tools in Camera Raw, mask-driven blurs...  With enough compute power to be able to operate on multi-dimensional data the sky's the limit, and we've reached an age where stuff that takes millions of instructions per pixel can still operate on megapixels in an eyeblink.

The concept of what's "complex" is necessarily changing at an amazing rate.

It's an exciting time to be into digital imaging development.

-Noel

|
Mark as:
• Currently Being Moderated
Aug 29, 2012 5:58 AM   in reply to Noel Carboni

Thank you for the remarks.

|
Mark as:
• Currently Being Moderated
Aug 30, 2012 1:28 AM   in reply to Lundberg02

Lundberg02 wrote:

I don't want to quote Martin Evening directly without his permission, but he says that the crop tool perspective correction is not implemented correctly in CS5 and remains uncorrected in CS6…

Did he express any opinion on whether it was (and remains, of course) correctly implemented in CS4 and it broke in CS5?

What is your personal experience with perspective correction in CS4?

I have all three versions, among others, and had not experienced problems with perspective correction in CS4.  I've only briefly launched CS5, so I have no experience with that.  I'm currently using CS6 for ACR 7.x and then revert to my much faster machine for editing in CS4.

|
Mark as:
• 22,319 posts
Dec 23, 2006
Currently Being Moderated
Aug 30, 2012 9:12 AM   in reply to station_two

I'm curious:  How does a person - any person at any level of expertise - presume to say whether a tool is implemented "correctly"?  Is he seeing some blatant bug with it?

Lundberg, can you provide (summarize, paraphrase, hint at) any more detail about what he means?

-Noel

|
Mark as:
• 22,319 posts
Dec 23, 2006
Currently Being Moderated
Aug 30, 2012 8:19 PM   in reply to Lundberg02

There's some mixup as to who quoted what, and I've been loose about what Reply link I clicked on, but no worries.

Only quirk I've seen with Perspective Correction is that it may foul up the aspect ratio a bit if you move too many corners around.  But that's easily fixed with an Image - Image Size command with Constrain Proportions unchecked.

-Noel

|
Mark as:
• Currently Being Moderated
Aug 30, 2012 8:17 PM   in reply to Lundberg02

Lundberg02 wrote:

Noel, who are you quoting here:

I have all three versions, among others, and had not experienced problems with perspective correction in CS4.  I've only briefly launched CS5, so I have no experience with that.  I'm currently using CS6 for ACR 7.x and then revert to my much faster machine for editing in CS4.

I don't see that in this thread,…

Lundberg02,

That paragraph of gray text is not a quote by Noel.  It appears only in my post #16, and I wasn't quoting anyone.  The words are entirely mine.

I formatted it in faint gray because the paragraph is not strictly necessary for the comprehension of the rest of my post, just helpful in that regard (I thought).

|
Mark as:
• Currently Being Moderated
Aug 31, 2012 12:07 AM   in reply to Noel Carboni

Noel #19,

because I'm using still CS2, I would be glad if you could confirm,

that perspective cropping still doesn't offer an automatism - an

educated guess -  for the aspect ratio.

Applying first perspective cropping and then correction of aspect

ratio is a very bad idea, because the interpolation has to handle

large distortions twice, whereas perspective cropping with assumed

aspect ratio delivers minimal distortion in a practical sense.

Applying Undo in CS2 after perspective cropping (because the

one has to start from the beginning. Has this been repaired mean-

while?

By the way - I had investigated these aspect ratio issues already

more than ten years ago:

http://www.fho-emden.de/~hoffmann/sans04012001.pdf

(all examples without image processing by Photoshop)

Best regards --Gernot Hoffmann

|
Mark as:
• 22,319 posts
Dec 23, 2006
Currently Being Moderated
Aug 31, 2012 7:21 AM   in reply to Gernot Hoffmann

Gernot Hoffmann wrote:

because I'm using still CS2, I would be glad if you could confirm,

that perspective cropping still doesn't offer an automatism - an

educated guess -  for the aspect ratio.

That's a bit too simplistic a question.  Sometimes it seems to get it right, and sometimes it doesn't.  It seems to depend on how many corners you move.  Maybe.

This thread describes how it worked as of Photoshop CS5, and shows that the problem has been known a while:

I just verified the same behavior is still there in Photoshop CS6 as well.  Here's a result using Photoshop CS6:

But since it tends to make the result longer than it needs to be in one dimension, the second resampling (downsampling) step is not terribly evil.

This touches on another subject Lundberg and I have discussed in the past, though...  One of the reasons I virtually always work on upsampled data from start to finish is that resampling steps - such as what we're describing here - lose less critical sharpness during any needed resampling.

-Noel

|
Mark as:
• Currently Being Moderated
Aug 31, 2012 8:43 AM   in reply to Noel Carboni

Noel,

thanks. Obviously the algorithm wasn't improved - there is no

'educated guess' for the aspect ratio. The result - a more or

less visible misinterpretation of the aspect ratio - depends only

on the amount of the shifts of the edges of the 'reference quadri-

lateral' (using the middle handles) towards the image boundary

and beyond.

In my own examples one can see, that the reference quadri-

lateral (which becomes a rectangle in the corrected or rectified

image) has to be drawn only once, as large as possible.

Nothing else, the result is always convincing because of the

educated guess - in fact by averaging upper/lower and left/right

edges, really simple.

Concerning optimal resampling: Photoshop is OK, for my taste,

b) preparing them for inkjet/offset printing, fully color managed

In the world of science there has been done really much in the

field of interpolation/resampling. Of course, with special emphasis

to sharpness. Actually, I'm not concerned with, but I would like to

drop just one name: Philippe Thévenaz.

Best regards --Gernot Hoffmann

|
Mark as:
• 22,319 posts
Dec 23, 2006
Currently Being Moderated
Sep 3, 2012 3:19 PM   in reply to Lundberg02

My intuition tells me they're not "bad guesses" but honest to goodness algorithmic bugs.

That said, I had it work perfectly for me today on an image on which I moved all 4 corners.

-Noel

|
Mark as:
Actions

#### More Like This

• Retrieving data ...

#### Answers + Points = Status

• 10 points awarded for Correct Answers