When resizing an image to a pixel bounding rectangle of 1920 by 1080, the result can be off by one.
For example, an image is cropped with rotation to 16x9 yielding a result of 2697x1518. Resizing to a bounding rectangle of of 1920 by 1080, preserving the 16x9 proportions, yields an image of 1919x1080.
Resize to pixel bounding rectangle - off by one
Moderator: jsachs
-
- Posts: 414
- Joined: January 29th, 2019, 11:47 pm
- What is the make/model of your primary camera?: Nikon Z8
Re: Resize to pixel bounding rectangle - off by one
Since image dimensions are always an integral number of pixels, it is not generally possible to crop exactly to a specific aspect ratio. For example:
2697/1518 = 1.77668
16/9 = 1.77778
If you want to resize to exactly 1920 x 1080, use the Resize transformation and set the pixel width and height with Resample checked.
2697/1518 = 1.77668
16/9 = 1.77778
If you want to resize to exactly 1920 x 1080, use the Resize transformation and set the pixel width and height with Resample checked.
Jonathan Sachs
Digital Light & Color
Digital Light & Color
-
- Posts: 414
- Joined: January 29th, 2019, 11:47 pm
- What is the make/model of your primary camera?: Nikon Z8
Re: Resize to pixel bounding rectangle - off by one
The root of the issue appears to be in the cropping with rotation.
Here is an analysis:
2697/1518 = 1.77668, and the error from the ideal ratio is 0.00110 ( difference between 1.77778 and 1.77668 )
For a 16:9 ratio, there are two better solutions at a distance of 1 pixel:
2698/1518 = 1.77734, error = 0.00007
2697/1517 = 1.77785, error = 0.00007
The latter two would more easily fit the bounding rectangle, since the aspect ratio error is roughly divided by 15.
When a cropping rectangle is defined, the user interface could choose the integral dimensions that best fits the aspect ratio.
Here is an analysis:
2697/1518 = 1.77668, and the error from the ideal ratio is 0.00110 ( difference between 1.77778 and 1.77668 )
For a 16:9 ratio, there are two better solutions at a distance of 1 pixel:
2698/1518 = 1.77734, error = 0.00007
2697/1517 = 1.77785, error = 0.00007
The latter two would more easily fit the bounding rectangle, since the aspect ratio error is roughly divided by 15.
When a cropping rectangle is defined, the user interface could choose the integral dimensions that best fits the aspect ratio.
Re: Resize to pixel bounding rectangle - off by one
The problem has nothing to do with rotation -- the same issue arises if you crop without rotation since there can always be roundoff error when computing the output image dimensions.
Crop was never intended to produce precise or even the most precise possible aspect ratio -- if you need a precise result, use Resize.
Crop was never intended to produce precise or even the most precise possible aspect ratio -- if you need a precise result, use Resize.
Jonathan Sachs
Digital Light & Color
Digital Light & Color
-
- Posts: 414
- Joined: January 29th, 2019, 11:47 pm
- What is the make/model of your primary camera?: Nikon Z8
Re: Resize to pixel bounding rectangle - off by one - cropping
Thanks for your help. I agree that the rounding has to do with rectangular cropping, regrardless of rotation. Exactness of aspect ratio is not always feasible, also agreed. When one side of the rectangle is adjusted, the other side could be defined as the closest integral value per the desired aspect ratio.