Correction To Tilt-Shift Real Estate Image...

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tackd
Posts: 42
Joined: 2013-12-30T07:39:08-07:00
Authentication code: 6789

Correction To Tilt-Shift Real Estate Image...

Post by tackd »

Hi.

This image was shot at a slant with a Tilt-Shift applied either with software or a Tilt-Shift lens
to correct vericals straight.

Image

Photoshop straightening,perspective correction tools did not fare well with this image.
I fear a re-shoot will need to be done.

Is there any way IM can be used to straighten out the bottom slanted and distorted perspective ?

Thank you much.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Correction To Tilt-Shift Real Estate Image...

Post by snibgo »

The house is built on the side of a hill. The house is horizontal, and the road runs downhill from left to right. To get everything square, you should rebuild the house on flat land.

The image could be sheared to move the right side upwards, making the road horizontal but then house would look weird.

"-distort perspective" can make everything more square, eg:

Code: Select all

magick ^
  uaE0Qe.jpg ^
  -distort Perspective 0,0,0,0,639,0,639,0,55,307,55,307,572,314,572,314,0,380,0,425,637,425,637,425 ^
  hillhouse.jpg
Image
snibgo's IM pages: im.snibgo.com
tackd
Posts: 42
Joined: 2013-12-30T07:39:08-07:00
Authentication code: 6789

Re: Correction To Tilt-Shift Real Estate Image...

Post by tackd »

snibgo,

I'm seriously impressed at what you did, would you please allow me a curious request...,
this is a beautiful result but is it possible to correct the distortion of the downward bend in the sidewalks to be a little more straight ?

I'll consider rebuilding the House on flat land if you will consider teaching me how you did the correction (wink) !

Extremely well done.

Thank you so much.

Regards.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Correction To Tilt-Shift Real Estate Image...

Post by fmw42 »

Did you use a wide angle lens? If so that is likely the cause of the sidewalk bend. The perspective distortion that snibgo used will not correct that. You would need to add another distortion to correct the barrel/pincushion caused by the wide angle, I suspect. But snibgo is more versed on photography corrections that I. So I will defer to him on this.

See https://imagemagick.org/Usage/distorts/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Correction To Tilt-Shift Real Estate Image...

Post by snibgo »

tackd wrote:... to correct the distortion of the downward bend in the sidewalks to be a little more straight ?
The curve is in your input image. I used "-distort perspective", which preserves colinearity. This means that straight lines in the input remain straight in the output, and curved lines remain curved. We can't correct curves with "-distort perspective".

The curve may be because the road is like that, or because the camera lens has pincushion distortion. In any case, we can apply barrel distortion:

Code: Select all

magick ^
  uaE0Qe.jpg ^
  -distort barrel 0,0,0.04 ^
  -distort Perspective 0,0,0,0,639,0,639,0,55,307,55,307,572,314,572,314,0,380,0,425,637,425,637,425 ^
  hillhouse.jpg
snibgo's IM pages: im.snibgo.com
tackd
Posts: 42
Joined: 2013-12-30T07:39:08-07:00
Authentication code: 6789

Re: Correction To Tilt-Shift Real Estate Image...

Post by tackd »

Brilliant !

I tried to emulate your code;

Code: Select all

convert 002-10-Exterior-Front.jpg -distort barrel 0,0,0.04 -distort Perspective 0,0,0,0,639,0,639,0,55,307,55,307,572,314,572,314,0,380,0,425,637,425,637,425 hillouse.png
Looks good, except there is tearing on the right side...

Image

Did I do the code correctly ?

Regards.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Correction To Tilt-Shift Real Estate Image...

Post by snibgo »

There is "tearing" on all four sides. They are from virtual pixels. Insert "-virtual-pixel Black" before the first distortion to see them more clearly.

The solution is to crop the result. See my Inner Trim, or Fred's innercrop for a different method.
snibgo's IM pages: im.snibgo.com
tackd
Posts: 42
Joined: 2013-12-30T07:39:08-07:00
Authentication code: 6789

Re: Correction To Tilt-Shift Real Estate Image...

Post by tackd »

Thank you very much for your expertise.

I had another question that popped up.

In a similar fashion to how panorama stitching software works...

Could the straightened sidewalk of your 2nd barrel correction image be merged with your 1st perspective correction,
e.g. sidewalk and below from image 2, above sidewalk from image 1 ?
Similar to how one stitches a vertical panorama.

Maybe I'm reaching too far, but curious I am !

Regards.
tackd
Posts: 42
Joined: 2013-12-30T07:39:08-07:00
Authentication code: 6789

Re: Correction To Tilt-Shift Real Estate Image...

Post by tackd »

2nd thought, never mind the last post on stitching two images, seems far fetched.

Your first correction before the barrel distortion to correct perspective looks so good.
Is IM able to apply the barrel correction to the bottom part of the image (sidewalk and below) or
does it have to be applied to the center of the image.

Thank you.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Correction To Tilt-Shift Real Estate Image...

Post by snibgo »

An image can be composited over another same-size image with a mask that is white where we want the second image, black where we want the first, and gray for a blend.

So that is one way of getting a result using pixels from one image at the top and from the other image at the bottom, with a blend in the middle.

Blending geometric distortions (like barrel and perspective) is slightly more complex, because these don't change pixels, these move pixels. So at the blend, you want to move pixels by some intermediate result.

To get blended displacements, you can use displacement maps. Create an identity absolute map and distort it in the two ways. Invert both maps. Create the black-gray-white mask. Composite one map over the other with the mask, and invert the result back. This gives a blended absolute displacement map that you can use to displace your source image.

EDIT: I forgot to mention the inversions in the previous paragraph. A normal map has for each destination pixel a pointer to where the pixel came from. Inverting changes this, so that each source pixel points to where it moves to. For the blending to work as we want, we need the inversions.
snibgo's IM pages: im.snibgo.com
tackd
Posts: 42
Joined: 2013-12-30T07:39:08-07:00
Authentication code: 6789

Re: Correction To Tilt-Shift Real Estate Image...

Post by tackd »

Whoa snibgo !

Dizzy, I am.

Genius plan. Way beyond my basic wrapping textures around an image using displacement maps.

Hats off to you just the same.

Take good care, thanks again.
Post Reply