Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image export size doesn't respect crop aspect ratio #16638

Open
daniilshipilin opened this issue Apr 18, 2024 · 14 comments
Open

Image export size doesn't respect crop aspect ratio #16638

daniilshipilin opened this issue Apr 18, 2024 · 14 comments
Labels
reproduce: confirmed a way to make the bug re-appear 99% of times has been found

Comments

@daniilshipilin
Copy link

Describe the bug

When exporting image (for example downsizing to 3840x2160) there's a rounding issue, where end result jpg is 3840x2158. Crop aspect ratio is set to 16:9, HDTV, 1.78.

Screenshot 2024-04-18 090433
Screenshot 2024-04-18 090443
Screenshot 2024-04-18 090500

Steps to reproduce

  1. Set crop aspect ratio to 16:9
  2. Export jpg image with 3840x2160 size
  3. End jpg image would be 3840x2158

Expected behavior

It should respect the target size set

Logfile | Screenshot | Screencast

No response

Commit

No response

Where did you obtain darktable from?

downloaded from www.darktable.org

darktable version

4.6.1

What OS are you using?

Windows

What is the version of your OS?

Win 11 23H2

Describe your system?

No response

Are you using OpenCL GPU in darktable?

Yes

If yes, what is the GPU card and driver?

NVidia GeForce RTX 3070 Ti

Please provide additional context if applicable. You can attach files too, but might need to rename to .txt or .zip

No response

@zisoft
Copy link
Collaborator

zisoft commented Apr 19, 2024

I get the correct size if I let darktable decide for the longest side:

image

After export:

image

@daniilshipilin
Copy link
Author

Tried your export settings (3840x3840) - result is the same: 3840x2158

@daniilshipilin
Copy link
Author

daniilshipilin commented Apr 19, 2024

The same behaviour is when i select square aspect ratio 1:1. The result image is 3840x3837

@Robogenisis
Copy link

Robogenisis commented Apr 19, 2024

Same issue, I believe it originates with the crop module. Probably related to #16133

Behavior:

  • Export without cropping the image, resolution is correct. (5202x3464)
  • Export after enabling the crop module but without opening it, resolution is correct. (5202x3464)
  • Export after enabling and opening the crop module, resolution is incorrect (5200x3464).
  • Export after resetting the crop module while it is still open, resolution is incorrect (5200x3464).
  • Export after closing the crop module and then resetting it, resolution is correct (5202x3464).

I've been cropping to 1:1 and exporting at 2048x2048, and just realized I'm getting files that are as wrong as 2047x2045.

@jenshannoschwalm
Copy link
Collaborator

Allow upscale in export should fix it.

@Robogenisis
Copy link

@jenshannoschwalm Problem is still there with allow upscaling enabled. This workaround would also upscale undersized images which against my intent.

@kmilos
Copy link
Contributor

kmilos commented Apr 23, 2024

@mrusme
Copy link

mrusme commented Apr 23, 2024

Can confirm (#16671) that issue is there in 4.6.1, even with upscaling enabled.

For anyone looking for a workaround for the time being:

Export the images just a few pixels larger, e.g. 3846px and then run convert over them to crop them to exactly 3840x2160:

find ./ -type f -iname '*.jpg' -exec identify -format '%w %i\n' '{}' \; | awk '$1 >= 3000 { system("convert " $2 " -crop 3840x2160+0+0 " $2) }'

@jenshannoschwalm
Copy link
Collaborator

Sorry about the confusion i might have added above with a somewhat misleading comment.

The crop module and other modules like rotate do some rounding and "position corrections" that are essential for the pixelpipe thus they will simply not be able to keep an pixel exact dimension while processing all the pixels in the pipe. (In theory we could do that but that would lead to significant differences and artifacts while processing, simply because all scaling methods use maths that could introduce blurring, moire ...)

So we rely on the interpolator while exporting and that gets width&height not exactly matching the 16:9 ratio as desired.

You might look into lengthy discussions for ImageMagick, GraphicsMagick or GIMP about difficulties to find an optimal scaling operator that is safe for photo images and synthetic graphics and ...

So for now the best suggestion would be to export in HQ without downscaling and make use of specialist tools like the above mentioned.

@daniilshipilin
Copy link
Author

daniilshipilin commented Apr 25, 2024

Yes i get. Its hard to implement rounding etc. But how about this workaround:

Having a check executed at the end of jpg export, that analyzes, whether targeted aspect ratio is preserved -> if not, it cuts those extra pixels, so that we get exact 4K dimensions without that extra fiddling with extra tools, that btw. doesn't exist on Windows.

The thing is: this 'minor' problem could be an actual deal breaker to many people. I recently moved from CaptureOne (btw. it doesn't have this prob.) in order to try smth. different., and now i'm forced to go back, because batch export respects aspect ratio and i still have a valid license. I'm mostly exporting timelapse photos (1000+ per batch), and this already takes a lot of time. In order to build a video - i have to have exact 4K dimensions. Having additional processing on top of this is not a valid solution. At least in my case.

@wpferguson
Copy link
Member

that btw. doesn't exist on Windows

https://imagemagick.org/archive/binaries/ImageMagick-7.1.1-31-Q16-x64-static.exe

https://download.gimp.org/gimp/v2.10/windows/gimp-2.10.36-setup-1.exe

You can also get GIMP from the Microsoft Store.

@wpferguson
Copy link
Member

i have to have exact 4K dimensions

Why? Does the video creation software not work unless the pixels are exact. On a 75" 4K TV, 2158 pixels vs 2160 pixels works out to a .034 inch difference. Is there a visible difference?

Having a check executed at the end of jpg export, that analyzes, whether targeted aspect ratio is preserved -> if not, it cuts those extra pixels, so that we get exact 4K dimensions without that extra fiddling with extra tools,

We could do this with a Lua script. I already have one that does something similar (in terms of processing), exporting images then using convert from Imagemagick to sharpen the image. We could pad the export a few pixels in both directions, then do a final crop. It shows up as another export option and doesn't require any user intervention after the initial setup.

@mrusme
Copy link

mrusme commented Apr 25, 2024

@jenshannoschwalm thank you for the in-depth explanation! While I understand that apparently there are some hurdles that would be tricky to overcome, I keep wondering how other software (Capture One, literally every Adobe product, Pixelmator, Affinity, etc) does it? To me (the uninformed user) it sounds like there is a logical way to solve this issue, but other issues specifically within darktable's pipeline prevent from doing so.

Kindly correct me if I'm wrong.

@wpferguson
Copy link
Member

I keep wondering how other software (Capture One, literally every Adobe product, Pixelmator, Affinity, etc) does it?

We'll never know for sure since they are all closed source, but I suspect they all crop as the last step. That would also be why using convert yields the exact size since that's the only thing it's doing. darktable crops early in the pipe so it's possible for rounding errors to be present.

In every discrepancy example presented here the difference was discovered when the exported image was loaded in another program that told the dimensions. No one was able to visually detect the difference. If you do the math on the difference then darktable is 99.91% or more accurate. If you print the image at 300dpi, 2 pixels isn't going to make a difference. Unless you zoom to 100% and pixel peep you can't detect the difference.

@jenshannoschwalm jenshannoschwalm added the reproduce: confirmed a way to make the bug re-appear 99% of times has been found label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reproduce: confirmed a way to make the bug re-appear 99% of times has been found
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants