putting tile on image background is also changing need help

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?".
sujan.dasmahapatra
Posts: 44
Joined: 2012-02-18T21:42:01-07:00
Authentication code: 8675308

putting tile on image background is also changing need help

Post by sujan.dasmahapatra » 2012-03-04T10:13:21-07:00

I am trying to change the color of a white image with the tiles on another image. i am doing this

Code: Select all

exec("convert 15898.jpg  -normalize  +level 35%  texture.png");
exec("composite texture.png bodynormalclassic.png  -tile -compose Hardlight texture2.png");
exec("convert bodynormalclassic.png -fuzz 50% -transparent white -alpha extract -negate mask.png");
exec("convert bodynormalclassic.png texture2.png mask.png  -composite bodynormalclassic_mod3.png");
Its making the tiles on the image bodynormalclassic.png but my background is also whte so the background is also chaning to the tile pattern. How can I stop the background to change. I want only image to change. Please help me.

User avatar
fmw42
Posts: 22979
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: putting tile on image background is also changing need h

Post by fmw42 » 2012-03-04T12:16:20-07:00

Perhaps you need to post links to your images so we can see what you are trying to do. It is very hard to figure out why code does not work without examples. You should also identify your version of IM and platform. see viewtopic.php?f=1&t=9620

sujan.dasmahapatra
Posts: 44
Joined: 2012-02-18T21:42:01-07:00
Authentication code: 8675308

Re: putting tile on image background is also changing need h

Post by sujan.dasmahapatra » 2012-03-05T04:17:19-07:00

check this link
http://imageshack.us/photo/my-images/5 ... mod3.png/
15898.png is the tile that i want to put on the image "sleevelongnormal.png" the 2 hands sleeves. So I am coding like this. since the sleeves are white so i am trying to change the color white of the image with the tile. but you can see the background of the image is also changing, "sleevelongnormal_mod3.png". Please tell me how can i stop the background to change i want only the sleeves to be with the tiles.

Code: Select all

exec("convert  15898.jpg  -normalize  +level 35%  texture.png");
exec("composite  texture.png sleevelongnormal.png  -tile -compose Hardlight texture2.png");
exec("convert  sleevelongnormal.png -fuzz 50%  -transparent white -alpha extract -negate mask.png");
exec("convert  sleevelongnormal.png texture2.png mask.png  -composite sleevelongnormal_mod3.png");

User avatar
fmw42
Posts: 22979
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: putting tile on image background is also changing need h

Post by fmw42 » 2012-03-05T12:17:15-07:00

this works for me. (note your images got converted to jpeg when uploading). the following is what it should be if not changed to jpeg.


convert 1sleevelongnormal.png 15898.png -compose multiply -composite result.png

User avatar
anthony
Posts: 8880
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: putting tile on image background is also changing need h

Post by anthony » 2012-03-06T01:28:01-07:00

This image definitely needs some type of image map to either displace (relative) or distort (absolute) the image to fit the object being covered.
http://www.imagemagick.org/Usage/mapping/#distort

Working out that map however will be VERY hard, and probably require some artistic work. But once you have that map, any texture can be mapped to the object!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
fmw42
Posts: 22979
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: putting tile on image background is also changing need h

Post by fmw42 » 2012-03-06T12:13:42-07:00

As Anthony suggested, you can try to use the shirt as a displacement map to distort the stripes when placing onto the shirt. See a similar example at viewtopic.php?f=1&t=16921&p=62696&hilit ... irt#p62696


convert 15898.png \( sleevelongnormal.png -blur 0x3 -auto-level \) -alpha set \
-virtual-pixel transparent -compose displace \
-set option:compose:args -20x-20 -composite 1598_displace.png

convert 1598_displace.png 1sleevelongnormal.png -compose multiply -composite sleevelongnormal_disp_comp.png

Image

However, it does not take into account the bent arms. Sorry, but I don't know how to deal with that. Seems you would need a 3D texture mapping system with 3D model of your shirt.

sujan.dasmahapatra
Posts: 44
Joined: 2012-02-18T21:42:01-07:00
Authentication code: 8675308

Re: putting tile on image background is also changing need h

Post by sujan.dasmahapatra » 2012-03-07T04:20:33-07:00

http://imageshack.us/photo/my-images/3 ... mod3.png/
http://imageshack.us/photo/my-images/1 ... mod3.png/
check these 2 images. both have the black background. i am tring to make a layer of them.
so i am doing this

Code: Select all

exec("convert bodynormalclassic_mod3.png sleevelongnormal_mod3.png  -layers merge shirtmod3.png");
but i get only the 2nd image. not the combined one. body and sleeve are not combined. please tell me whats going wrong in this how can i get the combined body and sleeve. Thanks a lot for your help.

User avatar
fmw42
Posts: 22979
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: putting tile on image background is also changing need h

Post by fmw42 » 2012-03-07T11:06:20-07:00

Problems you have with your images.

1) You must use a transparent background not black to merge them.

2) Your black background is not fully black.

3) Your masking does not overlap.

So try


convert bodynormalclassicmod3.png sleevelongnormalmod3.png -fuzz 20% -transparent black -background black -flatten miff:- | convert - -median 3x3 shirt.png

Image


the -fuzz 20% -transparent black converts all near black to transparent. Then you can flatten or layers merge the images against a black background. But that leaves a gap between your shirt and sleeves. So I have had to add a median filter to smooth over the gap.

(For some reason, I cannot chain them in one convert, even adding -alpha opaque and -compose over. So had to pipe the output to a new convert. I am missing resetting something to make it chain properly.)

sujan.dasmahapatra
Posts: 44
Joined: 2012-02-18T21:42:01-07:00
Authentication code: 8675308

Re: putting tile on image background is also changing need h

Post by sujan.dasmahapatra » 2012-03-07T14:49:09-07:00

Thanks a lot friend it's working excellent thanks for your help.

User avatar
anthony
Posts: 8880
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: putting tile on image background is also changing need h

Post by anthony » 2012-03-07T19:17:06-07:00

No need to convert the background to transparency at all. Compose Screen, (negated multiply) will essentually make black and near black act like it is transparent!
http://www.imagemagick.org/Usage/compose/#screen

Code: Select all

convert bodynormalclassicmod3.png sleevelongnormalmod3.png \
         -compose screen -composite +compose   result.png
The if you use -flatten (for merging more than two pieces) add a -background black for the operators initial starting canvas.

Code: Select all

   convert read_in_more_that_two_pieces....  \
         -compose screen -background black -flatten -compose over  result.png
the final -compose over is recommended as in IMv6, the compose setting can be saved in some image file formats. It is something on my 'todo' list. (same goes for -gravity with MIFF image file format!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
fmw42
Posts: 22979
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: putting tile on image background is also changing need h

Post by fmw42 » 2012-03-07T19:27:35-07:00

Anthony,

the problem is that he does not have flat black for the background, it varies. So I suspect one would have to use -fuzz XX% -black-threshold on the images before your processsing. Is that correct?

Fred

User avatar
anthony
Posts: 8880
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: putting tile on image background is also changing need h

Post by anthony » 2012-03-07T21:13:53-07:00

Yes. Though near black with my script is also equivalent to near transparent so it should not effect results too much, unless the parts overlap (which they don't). If fact they seem to have a proper masked join as I don't even get a join like using screen.

Actually with 'Over' composition a zero (or black) alpha channel is considered transparent, and when images are merged a 'screen' mathematical operation is performed on the alpha channel to generate the correct alpha for an 'over' composition.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
fmw42
Posts: 22979
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: putting tile on image background is also changing need h

Post by fmw42 » 2012-03-07T22:10:29-07:00

Anthony,

Yes, I tried the -compose screen and it works better than my converting to transparency. I did not need to use median filtering to smooth the gap.

But I would certainly like to understand why in my example above I had to pipe to a new convert.

Fred

User avatar
anthony
Posts: 8880
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: putting tile on image background is also changing need h

Post by anthony » 2012-03-07T23:37:06-07:00

Thinking about it 'screen' is probably the wrong solution as well. 'plus' is probably the right solution to handle masks that share a common edge. See my raw notes...
http://www.imagemagick.org/Usage/masking/#aligning
fmw42 wrote:But I would certainly like to understand why in my example above I had to pipe to a new convert.
I don't know... it worked for me except for some slight aliasing along the edges from the -transparent color replacement, nothing went wrong with it!
This was the command I used... no pipeline.

Code: Select all

convert bodynormalclassicmod3.png sleevelongnormalmod3.png -fuzz 20% -transparent black -background black -flatten -median 3x3 show:
Thought it was perhaps the use of show: but saving to a PNG produced the same result.

I am using

Code: Select all

convert -version
Version: ImageMagick 6.7.5-10 2012-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP    
So what did your IM do? How did your command go wrong? You don't exactly say, only what you tried.

NOTE: median is purely a channel operator (no sync channel flag handling). As such if you tried it on an image with transparency, it would do nothing as the channel default in IMv6 is RGB and not RGBA. In other words it would not have filled in a line of transparent pixels! This is only relevent if you were trying to use -background none in your command. Adding -channel RGBA should fix that problem.

Hmmmm.... Under my testing it looks like median destroys alpha (when it is not in -channel setting) rather than preserve it! I have seen this same problem with -sparse-color development with channel restrictions, I know the cause.

Note to Magick for bug fix: When median makes a image clone for its results it is requests a faster 'cleared' image rather than a exact 'copy' of the original image data, thus when it does not apply itself to alpha, alpha does not get copied, and transparency is lost.

ADDITIONAL: median really could be rolled in as a special morphology operator, with the 3x3 being the 'neighbourhood'. As a morphology operator it could use other neighbourhoods than just square (EG: diamonds disks)


ASIDE: I generally avoid using color replacement. I have always considered replacing a range of colors with a single color a bad idea, even though it is a rather common idea. My "bg_removal" script
http://www.imagemagick.org/Usage/scripts/bg_removal
developed from my notes in Recovering Semi-Transparent Edges
http://www.imagemagick.org/Usage/masking/#semi-trans
could now be modified to automatically determine the semi-transparent colors using a 'color diffusion' (well shepards fill) of the internal colors, rather than its current use a fixed 'edge' or 'shadow' color. All you need is a good internal-external contrast and you can recover the edge aliasing near perfectly.

This however is really another topic.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

User avatar
fmw42
Posts: 22979
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: putting tile on image background is also changing need h

Post by fmw42 » 2012-03-08T10:39:39-07:00

So what did your IM do? How did your command go wrong? You don't exactly say, only what you tried.
I used this:

convert 1bodynormalclassicmod3.png 1sleevelongnormalmod3.png -fuzz 20% -transparent black -background black -flatten -median 3x3 1shirt_bad.png

and the result is the transparent sleeve image. No error messages!


-compose plus does not work as well as -compose screen. It leaves a white transition gap between the two images rather than a black one from my method without the -median. But -compose screen works perfectly.

Post Reply