pixlsus / GIMP-Scripts

Community managed scripts for the GNU Image Manipulation Program
https://pixls.us
48 stars 4 forks source link

MM and MMM do not match Pat David's #4

Closed billmartz closed 5 years ago

billmartz commented 5 years ago

This was originally a comment at https://github.com/molpopgen/gimp_scripts/pull/3 to help improve the python script that is modeled after this script, but have made several edits for clarity:

First off, until I looked at this I had never had any experience with Script-Fu or Python. Second, I am using GIMP 2.10.8.

I downloaded the original Mountains as Far as the Eye Can See jpg, loaded it into GIMP, converted to sRGB, and converted to 32 floating, linear light.

https://www.flickr.com/photos/nps_wear/8517263428/

mountains as far as the eye can see

I modified the Saul Goode scm to change the naming convention so that the channel names were just L, LL, LLL, etc.

sg-luminosity-masks.scm - R3 .txt

Saul's script creates an L mask that matches the Pat David L mask as seen in https://www.gimp.org/tutorials/Luminosity_Masks/

The python script produces a mask that matches my manually created mask as described next.

When I try to manually duplicate the script actions to produce the D mask, I get a very different result than the script produces. As I understand it, the script copies the L channel and inverts it.

(set! D (car (gimp-channel-copy L))) (gimp-image-insert-channel image D 0 1) (gimp-item-set-name D "D") (gimp-invert D)

I tried L Channel to Selection and then Select Invert to match the script. I also tried following Pat's directions in the tutorial: "With the entire image selected, now we just have to subtract the “Lights” channel." Neither of those methods produced the channel the scripts does.

D produced by script: d from script

D manually created: d manually created

The M mask from the script appears to be the same as Pat's. Pat intersects the D channel with the L channel to produce the M channel and so does the script. Tony Kuyper's method differs:

http://goodlight.us/writing/luminositymasks/luminositymasks-5.html

"You have to first select the entire image (Ctrl+A) and then subtract off one light and one dark mask."

M produced by script:

m produced by script

M produced by Tony Kuyper method:

m produced by tony kuyper method

The big discrepancies lie with the MM and MMM masks. For example, to get MMM, the tutorial indicates that you would use Channel to Selection with the LLL channel and then intersect the DDD channel with that. That produces what appears to be a totally black mask.

Apparently to get around that, the script inverts LLL before subtracting DDD:

(set! MMM (car (gimp-channel-copy LLL))) (gimp-image-insert-channel image MMM 0 3) (gimp-item-set-name MMM "MMM") (gimp-invert MMM) (gimp-channel-combine-masks MMM DDD CHANNEL-OP-SUBTRACT 0 0)

which produces:

mmm produced by script

If you use the Tony Kuyper method of subtracting LLL and DDD from the selected image you get:

mmm produced by tony kuyper method

The script's MMM varies considerably from Pat's MMM, whereas the Kuyper MMM is very similar, although, it seems to me, lighter.

I'm just putting this all out here in the interest of getting the best script possible; no criticism of anyone's work is intended.

molpopgen commented 5 years ago

If I can chime in:

The original Python code was developed in part by copying the code in this repo for the M layers. Visually, the L and D* outputs match, meaning that making them visible gives the same appearance, at least to first order, with both approaches.

I've mucked around for a while tonight, and I cannot discern why the M* layers differ.

patdavid commented 5 years ago

I can try to take a look later this week and see what's going on. If I end up AWOL for too long, ping me again.

patdavid commented 5 years ago

Ah, one quick question - are you working in 32-bit float linear light?

I haven't tested this yet in 2.10.8 with linear light, but it wouldn't surprise me to find these differences. I'll check it later.

billmartz commented 5 years ago

Yes

On Tue, Jan 15, 2019 at 1:25 PM Pat David notifications@github.com wrote:

Ah, one quick question - are you working in 32-bit float linear light?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pixlsus/GIMP-Scripts/issues/4#issuecomment-454498385, or mute the thread https://github.com/notifications/unsubscribe-auth/AsdV_FtjGSCwOtC6tKRiL8eUyEpDCK7Cks5vDh00gaJpZM4aATPm .

patdavid commented 5 years ago

The first two examples you provided look to me like the subtraction operation is being performed in linear light, resulting in the different darks channel.

The script inverts the "D" channel, which happens using the normal Invert command (not the Linear Invert - if you test this and use Linear Invert on the desaturated "L" mask, you'll get the same thing the manual "D" creation is showing you). Manual creation will subtract the "L" channel from the entire image in linear light.

The tutorial should be updated to take linear light into account for these types of operations.

billmartz commented 5 years ago

Thanks, Pat. I will check that out.

On Tue, Jan 15, 2019 at 3:35 PM Pat David notifications@github.com wrote:

The first two examples you provided look to me like the subtraction operation is being performed in linear light, resulting in the different darks channel.

The script inverts the "D" channel, which happens using the normal Invert command (not the Linear Invert). Manual creation will subtract the "L" channel from the entire image in linear light.

The tutorial should be updated to take linear light into account for these types of operations.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pixlsus/GIMP-Scripts/issues/4#issuecomment-454541408, or mute the thread https://github.com/notifications/unsubscribe-auth/AsdV_MolGWm05K9tHbBh_6S39EuVdKU1ks5vDjuggaJpZM4aATPm .

billmartz commented 5 years ago

I have tested the use of linear invert and normal invert, and, yes, normal invert produces a D like the one in the article and in the sg script. Linear invert produces the same result as creating D by subtracting L. I worked with a sRGB, 32 bit floating, linear light image.

I have compared D from the article, D from the script, and D via normal invert, and they look the same to me.

The next steps are to create DD and DDD by subtracting L. My manually created DD via normal invert and the DD created using the script match, as far as I can see. The difference is seen when you compare them to the article’s DD.

DD by subtraction of L from D normal invert dd by subtraction of l from d normal invert

DD article: dd from article

My DD blocks lighter areas than the article’s, i.e., the articles’s mask would apply to a narrower range of darkness.

Looking at the DDDs: DDD by subtraction of L from DD (normal invert) ddd by subtraction of l from dd normal invert

DDD article: ddd from article

There is an analogous difference between my manually created LL and LLL and the article’s. But my manually created masks do match the masks created by the script.

So far we have seen differences in degree, and I am wondering if the differences are caused by working in linear light. I created versions of the masks using an 8 bit integer, perceptual image and a 32 bit floating, perceptual image; however, all the masks were much lighter than the masks shown here.

The big issue comes with the MM and MMM masks. Following the procedure in the article produces essentially solid black masks for both. As I indicated in my first comment, the script, it seems to get around the problem, inverts the LL and LLL masks and then subtracts the DD and DDD masks, instead of intersecting them, producing, for example, this MMM: mmm produced by script

As opposed to the article’s MMM: mmm from article

The manually created MMM mask applies to a narrower range of tones than the article’s mask, and the degree of selection varies too, but exactly how it affects the appearance I don’t really know. Aesthetically, I might like the manual result better, but I cannot produce the article’s result to compare them.