Apply standard brightness/saturation/contrast
-
- Posts: 4
- Joined: 2017-06-07T01:20:12-07:00
- Authentication code: 1151
Apply standard brightness/saturation/contrast
Hi Guys,
I have a dataset of similar images with different levels of saturation, brightness, and contrasts. Is there some way to "normalize" those three factors to force the images to look alike? I mean, I would like to have a standard brightness/saturation and make for example dark images lighter and light images darker
I have a dataset of similar images with different levels of saturation, brightness, and contrasts. Is there some way to "normalize" those three factors to force the images to look alike? I mean, I would like to have a standard brightness/saturation and make for example dark images lighter and light images darker
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Apply standard brightness/saturation/contrast
What version of IM? I'll assume v7. On what platform?
The first step is to define your measurements.
Assuming sRGB images, brightness and contrast might be the mean and standard deviation (SD) of (a) all the channels or (b) the lightness channel of Lab.
Saturation might be the mean value in the C channel of HCL.
Then define what you want those values to be, on a scale of 0.0 to 1.0. For example: mean=0.5, SD=0.16, saturation=0.15.
Then decide how to adjust the images. For example, changing the mean (for all channels, or just one channel) is easily done by raising values to a power:
... which will change the mean value to 0.5.
Changing the SD is harder. I do it by "-sigmoidal-contrast" with trial and error.
The first step is to define your measurements.
Assuming sRGB images, brightness and contrast might be the mean and standard deviation (SD) of (a) all the channels or (b) the lightness channel of Lab.
Saturation might be the mean value in the C channel of HCL.
Then define what you want those values to be, on a scale of 0.0 to 1.0. For example: mean=0.5, SD=0.16, saturation=0.15.
Then decide how to adjust the images. For example, changing the mean (for all channels, or just one channel) is easily done by raising values to a power:
Code: Select all
magick in.ext -evaluate Pow %[fx:log(0.5)/log(mean)] out.ext
Changing the SD is harder. I do it by "-sigmoidal-contrast" with trial and error.
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2017-06-07T01:20:12-07:00
- Authentication code: 1151
Re: Apply standard brightness/saturation/contrast
Hi!
I am using v7 on Mac.
Thanks a lot for your answer! I am quite new on ImageMagick, so barely understood what you said. I will try to find out how to get all those values and them I will come back to this thread.
I am using v7 on Mac.
Thanks a lot for your answer! I am quite new on ImageMagick, so barely understood what you said. I will try to find out how to get all those values and them I will come back to this thread.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Apply standard brightness/saturation/contrast
Useful links for getting started:
http://www.imagemagick.org/Usage/basics/
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/script/comma ... ptions.php
At the risk of confusing you, I'll mention a couple of points.
1. Brightness, contrast and saturation are not independent. Changing any one usually also somewhat changes the others. So if you want a "perfect" result, you may need to iterate.
2. There are simple methods for making one image "look like" another. For example, see my Gain and bias page.
3. If you can show sample images, we can give more specific guidance. You can upload to somewhere like dropbox.com and paste links here.
http://www.imagemagick.org/Usage/basics/
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/script/comma ... ptions.php
At the risk of confusing you, I'll mention a couple of points.
1. Brightness, contrast and saturation are not independent. Changing any one usually also somewhat changes the others. So if you want a "perfect" result, you may need to iterate.
2. There are simple methods for making one image "look like" another. For example, see my Gain and bias page.
3. If you can show sample images, we can give more specific guidance. You can upload to somewhere like dropbox.com and paste links here.
snibgo's IM pages: im.snibgo.com
-
- Posts: 4
- Joined: 2017-06-07T01:20:12-07:00
- Authentication code: 1151
Re: Apply standard brightness/saturation/contrast
Wow, thanks a lot!
I am reading all references that you posted.
To summarize my problem, the ideal image would be something like
http://3.bp.blogspot.com/-awVv7mV3lTs/T ... 00/RG2.JPG
But most of images are like:
http://3.bp.blogspot.com/-EX_Xy-BhIlk/U ... 600/oi.png
https://1.bp.blogspot.com/-mf33JuJWkT0/ ... 1600/2.jpg
http://1.bp.blogspot.com/-0bEWp7P6oIo/U ... M00763.jpg
http://1.bp.blogspot.com/-wnHQ0JrnwPY/T ... C04750.JPG
https://1.bp.blogspot.com/-YIiNIO1NJwI/ ... 4460_n.jpg
https://4.bp.blogspot.com/-Z3KCM6yIT-Q/ ... 1%255D.JPG
I am doing some OCR, so I pre-process those images to make my OCR engine be able to recognize it, I have some filters that are able to remove the green background for example, but in order to do it accurately, the images should have a similar background color.
I am reading all references that you posted.
To summarize my problem, the ideal image would be something like
http://3.bp.blogspot.com/-awVv7mV3lTs/T ... 00/RG2.JPG
But most of images are like:
http://3.bp.blogspot.com/-EX_Xy-BhIlk/U ... 600/oi.png
https://1.bp.blogspot.com/-mf33JuJWkT0/ ... 1600/2.jpg
http://1.bp.blogspot.com/-0bEWp7P6oIo/U ... M00763.jpg
http://1.bp.blogspot.com/-wnHQ0JrnwPY/T ... C04750.JPG
https://1.bp.blogspot.com/-YIiNIO1NJwI/ ... 4460_n.jpg
https://4.bp.blogspot.com/-Z3KCM6yIT-Q/ ... 1%255D.JPG
I am doing some OCR, so I pre-process those images to make my OCR engine be able to recognize it, I have some filters that are able to remove the green background for example, but in order to do it accurately, the images should have a similar background color.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Apply standard brightness/saturation/contrast
You have multiple problems.
1) images with glare (blown out regions that are all white from too much light)
2) blurred images
3) faded images
4) images with uneven illumination
There is not one universal solution. I doubt there is anything you can do about glare. Some sharpening can help if the blur is not too extreme. Faded images could be helped simply by increasing the contrast and/or saturation. Images with uneven illumination may be helped by my unix bash shell script, textcleaner. Some of the sharpening and contrast improvement may be helped by my script, autotune (or simply -auto-level, -auto-gamma, -modulate -- the latter for saturation).
All my scripts at my link below run on Unix-like systems. So that includes Mac OSX. I developed them on Mac OSX.
1) images with glare (blown out regions that are all white from too much light)
2) blurred images
3) faded images
4) images with uneven illumination
There is not one universal solution. I doubt there is anything you can do about glare. Some sharpening can help if the blur is not too extreme. Faded images could be helped simply by increasing the contrast and/or saturation. Images with uneven illumination may be helped by my unix bash shell script, textcleaner. Some of the sharpening and contrast improvement may be helped by my script, autotune (or simply -auto-level, -auto-gamma, -modulate -- the latter for saturation).
All my scripts at my link below run on Unix-like systems. So that includes Mac OSX. I developed them on Mac OSX.
Re: Apply standard brightness/saturation/contrast
Here are comments by me and fmw42 on the StackOverflow instance of this question:
Have you tried the "-normalize" option of ImageMagick? There are more complex methods that produce better results, but you might like the result as a first cut at fixing them. – Glenn Randers-Pehrson yesterday
Just to add a little to Glenn's command, a simple approach is just to stretch the histogram. You can use -contrast-stretch 0% to stretch the histogram to full dynamic range or to clip a little off the dark and light ends of the histogram to stretch it even more. This increases contrast/brightness. -normalize is just -contrast-stretch 2%x1%. See imagemagick.org/script/…. Also -auto-level and -auto-gamma combined are effective and simple. – fmw42 yesterday
Have you tried the "-normalize" option of ImageMagick? There are more complex methods that produce better results, but you might like the result as a first cut at fixing them. – Glenn Randers-Pehrson yesterday
Just to add a little to Glenn's command, a simple approach is just to stretch the histogram. You can use -contrast-stretch 0% to stretch the histogram to full dynamic range or to clip a little off the dark and light ends of the histogram to stretch it even more. This increases contrast/brightness. -normalize is just -contrast-stretch 2%x1%. See imagemagick.org/script/…. Also -auto-level and -auto-gamma combined are effective and simple. – fmw42 yesterday
-
- Posts: 4
- Joined: 2017-06-07T01:20:12-07:00
- Authentication code: 1151
Re: Apply standard brightness/saturation/contrast
Thanks a lot guys, all comments here were really helpful
I am really impressed how autotone just works out of the box, this simple command increased the number of characters recognized in 8%:
Textcleaner however did not work quite well for the type of images that I have.
I still have some corner cases where the background pattern is interfering in the OCR, like this one:
http://imgur.com/a/Mav3q
Is there any way get rid of this background pattern without messing up with the letters?
I have tried to force the letters to be more visible, like:
And also some noise reduction, but no success so far.
I am really impressed how autotone just works out of the box, this simple command increased the number of characters recognized in 8%:
Code: Select all
./autotone -P 80 in.jpg out.jpg
I still have some corner cases where the background pattern is interfering in the OCR, like this one:
http://imgur.com/a/Mav3q
Is there any way get rid of this background pattern without messing up with the letters?
I have tried to force the letters to be more visible, like:
Code: Select all
convert rgfix-7.jpg -fuzz 30% -fill black -opaque '#172126' result.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Apply standard brightness/saturation/contrast
Try something like either of these. Adjust the values as desired
Code: Select all
convert fK1Mz6L.jpg -fuzz 15% -fill black -opaque "#2E303A" -fuzz 0 -fill white +opaque black result.png
Code: Select all
convert fK1Mz6L.jpg -threshold 35% result.png
Re: Apply standard brightness/saturation/contrast
@fred, thanks for autotone. I just updated an old answer of mine on StackExchange to add a link to it:
https://graphicdesign.stackexchange.com ... 7593#77593
Almost immediately I got a downvote. Go figure. I guess they didn't like it being noncommercial use only.
https://graphicdesign.stackexchange.com ... 7593#77593
Almost immediately I got a downvote. Go figure. I guess they didn't like it being noncommercial use only.