Apply texture on selected Area (Color) of an Image

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
sanjeevk
Posts: 26
Joined: 2009-08-26T02:17:36-07:00
Authentication code: 8675309
Location: India
Contact:

Apply texture on selected Area (Color) of an Image

Post by sanjeevk »

Hi All,

I want to apply one image on the selected area or color of an Image.
for this I have try following :-

composite -blend 70 Rings_0.png HardTwist.png new.png..

This does not give exact result.

any one can help me.
Last edited by sanjeevk on 2009-08-27T21:32:51-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: Apply texture on selected Area (Color) of an Image

Post by fmw42 »

please post examples otherwise we have no idea what you mean by "does not give exact results"

please show a good result as well
sanjeevk
Posts: 26
Joined: 2009-08-26T02:17:36-07:00
Authentication code: 8675309
Location: India
Contact:

Re: Apply texture on selected Area (Color) of an Image

Post by sanjeevk »

Suppose we have an Image that have many color like red, green and white . we can apply texture on the over all image. As giving in the followin example on ImageMagick.

http://www.imagemagick.org/Usage/photos/#texture

In this example texture is apply on whole image. I want to apply this texture only on white color of this image. Please suggest on the same.

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

Re: Apply texture on selected Area (Color) of an Image

Post by fmw42 »

sorry can you show us the texture and what image you want to apply in only the white area. it is not clear what you want.

If I understand and perhaps not, then you need to have a texture image the size of the other image. In the other image you need to mask the white area and make it transparent. Then you can composite the image with the white area made transparent over the background texture image.

If you can provide and example of your texture image and the image you want to put your texture into, then perhaps we can provide the commands to do so.
sanjeevk
Posts: 26
Joined: 2009-08-26T02:17:36-07:00
Authentication code: 8675309
Location: India
Contact:

Re: Apply texture on selected Area (Color) of an Image

Post by sanjeevk »

Currently I am working on a web base application for on-line color manipulation of an image.

Please click on this link : http://www.imagemagick.org/Usage/photos/#texture

see this example. In this example texture is added to the all over the Image. I want to apply different texture on the different color of the same image OR we can say that I want to apply texture on only selected color of this image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply texture on selected Area (Color) of an Image

Post by fmw42 »

I will try to work on this tomorrow unless Anthony gets to it tonight. It is about my bedtime.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply texture on selected Area (Color) of an Image

Post by fmw42 »

Image

Image

# do same processing as Anthony
# create copy of original with white made transparent
# composite together

convert pagoda_sm.jpg \
\( -clone 0 -size 320x295 tile:texture_fabric.gif \
-compose hardlight -composite \) \
\( -clone 0 -strip -fuzz 10% -transparent white \) \
-delete 0 -compose over -composite pagoda_sm_texture_white.png

Image
sanjeevk
Posts: 26
Joined: 2009-08-26T02:17:36-07:00
Authentication code: 8675309
Location: India
Contact:

Re: Apply texture on selected Area (Color) of an Image

Post by sanjeevk »

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

Re: Apply texture on selected Area (Color) of an Image

Post by anthony »

see IM Examples, Photo Handling, Add a Texture to an Image
http://www.imagemagick.org/Usage/photos/#texture

However note that in freds solution the mask was created from the image of just the areas within 10% of white. In your case a separate mask image would be used to limit the area being textured.

Fred, perhaps you should have generated the mask separately. However it is a good addition to add to IM Examples, so I'll see about doing that.

Hmmm now if I can get a GOOD example of say replacing a dress, then I would make it a completely new photo modification section, that follows on from the 'pagoda' example.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sanjeevk
Posts: 26
Joined: 2009-08-26T02:17:36-07:00
Authentication code: 8675309
Location: India
Contact:

Re: Apply texture on selected Area (Color) of an Image

Post by sanjeevk »

Hi fmw42,
It's work like magick. But when I use it with a transparent .png image in witch only one color strip and rest part of this image is transparent in that case texture is also apply on transparent part of this image.while I want to untouched transparent part of this image.Can you suggest on the same.

Thanks,
Sanjeev Kumar
Last edited by sanjeevk on 2009-08-27T21:51:21-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: Apply texture on selected Area (Color) of an Image

Post by fmw42 »

sanjeevk wrote:Thanks,
Anthony

Actually it was fmw42 who made the example
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply texture on selected Area (Color) of an Image

Post by fmw42 »

anthony wrote:
However note that in freds solution the mask was created from the image of just the areas within 10% of white. In your case a separate mask image would be used to limit the area being textured.

Fred, perhaps you should have generated the mask separately. However it is a good addition to add to IM Examples, so I'll see about doing that.
Sorry I still don't understand his requirement and a lack of supplying his real image just makes it harder.

I am not sure what you meant by generating the mask separately. Perhaps you can supply another solution that would work better. In fact, I would be very interested in seeing if you can repeat my solution (where I change from using composite to convert, so I could make it one command line), but could not figure out how to avoid feeding the size to the tile:textureimage. You were able to avoid that in your original method, but I have searched your pages and all your other examples seem to need the size defined for the texture. Is this a composite only issue or can it carry over to convert.

In fact, I still think IM needs some general way of setting and retrieving an image size in a single command line to avoid a pre-command to find the size and put it into a variable. There are many times when you want to create an gradient: or texture of a given size to match some image in a given command line (not to mention some constant color, although that can be done with a clone and -colorize or -threshold or the like). But I can figure out no way to generate a gradient:, radial-gradient: pattern: or tile to match some image in the one and only command line via a clone of a previous image in the command line. Am I missing something?

Something like:

convert image \
\( -clone -setsize +delete gradient: \) \ ....

Any ideas how to do this now or later?
Last edited by fmw42 on 2009-08-27T21:50:38-07:00, edited 1 time in total.
sanjeevk
Posts: 26
Joined: 2009-08-26T02:17:36-07:00
Authentication code: 8675309
Location: India
Contact:

Re: Apply texture on selected Area (Color) of an Image

Post by sanjeevk »

Sooooryyy

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

Re: Apply texture on selected Area (Color) of an Image

Post by fmw42 »

sanjeevk wrote:Sooooryyy

fmw42

No problem. Glad to help. But I don't understand your transparency issue. You made no mention of your image having transparency. The obvious but perhaps not best solution is to copy the alpha channel to a separate image, then delete the alpha channel on your image, then add the texture, then compose copy_opacity to add your original alpha channel back at the end.

But you have not provided an real example of your images for us to know your real problems and test any solution. So we are just guessing at this point. At least I am. Perhaps Anthony understands and can provide a better method or one more general.
sanjeevk
Posts: 26
Joined: 2009-08-26T02:17:36-07:00
Authentication code: 8675309
Location: India
Contact:

Re: Apply texture on selected Area (Color) of an Image

Post by sanjeevk »

HI fmw42,

Use this image.

Image

and run this command

convert aqua_font.png \( -clone 0 -size 66x58 tile:texture_fabric.gif -compose hardlight -composite \) \( -clone 0 -strip -fuzz 10% -transparent \#1D8DF9 \) -delete 0 -compose over -composite aqua_font_texture.png.

see the output.
this command apply texture on whole image. While I want to apply texture only on "A" or only on blue color of this image.

thanks,
sanjeev kumar
Post Reply