Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Colour Cast Reduction Plug-in

Tue Jun 20, 2023 10:43 am

I have updated my colour cast reduction plug-in. It is based on the one by Krikor and Tim.

I added a mask so that the black (and close to black) parts of the original image are not contaminated by the correction colour which is overlaid.

I had found it useful to use Colours/Auto/Stretch Contrast prior to running the plug-in, where the original was dark, bright, or lacking in contrast. Because this is not available in Gimp Python I have added the option to use levels_stretch and then reduced contrast by 10% to create some headroom for the colour cast reduction.

I hope people will try this on real-world images and provide me with feedback as to it's usefulness.

col-cast-reduction.zip
(2.93 KiB) Downloaded 21 times


Edit: I found an error in the creation of the Contrast layer. This is now corrected. The default contrast increase (opacity of Contrast layer) is now set at 10%.
The revision data and the comments in the listing has been updated.

Edit2: The plug-in was found to be extremely slow for large images, so pixelise is now done on a small scaled version of the image and a sample of colour taken from this used to fill the Colour layer.

Edit3: Revised by simplification. Now runs quite fast on even very large images.

Re: Colour Cast Reduction Plug-in

Fri Jun 23, 2023 5:34 am

Latest update to this plug-in.
I discovered an error in the creation of the Contrast layer. (I always make mistakes in Python programs and discover them later!) This has now been corrected and i have replaced the file (above).

The Stretch Contrast option (the default) improves the colour correction, not only for those images initially lacking in contrast, but also those where the histogram spreads across the whole of the range.
After running the plug-in, the contrast can be changed by altering the opacity of the Contrast layer (default 10%) and the amount of colour correction can be adjusted by the use of Colours/Saturation on the Colour layer.

I have been able to carry out a limited amount of testing by "borrowing" a number of examples found in a paper on the internet. However, these are not in the public domain so I cannot show them here.

If anyone can provide me with examples it will enable me to test further.

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 1:49 am

What about creative commons licences?

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 2:47 am

@Sallyanne,

I have re-written the tutorial for the plug-in to reflect it's changes. I have inserted some before and after examples. The first of these, the one that prompted the changes to the plug-in, is from Pixls.Us so has a creative commons licence. The others I believe, but cannot confirm, are in the public domain. However, if I am mistaken, I doubt anyone is going to sue me over such insignificant images.

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 2:54 am

I have re-written the tutorial for the plug-in to reflect the changes.
In addition to reducing colour-casts it appears to be useful for recovering problem images. Similar, but not identical to Colours/Auto/Stretch Contrast.
Foggy images are clarified to a great extent. It appears to work well for many pictures, but there are others where the results are definitely less than satisfactory!

col_cast_reduction_tut.pdf
(837.22 KiB) Downloaded 61 times


Edit: The plug-in was found to be extremely slow for large images. It has now been amended to resolve this problem.
The tutorial has been updated. There is no difference in operation, but the description of the operating principles has been updated.

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 3:30 am

Thanks a lot David! I need to learn it and to know how to use it correctly.
I know how important it is to improve so many pictures and photos.
Thank you so much. :tyspin

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 3:46 am

Thank you david. Might come in handy sometime.

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 11:29 am

Apologies to all!

When testing on a .TIFF image of 396.3 MB (derived from a RAW of 49.1 MB) I found that the pixelise process was taking forever - I aborted after about 15 minutes.

I have changed the plug-in so that it creates a small, scaled layer (100px wide) for the pixelation process. This layer is then sampled, used to set the foreground colour which is then used to fill the colour layer. This part of the process is now almost instantaneous.

The Decompose/Recompose procedure (used to remove an alpha channel) seems to only increase linearly with the size of the image. In the case of this very large image this process took about 20 seconds.

I have tested the plug-in on about 30 images and the results appear to be identical to those obtained previously.

The file and the tutorial have been updated to reflect the changes.

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 12:57 pm

I tried it out on a photo of myself that has obvious "color cast" issues.
Seems to have worked alright.
Image
My only criticism would be that there is only one option/variable to choose from.

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 2:46 pm

@Wallace,

I am still exploring the possibilities of this plug-in.
In addition to being able to adjust the contrast by changing the opacity of the Contrast layer and the amount of colour correction by using Colours/Saturation on the Colour layer, the base layer can be altered using Curves, Saturation, or any of the options in the Colour menu.

2101_122811_1141b_1.jpg
2101_122811_1141b_1.jpg (102.82 KiB) Viewed 654 times

Re: Colour Cast Reduction Plug-in

Sun Jun 25, 2023 3:06 pm

david wrote:@Wallace,

I am still exploring the possibilities of this plug-in.
In addition to being able to adjust the contrast by changing the
opacity of the Contrast layer and the amount of colour correction
by using Colours/Saturation on the Colour layer,
the base layer can be altered using Curves, Saturation,
or any of the options in the Colour menu.

It seems to capture the colors pretty closely.
Even though the cast was pretty bad.
Do you think being able to sample the color cast would help any?

Re: Colour Cast Reduction Plug-in

Mon Jun 26, 2023 1:09 am

Hi David.

To consider:
You have a slight inconsistency in your code execution

If use "Stretch Contrast: No " orginal layer remains (and as far as possible should always remain)
If use "Stretch Contrast: Yes" orginal layer is deleted

You can replace line 144 - 146

Code:
   pdb.gimp_image_remove_layer(image, layer)

   name =pdb.gimp_drawable_set_name(layer_copy1, name)


to:
Code:
   if stretch == "No":   
      pdb.gimp_image_remove_layer(image, layer_copy1)
   
   # name =pdb.gimp_drawable_set_name(layer_copy1, name)


However, a better solution would be to include work on multiple layers (for the selected active layer):
If use "Stretch Contrast: Yes" the layers structure is correct
If use for layers "Stretch Contrast: No" the layer structure is incorrect
Requires moving the layer_copy1 to the top before executing the actual code
behind the line:
Code:
   pdb.gimp_image_insert_layer(image,layer_copy1,None,0) # insert layer

add
Code:
   if stretch == "No":   
      pdb.gimp_image_raise_item_to_top(image, layer_copy1)


and delete two lines:
Code:
    pdb.gimp_image_remove_layer(image, layer_copy1)
    name =pdb.gimp_drawable_set_name(layer_copy1, name)

Re: Colour Cast Reduction Plug-in

Mon Jun 26, 2023 4:05 am

@MareroQ,

I have spent a couple of hours going through the code this morning and I fail to see the problem!

It is version 6 that you are commenting on?

The original image (possibly with an alpha channel which must be removed) is used as a source for layer_copy1 (which then becomes the working base image). It is only retained to transfer its name to layer_copy1 at the end of the program and is then deleted.

I wrote it this way because it allowed me to do comparisons with the original image during the development process.

If stretch is "Yes", layer_copy1 is stretched, if "No" it remains unaltered.

Re: Colour Cast Reduction Plug-in

Mon Jun 26, 2023 4:10 am

@Wallace,
In order to capture the colour cast you have to find it! You would have to know some point on the image which should be neutral in colour so that the colour at that point is the colour cast.

Re: Colour Cast Reduction Plug-in

Mon Jun 26, 2023 9:57 am

I used version 1.6.
Start from single layer: sample_lena.png
Results

Image

Image

You talk about a comparison - but the original no longer exists.


About alpha channel.
You wrote:
...The original image (possibly with an alpha channel which must be removed)....
It is understandable that I have to remove it manually?

...but in the manual col_cast_reduction_tut.pdf:
...If there is an existing selection it is saved to a channel and re-instated after the plug-in has run.
The plug-in decomposes the image to RGB and recomposes to a new layer. This is to eliminate any alpha channel which would have the effect of diluting the colour cast correction. If there is an alpha
channel it is re-instated after the plug-in has run
Any pre-existing selection and alpha channel are added back to the image...



Yet another possibility:
You can start by moving the active layer (especially useful when starting with an image with multiple layers) to a new image (adding a simple code snippet).

All that I wrote is insignificant trifles because what counts is the main function. :bigthup

Re: Colour Cast Reduction Plug-in

Mon Jun 26, 2023 10:40 am

@MareroQ,
Thanks for your reply. Apologies for being so slow to catch your meaning.

However, the way I have coded this is intentional. When Stretch Contrast is beneficial for an image, I wish the Colour layer and the Contrast layer to work on the stretched base layer.

The reason for renaming the base layer to the original image name was for convenience in saving or export. Perhaps I should, instead, consider adding a suffix to the name in all cases so that it has a new name. But a name which is relates to the original.

Re: Colour Cast Reduction Plug-in

Tue Aug 22, 2023 5:22 am

Yet another revision to the colour cast reduction plug-in!

This time it is by elimination. By using pdb.gimp_layer_flatten(layer_copy1) I was able to eliminate the decompose/recompose routine I had previously used to remove the alpha channel.
The contrast layer has also been removed, as adjustments to contrast, brightness, etc. can be done on the base layer after the plug-in has been run.
Altering the saturation of the colour layer will vary the colour cast.

Testing on a .TIFF file of 72.6MB it now runs in under 10 Seconds.

col-cast-reduction.zip
(2.93 KiB) Downloaded 30 times
Post a reply