How to change contrast

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

I did not realized you used different image than me. I used the image detail "A".

I just run the program generate.bat I forgot it to run, but I wanted the video to be short. See the script for commands.

The program is called ScreenVCR or Screen Video Recorder. It is free for 14 days. You must set full screen in options to use it for full screen.

Edit:
I read your last post again and I think what tool do you mean. Do you mean the scipt or the editor?

The script uses these commands:

Code: Select all

convert original.jpg -level 0,212,0.87 lighter.jpg
convert original.jpg -fuzz 25% -fill black +opaque #82b068 darker_colors.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change contrast

Post by fmw42 »

First I am not on Windows. So I cannot run you bat file. The tool I meant was your image editor that allowed you to create the lighten and darken images and then composite them. The one you used in the video, not the video recording tool.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change contrast

Post by fmw42 »

Try this:


convert original.jpg \
\( -clone 0 -level 0,83%,.87 \) \
\( -clone 0 -fuzz 15% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black \) \
-compose over -composite result15.jpg

Try also with fuzz 10%.

Note I adjusted your fuzz value for this image. I also converted your level value of 212 to percent since I am on Q16 and level values range from 0 to 65535.

Note also that in the second step I added -fuzz 0 fill white +opaque black to make the image a binary b/w mask. Then used that to composite the the lighter with the original so that the light green areas are made lighter.

If you want to adjust the mixing, you can change the transparency/opacity of the lighter image by adjusting the alpha channel.


convert original.jpg \
\( -clone 0 -level 0,83%,.87 -alpha set -channel a -evaluate set 50% +channel \) \
\( -clone 0 -fuzz 15% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black \) \
-compose over -composite result15_50.jpg

See
http://www.imagemagick.org/Usage/color_basics/#replace
http://www.imagemagick.org/Usage/transf ... aluate_set
http://www.imagemagick.org/Usage/canvas/#other (transparency)
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/masking/#alpha
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#seq_combine
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

I had problem with your command, so I changed the level back to my setting to work. Also I have increased the fuzz, because it was not selected enough.

Here is how it looked when I increased fuzz:
http://i46.tinypic.com/2jg81p5.jpg

The overlay method does not look good to me, so I tried blending method which you recommended to me. But I do know know how to write it correctly here so it does not work:

Code: Select all

convert original.jpg ^
 "(" -clone 0 -level 0,212,0.87 ")" ^
 "(" -clone 0 -fuzz 25% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black ")" ^
 -compose blend -define compose:args=50 -composite
This is on Windows and I changed the \( to "(" to work the command.

Edit:
Ah, I must add the alpha channel. OK. So the first command works now. And could we try the blend command if it could work?

One more thing I had to change in the script. Not the +opaque but -opaque to get the higher contrast on whole image.

Code: Select all

convert original.jpg ^
 "(" -clone 0 -level 0,212,0.87 -alpha set -channel a -evaluate set 68% +channel ")" ^
 "(" -clone 0 -fuzz 25% -fill black -opaque "#82b068" -fuzz 0 -fill white -opaque black ")" ^
 -compose over -composite repaired.jpg
But the result is still not as I intended. For some reason the black area which is black in mask (see darker_colors.jpg) has too suppressed contrast now. I originally wanted the image to have higher contrast, but the result is almost unnoticeable. Only the area which has higher brightness of greens should to be suppressed.

As far as I understand to your command, you changed contrast only to the light greens? But what I want is to change contrast to whole image, and the areas which would be too light green would be overlayed cca 60%-68% of the original lightgreen selection.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change contrast

Post by fmw42 »

I really do not know what to tell you. I watched your video and that seemed to be what you were doing. To be able to repeat your process, you will need to capture each step you perform on your other system and provide all those images with comments about what you did for each.

With regard to my command, you do not need (and perhaps should not have) double quotes around the parenthesis. In windows, parens do not need escapes nor quotes and the end of line \ needs to be changed to ^ as you have done. Also % needs to be %%. And hex colors need to be in double quotes.

Also you must not change +opaque to -opaque otherwise, you do not get a binary mask. See your video. It turns the darker image into a binary mask and seems to composite the lighter image over the original using the mask to only change where the mask is white corresponding to the lightened green regions.

Try this.

convert original.jpg ^
( -clone 0 -level 0,83%%,.87 ) ^
( -clone 0 -fuzz 15%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black ) ^
-compose over -composite result15.jpg

And

convert original.jpg ^
( -clone 0 -level 0,83%%,.87 -alpha set -channel a -evaluate set 50%% +channel ) ^
( -clone 0 -fuzz 15%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black ) ^
-compose over -composite result15_50.jpg

You can play with the fuzz 15 to change it as desired (and the -evaluate set 50 for the mixing)
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

Sorry but it absolutely does not give sense to me, and I do not understand the command. I use your last command.

I compare three images. "original.jpg", "lighter.jpg" and the resulting image.
Center on top of the screen. "lighter.jpg" has lighter trees (not all but the young trees looks a bit lighter). The change is almost unnoticeable. But if you switch these too images more times, you should see it. Also the fields at top at center are a bit lighter. If I see the the resulting image, I do not see it.

In the video tutorial, I have copied the "darker_colors" to paste the layer over the background lighter image. I deleted the black pixels from the darker image, so the lighter background (the fields and young trees) should to be visible on the screen. I also did 12 different results ale all these images stays same color in this area. So I am confused why.

I do not fully understand how the command works. How works the mask in your command. I see there 3 source arguments:
1) original.jpg
2) ( -clone 0 -level 0,83%%,.87 ) ... copy of the original.jpg with higher contrast
3) the mask ...
Does it mean that is there are three arguments, so the 3rd one is a mask?
I heard only about two arguments to get the blend. The mask is binded to compose or to composite?

Sorry for taking your time.
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

fmw42 wrote:See your video. It turns the darker image into a binary mask and seems to composite the lighter image over the original using the mask to only change where the mask is white corresponding to the lightened green regions.
No no no. It is like this:
It turns the darker image (has the colors from original) into a binary mask and composites the darker image over the lighter image. It means that the original is pasted over lighter image, but the area which is not light green is deleted.

Edit
I am not too much good on explaining so I hoped that the video could explain better than me.

Now I checked my post from "2012-05-18T10:00:53+00:00 " and I see that I have written error there, so I caused your mistaken :-( I ave written "From there I copy the image and paste it to the original file". Sorry for that. I have written there that I pasted the image to original instead into lighter image. That was my mistake.
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

So I tried my own way because I was not able to do it with the "clone 0".

Code: Select all

convert original.jpg -level 0,89%%,.87 -write mpr:lighter +delete ^
	original.jpg -fuzz 10%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black -write mpr:mask +delete ^
mpr:lighter ^
 ( original.jpg ) ^
 ( mpr:mask ) ^
 -compose blend -define compose:args=40 -composite result15.jpg
Notice - I have changed the gamma for the lighter image because the white colors seems too seed too light!

Code: Select all

convert original.jpg -level 0,92%%,.87 -write mpr:lighter +delete ^
	original.jpg -fuzz 10%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black -write mpr:mask +delete ^
mpr:lighter ^
 ( original.jpg ) ^
 ( mpr:mask ) ^
 -compose blend -define compose:args=40 -composite result15.jpg
Then I changed the white value of contrast to ".93"

So you can compare these images and I think this one is the best:

Code: Select all

convert original.jpg -level 0,92%%,.93 -write mpr:lighter +delete ^
	original.jpg -fuzz 10%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black -write mpr:mask +delete ^
mpr:lighter ^
 ( original.jpg ) ^
 ( mpr:mask ) ^
 -compose blend -define compose:args=40 -composite result15.jpg
Sure I don't know if it is the best method. But the best result I could reach.

You can download the results here to compare the images. The last one with number 22 is the best one.

http://ulozto.cz/xgC3WKA/images-zip
Last edited by VanGog on 2012-05-20T00:41:46-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change contrast

Post by fmw42 »

I do not fully understand how the command works. How works the mask in your command. I see there 3 source arguments:
1) original.jpg
2) ( -clone 0 -level 0,83%%,.87 ) ... copy of the original.jpg with higher contrast
3) the mask ...
Does it mean that is there are three arguments, so the 3rd one is a mask?
I heard only about two arguments to get the blend. The mask is binded to compose or to composite?

Sorry for taking your time.
You can have 3 images for composite, the last one being the mask. see
http://www.imagemagick.org/Usage/compose/#compose

I do not understand why you cannot use clones. What was your command line? Did you leave space between the parens and the rest of the command. Did you put -clone 0?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change contrast

Post by fmw42 »

convert original.jpg -level 0,92%%,.87 -write mpr:lighter +delete ^
original.jpg -fuzz 10%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black -write mpr:mask +delete ^
mpr:lighter ^
( original.jpg ) ^
( mpr:mask ) ^
-compose blend -define compose:args=40 -composite result15.jpg
This should be the clone equivalent.


convert original.jpg ^
( -clone 0 -level 0,92%%,.87 ) ^
( -clone 0 -fuzz 10%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black ) ^
-swap 0,1 -compose blend -define compose:args=40 -composite result15.jpg


So the reason my results were not correct was that you wanted the overlay the opposite way with the original over the lighter rather than what I had thought was the lighter over the original. The same should be achieved by -negate on the mask (though I am seeing some slight difference. I am not sure why). So stick with the one above rather than the one below.

convert original.jpg ^
( -clone 0 -level 0,92%%,.87 ) ^
( -clone 0 -fuzz 10%% -fill black +opaque "#82b068" -fuzz 0 -fill white +opaque black -negate ) ^
-compose blend -define compose:args=40 -composite result15.jpg
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

Thanks. Your code really does the same thing. No difference if you set correctly the values. So the swap 0,1 switches the layer 0 layer 1, right?

Yet I would do last variant to the contrast. I want try to add higher contrast (configuration more close to the original configuration), to do the same as we did now, but I would try to add white color selection, same procedure as with the lightgreen. To add one more layer and one more mask. Here I am not sure how to do it because I red that the compose works only with two images.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change contrast

Post by fmw42 »

You do one compose with 3 images (the last being the mask), take the result and do another compose with two more images (the last being the mask). You can just chain them so only one command line is needed. See http://www.imagemagick.org/Usage/layers/#convert
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

Why this command results in 2 images?

Code: Select all

convert original.jpg -clone 0 -level 0,92%,.87 result3.jpg
VanGog
Posts: 308
Joined: 2012-02-05T02:46:58-07:00
Authentication code: 8675308

Re: How to change contrast

Post by VanGog »

I see. Probably because I did not flatten the two levels... Am I right? So this is Layer 0 and Layer 1. It is logical.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change contrast

Post by fmw42 »

VanGog wrote:Why this command results in 2 images?

Code: Select all

convert original.jpg -clone 0 -level 0,92%,.87 result3.jpg
You have cloned (copied) the first image and so now the command line has two inputs and will result in two images labeled -0 and -1, both of which will be identical. Take out the -clone or process the clone in parenthesis differently and then combine them in some way such as compose ... -composite or -background -flatten.
Post Reply