Fit one image on its place on another image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
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)
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
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
-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
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Fit one image on its place on another image
I suspect you are using Q16 (16-bit) ImageMagic, and those values are very small compared to 65535.I've tried +level 10,135 and -level 10,235 , and only got white or black paper instead of image.
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%"
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.... so I only want white color of my overlaying image turn to rgb(209,244,248) ...
snibgo's IM pages: im.snibgo.com
Re: Fit one image on its place on another image
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:
I tried to replace -brightness-contrast with -level
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..
As a result I have bg image with blank paper. But this works fine separately:
Here is archive with all images used in commandline
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
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
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
Code: Select all
convert bull.jpg bull_mask.jpg -alpha Off -compose Copy_Opacity -composite result.png
Oh, I didn't draw much attention on it, thanksI 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%"
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
-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_plusI need is something like -level -16%
Re: Fit one image on its place on another image
Tried +level 16% in whole commandline - result is the same, that is nothing changed, level correction didn't works
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
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
see http://www.imagemagick.org/Usage/color/#modulate
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
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.
-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
I've played with levels on custom image, after explanation it works fine, thanks.
Now I have only problem with this
Yeah, this is exactly that what I wanted to do+level LxH% stretches black to graylevel L and white to graylevel H
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Fit one image on its place on another image
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.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
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.
Last edited by fmw42 on 2010-05-31T20:20:29-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fit one image on its place on another image
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Fit one image on its place on another image
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!
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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/