Page 2 of 3

Re: Fit one image on its place on another image

Posted: 2010-05-29T10:27:58-07:00
by fmw42
you can adjust the background image so that the card is white by using -recolor or possibly modulate
see http://www.imagemagick.org/Usage/color/#recolor

NOTE: apparently -recolor is now deprecated in favor of an improvement now called -color-matrix
see http://www.imagemagick.org/script/comma ... lor-matrix

for brightness/contrast, see -level, +level, -brightness-contrast, -auto-level, modulate (can also shift hues), etc

for shadows, there is no really good way, but see http://www.imagemagick.org/Usage/distorts/#shadow3d


for correct control points, see image coordinates vs pixel coordinates at http://www.imagemagick.org/Usage/distor ... rol_points

most things with examples can be found at http://www.imagemagick.org/Usage/ (good reading for beginners)

Re: Fit one image on its place on another image

Posted: 2010-05-29T13:40:06-07:00
by Fludimir
I've tried +level 10,135 and -level 10,235 , and only got white or black paper instead of image. -brightness-contrast works fine, so I'm using it , but it would be great to explain how to use +-level
Recolor or Color-Matrix looks something strange , I want only add some blue tint, is there any simplest way? I have rgb(209,244,248) color on white paper, so I only want white color of my overlaying image turn to rgb(209,244,248), and of course other colors should be corrected too. What option I have to use to get such result? I can get slightly similar result with adding -fill "rgb(209,244,248)" -tint 90 , this looks good but actualy is not that what I've tried to do

Yeah, thanks, I get a lot of usefull examles from docs-usage, but not all explained well and some questions I have to ask here. Thanks for help

Re: Fit one image on its place on another image

Posted: 2010-05-29T16:06:35-07:00
by fmw42
-tint will add color, but I thought you wanted to take out the blue tint in the card?

To do that, use -color matrix with a 3x3 matrix. The values of the matrix are all zero except the diagonal. The diagonal values are the r, g and b ratios between the desired color and old color. So get the 8-bit (0-255) color of the card for the denominator values and use white (r=g=b=255) for the numerator.

convert image -color-matrix "$redfrac 0 0 0 $greenfrac 0 0 0 $bluefrac" result

also see viewtopic.php?f=1&t=15564&start=0&hilit=recolor

-level will increase brightness and or contrast. if you just want it brighter use -level 0x80% will increase brightness by about 20% and increase some contrast. You are basically changing the slope and intercept of a straight line transformation between input and output values. see http://www.imagemagick.org/Usage/color/#level the examples are pretty straight forward.

+level will decrease brightness and or contrast

Re: Fit one image on its place on another image

Posted: 2010-05-29T18:24:21-07:00
by snibgo
I've tried +level 10,135 and -level 10,235 , and only got white or black paper instead of image.
I suspect you are using Q16 (16-bit) ImageMagic, and those values are very small compared to 65535.

It is generally not good to assume any particular Q-value. Instead, express values as percentages. 10 is 3.9% of 255, and 135 is 52.9%, so try "+level 3.9%,52.9%"

... so I only want white color of my overlaying image turn to rgb(209,244,248) ...
The "white" paper is darker than her collar, so you might prefer a particular gray (not pure white) to turn to rgb(209,244,248). Suppose you want rgb(220,220,220) to turn to that blue. Then set redfrac = 209/220 = 0.95, etc. Invert the fraction to turn blue into grey.

Re: Fit one image on its place on another image

Posted: 2010-05-29T18:33:24-07:00
by Fludimir
I've got perfect result with color-matrix, thanks

Looked into http://www.imagemagick.org/Usage/color/#level , level correction that I need is something like -level -16% . Actually I wanted to do this http://i5.fastpic.ru/big/2010/0530/2d/a ... efdd2d.jpg , -level -16% works almost similarly.
I tested this on a single image - works well . But in full commandline it didn't works, strange for me. Also I have problems with alpha-mask for photo, it works well separately, but didn't works together with other parameters.

Here is commandline that works well:

Code: Select all

convert bg.jpg  ( bull.jpg -virtual-pixel transparent -background none -gravity northwest -extent 1920x1088 -distort Perspective "0,0 435,17 475,0 912,192 475,595 802,962 0,595 268,865 0,0 432,16"  -auto-level -brightness-contrast 0,-16 -color-matrix ".816 0 0 0 .953 0 0 0 .968" )  bgmask.jpg -composite result.jpg
I tried to replace -brightness-contrast with -level

Code: Select all

convert bg.jpg  ( bull.jpg -virtual-pixel transparent -background none -gravity northwest -extent 1920x1088 -distort Perspective "0,0 435,17 475,0 912,192 475,595 802,962 0,595 268,865 0,0 432,16"  -auto-level -level -16% -color-matrix ".816 0 0 0 .953 0 0 0 .968" )  bgmask.jpg -composite result.jpg
And -level didn't works - I can remove it or set custom value and result images are equal . Why?

Also I tried to add alpha-mask to bull.jpg before distorting it..

Code: Select all

convert bg.jpg  ( ( bull.jpg  bull_mask.jpg  -alpha Off  -compose Copy_Opacity -composite ) -virtual-pixel transparent -background none -gravity northwest -extent 1920x1088 -distort Perspective "0,0 435,17 475,0 912,192 475,595 802,962 0,595 268,865 0,0 432,16"  -auto-level -brightness-contrast -8,-16 -color-matrix ".816 0 0 0 .953 0 0 0 .968" ) -composite result.jpg 
As a result I have bg image with blank paper. But this works fine separately:

Code: Select all

convert bull.jpg  bull_mask.jpg  -alpha Off  -compose Copy_Opacity   -composite  result.png
Here is archive with all images used in commandline

I suspect you are using Q16 (16-bit) ImageMagic, and those values are very small compared to 65535.
It is generally not good to assume any particular Q-value. Instead, express values as percentages. 10 is 3.9% of 255, and 135 is 52.9%, so try "+level 3.9%,52.9%"
Oh, I didn't draw much attention on it, thanks

Re: Fit one image on its place on another image

Posted: 2010-05-29T19:02:46-07:00
by fmw42
I need is something like -level -16%
-level does not allow negative values. If you want to reduce brightness or contrast use +level 16% see http://www.imagemagick.org/Usage/color/#level_plus

Re: Fit one image on its place on another image

Posted: 2010-05-30T01:51:11-07:00
by Fludimir
Tried +level 16% in whole commandline - result is the same, that is nothing changed, level correction didn't works

Re: Fit one image on its place on another image

Posted: 2010-05-30T15:36:25-07:00
by fmw42
You probably need two values in -level or +level

try

+level 0x84% or + level 16x84%

or

-level with the same arguments. Sorry I really don't know what you are trying to achieve here. You need to play some with -level and +level after studying the docs (best to use % arguments). Or just go with -contrast-brightness if that works for you.

Re: Fit one image on its place on another image

Posted: 2010-05-30T17:09:07-07:00
by fmw42
If you just want to brighten or darken and image (no contrast change), then use -modulate XX,100,100 where xx=100 is no change, xx=120 is 20 percent brighter and xx=80 is 20 percent darker. -modulate B,S,H (where B is brightness, S is saturation and H is hue). So you can adjust the hue as well if you want.

see http://www.imagemagick.org/Usage/color/#modulate

Re: Fit one image on its place on another image

Posted: 2010-05-30T17:45:23-07:00
by fmw42
NOTE:

-level LxH% stretches graylevel L to black and graylevel H to white (where graylevels are specified as % of quantumrange for your IM compile , i.e 0% is black and 100% is white)

+level LxH% stretches black to graylevel L and white to graylevel H

Perhaps that makes it more clear.

Re: Fit one image on its place on another image

Posted: 2010-05-30T17:48:54-07:00
by Fludimir
I've played with levels on custom image, after explanation it works fine, thanks.
+level LxH% stretches black to graylevel L and white to graylevel H
Yeah, this is exactly that what I wanted to do

Now I have only problem with this
Also I tried to add alpha-mask to bull.jpg before distorting it..
Code: Select all
convert bg.jpg ( ( bull.jpg bull_mask.jpg -alpha Off -compose Copy_Opacity -composite ) -virtual-pixel transparent -background none -gravity northwest -extent 1920x1088 -distort Perspective "0,0 435,17 475,0 912,192 475,595 802,962 0,595 268,865 0,0 432,16" -auto-level -brightness-contrast -8,-16 -color-matrix ".816 0 0 0 .953 0 0 0 .968" ) -composite result.jpg

As a result I have bg image with blank paper. But this works fine separately:
Code: Select all
convert bull.jpg bull_mask.jpg -alpha Off -compose Copy_Opacity -composite result.png


Here is archive with all images used in commandline

Re: Fit one image on its place on another image

Posted: 2010-05-30T17:57:38-07:00
by snibgo
The compose method is changed to Copy_Opacity, so that's what the final composite uses. If it should be "compose over", you have to explicitly set it.

Re: Fit one image on its place on another image

Posted: 2010-05-30T18:13:33-07:00
by fmw42
It seems to me that you need to create a mask of the fingers from the background image and then use the mask to composite the result of perspective with the original image so the fingers then cover the perspective image overlay.

Re: Fit one image on its place on another image

Posted: 2010-05-31T18:33:34-07:00
by fmw42
Here is what I think you may want.

I renamed your two images as bg.jpg and fg.jpg for simplicity. Then I created a mask from bg.jpg (same size as bg.jpg)

http://www.fmwconcepts.com/misc_tests/p ... _mask3.gif

convert bg.jpg \( +clone \
\( fg.jpg -background none -virtual-pixel transparent +distort perspective \
"0,0 434,17 474,0 910,192 474,594 803,957 0,594 268,868 " \) \
-layers merge \) +swap bg_mask3.gif -compose over -composite bg_fg.jpg

http://www.fmwconcepts.com/misc_tests/p ... /bg_fg.jpg

Re: Fit one image on its place on another image

Posted: 2010-06-01T19:27:17-07:00
by anthony
Hmmm looking over this topic. I would like to make one suggestion.

Using the images found in the RAR archive download

First as already mentioned use +distort.

Second as +distort generates a 'layer' image with a virtual canvas, you really want to use -flatten or -layers merge to merge the images together. That way your perspective control points offset will still line up right.

Only one mask is needed, and that is probably the background mask. It should also be black everywhere you need transparent, but you can work around that.

To generate the overlay with distorting and masking is...

convert bull.jpg -alpha set -virtual-pixel transparent \
+distort Perspective "0,0 435,17 475,0 912,192 475,595 802,962 0,595 268,865 0,0 432,16" \
\( bgmask.jpg -alpha Shape \) +swap -compose In -flatten \
distored_masked_overlay.png

Now when overlaying I would multiply the images together so that the tinting present on the 'white page' of the original image is merged with the overlay.

convert distored_masked_overlay.png \
bg.jpg -compose multiply -composite \
result.jpg

The mask looks like it could do with a little more work, and I'll leave you with color tiniting.

PS: PLEASE break up your commands using multiple lines as I show above. It makes it far far easier to follow exactly what you are doing!