It is currently Tue Jul 02, 2024 3:11 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 17 posts ] 
Author Message
 Post subject: Colour Cast Reduction Plug-in
PostPosted: Tue Jun 20, 2023 10:43 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
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.

Attachment:
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.


Last edited by david on Tue Aug 22, 2023 5:26 am, edited 2 times in total.

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: Colour Cast Reduction Plug-in
PostPosted: Fri Jun 23, 2023 5:34 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
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.


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 1:49 am  (#3) 
Offline
Global Moderator
User avatar

Joined: Apr 01, 2012
Posts: 7744
Location: On the other side of this screen
What about creative commons licences?

_________________


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 2:47 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
@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.


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 2:54 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
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!

Attachment:
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.


Last edited by david on Sun Jun 25, 2023 11:16 am, edited 1 time in total.

Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 3:30 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Mar 01, 2014
Posts: 12707
Location: Spain, Aragón
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

_________________
Image

Gimp 2.10.30(samj) portable _ OS Windows 10 Home_ 64bits
Don’t be afraid to start over. It’s a new chance to rebuild what you want.


Last edited by Issabella on Sun Jun 25, 2023 3:49 am, edited 1 time in total.

Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 3:46 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Sep 27, 2016
Posts: 345
Location: Germany, BW
Thank you david. Might come in handy sometime.

_________________
Regards
nelo

(Gimp 2.10 on Linux Mint MATE 20.1)


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 11:29 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
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.


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 12:57 pm  (#9) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13068
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
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.

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 2:46 pm  (#10) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
@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.

Attachment:
2101_122811_1141b_1.jpg
2101_122811_1141b_1.jpg [ 102.82 KiB | Viewed 644 times ]


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Sun Jun 25, 2023 3:06 pm  (#11) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13068
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
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?

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Mon Jun 26, 2023 1:09 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
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

   pdb.gimp_image_remove_layer(image, layer)

   name =pdb.gimp_drawable_set_name(layer_copy1, name)


to:
   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:
   pdb.gimp_image_insert_layer(image,layer_copy1,None,0) # insert layer

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


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

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Mon Jun 26, 2023 4:05 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
@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.


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Mon Jun 26, 2023 4:10 am  (#14) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
@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.


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Mon Jun 26, 2023 9:57 am  (#15) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
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

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Mon Jun 26, 2023 10:40 am  (#16) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
@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.


Top
 Post subject: Re: Colour Cast Reduction Plug-in
PostPosted: Tue Aug 22, 2023 5:22 am  (#17) 
Offline
GimpChat Member
User avatar

Joined: Nov 15, 2014
Posts: 866
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.

Attachment:
col-cast-reduction.zip [2.93 KiB]
Downloaded 30 times


Top
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Colour Cast Script

0

No new posts Attachment(s) Noise reduction?

11

No new posts Attachment(s) Don't work procedures plug-in-bump-map, plug-in-displace

2

No new posts Change Foreground Colour

0

No new posts Attachment(s) Bleed Colour to Alpha

3



* Login  



Powered by phpBB3 © phpBB Group