darktable icon indicating copy to clipboard operation
darktable copied to clipboard

Feature proposal: Improve scale pixels module to better support anamorphic lenses

Open erikvanhamme opened this issue 1 year ago • 7 comments

Is your feature request related to a problem? Please describe.

Due to the niche nature of anamorphic lenses, no solid support is built into darktable. The proposal put forward here corrects that. It is understood that anamorphic lenses will always be a niche within stills photography, but it does not take much to provide solid support.

Describe the solution you'd like

It is possible to modify the scale pixels module to scale the input image pixels. This module is currently used to deal with sensor types with non-square pixels, but all its functionality transfers to anamorphic images as well. To the module, it does not matter if it is the sensor or the lens that makes the pixels non-square.

In essence this is what is needed:

  1. Make it possible to enable/disable the scale pixels module, even when the cameras.xml does not set the pixel_aspect_ratio hint.
  2. Add a slider to the parameters to allow a variable input range for the pixel_aspect_ratio between 0.5f and 2.0f.

Scale pixels already exists, it is tested and it sits at its correct place in the pixel pipeline. The modifications needed are minimal.

None of the modifications needed would break support for the Nikon D1X, which is the only camera that uses scale pixels to date. The hint would automatically turn on the module, and set its scale factor to 0.5.

Alternatives

As an alternative to this work, I have tested the method put forward in the manual, using the aspect ratio control of the rotate and perspective module.

Although this solution allows me to obtain the correct aspect ratio, it is not ideal. Stretching the image horizontally in this manner results in vertical shrinkage, aiming to retain the same total number of megapixels. However, this vertical compression poses an issue as it discards valuable information captured by the sensor.

Besides the "anamorphic look", the ability to use the full sensor resolution for widescreen images is one of the main advantages of an anamorphic lens.

I think that the scale pixels module is a better place to put this, as it seems that this is a module that is hardly ever used. There is only one camera in cameras.xml that has the hint needed to enable the module. Rotate and perspective is widely used, and seems far more risky to make changes to.

Additional context

As I am a programmer by occupation, I have implemented the above modifications as described. The code is in a separate branch of my fork of the darktable repo, as instructed by the developer documentation. My fork

I have edited 20+ images with these modifications, and encountered no problems. It did exactly what I wanted.

I start this ticket to discuss if this functionality is wanted in darktable. If the project leads decide that this is a good idea, I would be happy to do the additional work to get things production ready. I would also be willing to maintain this long term, as I would be ensuring support for the lens I love to shoot.

The following is missing from the work I have done so far:

  1. Translation of the tooltips for the added GUI elements.

In case anyone wants to test my changes, I can provide some raw files to play with.

erikvanhamme avatar Dec 20 '23 16:12 erikvanhamme

I tested with a raw file for the D1X, and my modifications did not break anything. The scale pixels module turned on as expected, and was initialized to 0.5 scaling factor, as it should be.

erikvanhamme avatar Dec 20 '23 16:12 erikvanhamme

The code is in a separate branch of my fork of the darktable repo, as instructed by the developer documentation.

So you can just make a pull request to make it more convenient for everyone to do test builds and code reviews.

victoryforce avatar Dec 20 '23 16:12 victoryforce

I think I remember reading being able to do this in the lens correction module. Maybe a better place for this functionally.

gi-man avatar Dec 20 '23 17:12 gi-man

Thanks for the feedback.

Lens correction module only gives me a complaint that it does not know the lens. All I can do there is manual vignette control.

I will make the pull request.

erikvanhamme avatar Dec 20 '23 17:12 erikvanhamme

If you manually pick a lens, then this should show: image

gi-man avatar Dec 21 '23 12:12 gi-man

If you manually pick a lens, then this should show: No setting I could make in the lens correction module changes the size of the image. Many kinds of distortion, but I could not make it do what I want.

erikvanhamme avatar Dec 21 '23 16:12 erikvanhamme

@gi-man The "scale" parameter in Lens Correction only magnifies/shrinks (in both dimensions) the image within the same pixel dimensions as the module's input. It's meant to avoid a black border if the applied distortion makes the image smaller or losing the outer border if the distortion makes the image larger.

You need to use Rotate and Perspective to change the aspect ratio, and as Erik pointed out, that changes the height as well as the width to (approximately) maintain the same number of pixels overall.

ralfbrown avatar Dec 21 '23 22:12 ralfbrown

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

github-actions[bot] avatar Feb 20 '24 00:02 github-actions[bot]

Implemented solution in master

jenshannoschwalm avatar Mar 17 '24 08:03 jenshannoschwalm