Page 1 of 3

How to change contrast

Posted: 2012-03-28T02:26:00-07:00
by VanGog
How to change contrast of image? What I want to do, see the attachments here:

http://www.fsdeveloper.com/forum/showth ... p?t=215921
The three last images shows the original photos, and I want to set the contrast a little bit up.

To reach the effect as on the attachments above (2nd and 4th image from left) I used Photoshop levels:
http://www.photoshopessentials.com/imag ... og-box.gif
The gray and the white slider. I shifted the gray slider from mid just a little to right and the white to left. How to reach same effect in IM?

Re: How to change contrast

Posted: 2012-03-28T09:36:39-07:00
by fmw42
IM has many ways to achieve contrast change. The basic one that is like PS levels is IM -levels blackpoint,whitepoint,gamma. It is not interactive, but you can achieve similar results. The middle slider in PS is the gamma parameter. The right slider is the whitepoint value. Get your values from PS and start with the same values for the IM arguments for -level.

see
http://www.imagemagick.org/script/comma ... .php#level

Other ways, are -auto-level, -auto-gamma, -gamma, -evaluate pow, -brightness-contrast, -sigmoidal-contrast, etc

Re: How to change contrast

Posted: 2012-03-28T09:57:16-07:00
by VanGog
Thanks, I'll try

Re: How to change contrast

Posted: 2012-05-17T12:14:54-07:00
by VanGog
Hello,
can you help me with this? I tried contrast correction but found one problem.

The original image was low contrast so I tried to correct.

Code: Select all

convert photo.bmp -level 0,212,0.87 photo.bmp
I have uploaded images of details from the image. To compare original and the change. First image in the group is original, the second is result and the third is the same image with marks of the places where I see the problem.

detail A
http://imagenic.net/viewer.php?file=wwt ... wvbbzy.jpg
http://imagenic.net/viewer.php?file=7al ... tt0nz6.jpg
http://imagenic.net/viewer.php?file=w5c ... sgha4l.jpg

detail B
http://imagenic.net/viewer.php?file=dyg ... igow59.jpg
http://imagenic.net/viewer.php?file=fv5 ... wvzxri.jpg
http://imagenic.net/viewer.php?file=wgv ... 2a1yh3.jpg

detail C
http://imagenic.net/viewer.php?file=jzm ... u5amr1.jpg
http://imagenic.net/viewer.php?file=osw ... ypxfm7.jpg
http://imagenic.net/viewer.php?file=kjy ... 5lbnit.jpg

In all the demonstrations I have problems with greens. When the green is too light and intensive so it looks unnatural.

In the detail A) There seems to me loo light the green and too intense.
In the detail B) the greens have expanded to light places like roads and white areas have strong tone of green.
In the detail C) there are again the light green area which gets too light and the yellow light area seem a litte bit more lighter.

Problem is that I need to get the contrast in the photo higher because darker areas of grass, trees need better contrast and the buildings too. So If I would discreased the contrast to get rid of the greens in roads and too intensive light greens so the trees and dark grass would be too dark and without contrast.

Can you pleas help me to fix the problem?

Originals once more to download here:
http://i47.tinypic.com/2qwzmom.jpg
http://i48.tinypic.com/333vjh1.jpg
http://i48.tinypic.com/fp2qo6.jpg

Re: How to change contrast

Posted: 2012-05-17T13:58:47-07:00
by fmw42
convert photo.bmp -level 0,212,0.87 photo.bmp
The values for blackpt and whitept in -level (0 and 212) will depend upon the compile version of IM. Those values are fine if you are using Q8 (8-bit) compile as values then range from 0 to 255. But if you are using Q16 compile (16-bit), then values are in the range 0-65535. That is why I typically use percents rather than raw values.

I don't believe that you specified what version of IM and what quantum level. Please let us know. Also do you have pictures from how it gets correctly processed if by Photoshop if that is your comparison or whatever you think is the correct result. IM -level is not quite the same as levels in Photoshop. It does not include clipping or output graylevel control. You can add clipping by using IM -contrast-stretch. Output graylevel control can be done with IM +level

If you are using PS, then please look at the Levels control window Options to see what the clip values are set to. That may be the difference as I recall that PS uses something like 0.1% clip.

If you need to control green or each channel separately, then add -channel ... before -level and it will only change the channels specified, if I recall correctly.

My script, levels, below does include those.

Re: How to change contrast

Posted: 2012-05-17T14:41:23-07:00
by VanGog
It is ImageMagick-6.7.5-Q8 . I used settings from PS.

The result is very similar to PS. I see no differences there.

I did not succeed to get ideal result in PS. I don't know how to do it. If I would want to correct the color for the roads, I would load the configuration mentioned above in the levels window and would change yellow gamma to 1.35, but I cannot to apply it because the contrast of the grass, trees, rivers and ponds would be too low. The yellow make the greens vivid.

I could post some "correct" pictures of the details but not whole image because one change of contrast will effect the rest of image.

Here is the image, how the road could look:
http://i48.tinypic.com/90n7g0.jpg
the second one is more close to ideal. Maybe it could have more yellows, but I suppressed them to leave the green tones.

Re: How to change contrast

Posted: 2012-05-17T14:51:08-07:00
by fmw42
try using whitebalance or autowhite with or without the -level first. see my script below. The key function in both these scripts is -recolor (now -color-matrix).

autowhite by itself seems to work fine in my opinion, but I am not sure if that is all that you need changing. I changed the name of your file for ease in use.

Original:

Image

autowhite road.jpg road_white.jpg

Here is the result

Image

Re: How to change contrast

Posted: 2012-05-17T15:04:13-07:00
by VanGog
another thing is the light greens problem.

When I will take the original image "A" and the changed image "A" (has too light greens) I will select the light greens in the images:
- #78aa61 in the original
- and #88c568 in the changed image
Then I copy and paste. 1st I paste the lightgreens from #88c568 selection, and then I paste the darker greens from #78aa61 selection. So I have three layers now.
To the second layer I set 75% visibility and to the third layer, the darker one, I set 60% visibility. So I got the result http://i47.tinypic.com/4trsl4.jpg
that looks good.

Re: How to change contrast

Posted: 2012-05-17T15:15:26-07:00
by VanGog
Thanks for your solution to the first problem. It looks great.

In the second example I confused layers. It should be the changed layer as the base layer. Then the selected colors from the darker layer... probably this would be enough.

I must go sleep now because I am tired

Re: How to change contrast

Posted: 2012-05-17T15:16:39-07:00
by VanGog
Thanks for your solution to the first problem. It looks great.

In the second example I confused layers. It should be the changed layer as the base layer. Then the selected colors from the darker layer... probably this would be enough.

I must go sleep now because I am tired. I will try it tomorrow.

Re: How to change contrast

Posted: 2012-05-17T15:42:46-07:00
by fmw42
You will have to explain the second problem a little more. I do not follow. Can you give your command line?

Re: How to change contrast

Posted: 2012-05-17T23:55:47-07:00
by VanGog
Yet I haven't command for the second problem. This was description for Photoshop, Again, this description is similar, but it is new, not the same as what I had written yesterday.

The idea is to create temporary file (lighter.bmp) with higher contrast. And temporary file (darker_colors.bmp) with light green colors from the original (this greens are darker then in the lighter.bmp). Then overlap the darker colors from the selection over the image with higher contrast (over lighter.bmp). The overlay transparency should be maybe 40, 50 or 60%. I did not tried yet. But in the result, the image with better contrast, will have this area just a little bit lighter, not too much.

1) So the first command to generate lighter.bmp is

Code: Select all

convert photo.bmp -level 0,212,0.87 lighter.bmp
2) now I should select dark green colors of #82b068 from the photo.bmp
and save them as darker_colors.bmp

3) Then make the final step of the overlay.

I should help myself with the first two steps, but don't know how to do the 3rd action.

But maybe you know better way then exporting the selected colors to new file.

Edit:
I test the command now with jpg sample:

Code: Select all

convert test.jpg -level 0,212,0.87 lighter.jpg
convert test.jpg -fuzz 25% -fill black +opaque #82b068 darker_colors.jpg
So I created mask. Now the final step, will you help me with it? And could we use Memory Program Register instead writing data to temporary file? (-write ... mpr:)
I already used it once but forgot how to use it.

Re: How to change contrast

Posted: 2012-05-18T09:27:10-07:00
by fmw42
I tried your commands on the road image and get very strange results that I do not think will work well. The lighter image is nearly all white. The darker image has very dark spots in the road.

Perhaps it would be better to point me to the Photoshop tutorial to see what they are doing.

Perhaps increasing and decreasing the saturation might do what you want rather than the contrast. But if you want contrast changes, see -brightness-contrast. If you need to combine them you can just use -compose blend -composite with the desired mixing percent. Also you can make a mask that selects just the green shade, probably from the Hue image (from -colorspace HSB or HSL). Use the same mask with both the lighter and darker images to affect the blend, so that only the greens are affected. Just some ideas.

Get the individual commands to do what you want, before trying to make the process quicker. You can often put it all in one command line later using clones. That is likely nearly as fast as mpr, which often requires special circumstances to use, when clones do not work.

Re: How to change contrast

Posted: 2012-05-18T10:00:53-07:00
by VanGog
OK, I created a video demonstration. I uploaded the video and photos with a generate.bat script. Plsease click on "Stahnout" to Download the file. http://ulozto.cz/xaiZh42/test-rar

Note:
On the video, I open new brighter file, Then I open the darker file with a black color. From there I copy the image and paste it to the original file (correction: paste it to the lighter file). I delete the black pixels. I change opacity. It was fast so I did not take care about precision. But the result is there.

Re: How to change contrast

Posted: 2012-05-18T10:49:06-07:00
by fmw42
OK. Thanks for the video and the images. Let me work on this, but I need to do some errands. So I probably cannot get back to you until later today or tomorrow. By the way, what tool were you using to create your work? You did not show how you got the lighter and darker images. What functions in that tool were you using?