It is currently Sat Jun 13, 2026 5:44 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Help recreating black level adjustment
PostPosted: Mon Dec 30, 2024 9:36 am  (#1) 
Offline
New Member

Joined: Dec 30, 2024
Posts: 4
TL;DR: When I go to Colors -> Exposure in the GIMP GUI and adjust the black level, what function does that call in the codebase? I want to replicate this functionality in a headless Java application.

I have looked into the GIMP source code to try and understand what method is being called when I navigate to colors -> exposure in the user interface to adjust the black level for an image. However, I can't seem to find the method calls that deals with this exposure function. Searching the codebase for black level does not directly bring up anything, and searching for exposure leads me to the dodge/burn function in the source code, as that changes the exposure value. Even searching for black level, black point, etc. does not bring up anything that looks like what I am after.

I also looked in the GEGL source code and found the exposure function quickly, but when I implemented the math that I found there in Java I am not getting the same results out as when I run the image through GIMP, even though I followed the math in the function correctly. The images that I am using are uncompressed TIFF both in and out, so I do not think there is a discrepancy due to file type conversion or compression.

After looking through the GEGL, I went back to the GIMP source code and found the ACES RRT conversion functions and thought that perhaps that was the key. I implemented that as well and followed the link in the source code to where everything was derived from to get a better understanding of what was going on. Still no luck.

My workflow in my code is currently import the image -> convert to ACES RRT -> perform exposure function from GEGL source code -> translate from ACES RRT back to sRGB. Because the output I am getting is still not the same as what I get if I perform the function in GIMP, that leads me to believe that GIMP is not implementing the exposure function as it is written in the GEGL source code. I'm thinking that it is either doing some kind of math before or after it calls the GEGL exposure function, or maybe it is not calling it at all. I also noticed that in the user interface, the colors -> exposure function is not marked with the "G" icon like the other GEGL functions, and it does not come up in the GEGL functions dialog box.

Any help/direction that I could get would be most appreciated.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Help recreating black level adjustment
PostPosted: Mon Dec 30, 2024 1:18 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 2011
gegl:exposure black-level=0.01 to 0.10 are black level's valid parameters.

Your best option is to call gegl:exposure through Java, first by installing GEGL on your system and then calling it. I don't see why you would mess with the algorithm itself.


Top
 Post subject: Re: Help recreating black level adjustment
PostPosted: Mon Dec 30, 2024 4:08 pm  (#3) 
Offline
New Member

Joined: Dec 30, 2024
Posts: 4
Thanks for the reply. Do you know for sure if GIMP is implementing/calling the exposure function from gegl? I'll try invoking the gegl function through the command line. If nothing else, this would verify if my Java implementation matches what GEGL:exposure is doing.

The point of trying to recreate whatever GIMP is doing in Java is so that I won't have to include more libraries/manage installations on the host machine because I won't be the only one using this.


Top
 Post subject: Re: Help recreating black level adjustment
PostPosted: Mon Dec 30, 2024 5:49 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 2011
I am certain gegl:exposure works entirely outside of GIMP


Top
 Post subject: Re: Help recreating black level adjustment
PostPosted: Mon Dec 30, 2024 6:21 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
I'm pretty sure Exposure is a GEGL thing even if it bears no GEGL icon. In fact the source is https://gitlab.gnome.org/GNOME/gegl/-/b ... exposure.c

You can learn a lot by using the Histogram dialog while you play with the tools, because it is updated in real time.

From a quick experiment, I took a picture where the darkest pixel had value 6 (in a 0..255 scale), so the histogram doesn't reach the origin. To bring the histogram to the origin with Exposure I have to use Black level=0.002. Or as a coincidence the "linear light" value for a sRGB value of 6 is 0.0018. So black level would be the linear level below which you want everything to be black.

This said there are plenty of image processing libraries for Java.

_________________
Image


Top
 Post subject: Re: Help recreating black level adjustment
PostPosted: Tue Dec 31, 2024 9:23 am  (#6) 
Offline
New Member

Joined: Dec 30, 2024
Posts: 4
contrast_ wrote:
I am certain gegl:exposure works entirely outside of GIMP


Sorry, I'm not sure I asked the question properly. What I mean to say is that I'm pretty confident that I recreated everything in the GEGL:exposure function, but that does not provide the same result as when I process the image with GIMP. Does anyone know if GIMP is doing any math/conversions either before or after the GEGL exposure function is applied? I can't even find where in the source code GIMP is calling out to GEGL:Exposure.


Top
 Post subject: Re: Help recreating black level adjustment
PostPosted: Tue Dec 31, 2024 9:32 am  (#7) 
Offline
New Member

Joined: Dec 30, 2024
Posts: 4
ofnuts wrote:
I'm pretty sure Exposure is a GEGL thing even if it bears no GEGL icon. In fact the source is GNOME/gegl/-/blob/master/operations/common/exposure.c


Thanks for the reply. Yeah, I saw that - that's where I got the math from (had to edit the quote because I can't post outside links). Since I am getting a different output when I use my implementation to process an image vs using GIMP to process an image that leads me to believe that either
a) I messed something up, which is always possible. I copied the math exactly so I'm not sure where I could have gone wrong.
b) GIMP is doing something before or after the gegl:exposure function

That is a good tip for the histogram though, perhaps I will mess around more with that to see what mistakes I could have made.

I can post some results detailing original pixel values vs my function (recreates gegl:exposure) vs GIMP if that would be helpful. It looked like GIMP was not applying the math evenly across all colors whereas my implementation was - it appeared that there was a larger change in the blue color band than the other two when passing the image through GIMP.


Top
 Post subject: Re: Help recreating black level adjustment
PostPosted: Tue Dec 31, 2024 5:05 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
c_austin85 wrote:
It looked like GIMP was not applying the math evenly across all colors whereas my implementation was - it appeared that there was a larger change in the blue color band than the other two when passing the image through GIMP.


Possible explanation:
https://www.gimp-forum.net/Thread-What- ... ions-wrong

Otherwise, the "exposure" slider seems to work in photographic EV, +1.00 doubles the linear light values and -1 halves them.

_________________
Image


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group