Fabric wrapping using imagemajick

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.
Post Reply
Loveleen
Posts: 5
Joined: 2012-02-07T07:52:02-07:00
Authentication code: 8675308

Fabric wrapping using imagemajick

Post by Loveleen »

Hi,

Im new to ImageMajick. Is there a way to be able to wrap a fabric(pattern) on a plain object using Imagemajick.

Something like http://www.liquidpixels.com/demos/demos.m?name=Norwalk

I would like to programtically implement the above example so that I can choose a swatch and change the fabric of the object.

Any example close to the above implemented in ImageMajick would be highly appreciated

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

Re: Fabric wrapping using imagemajick

Post by fmw42 »

Perhaps. You need to make a mask of the regions you want to put the fabric on. Then you can tile out the fabric pattern to the size of the background image and composite it with the mask(s) with the background image so that the white areas in the mask will be changed to the fabric and the other areas will come from the original image. However, I qualify this, since your object is not one surface and has seams, so I don't know exactly how those will come out. You may lose the "shape" of the object, unless you make multiple masks for each surface and perhaps use a perspective distortion for each. So in my opinion and without testing, I expect that this is not likely to work very well.

Unfortunately, IM is not a 3D system so does not know the 3D shape of the object.

IM can put images onto simple primitives like cylinders, spheres and cubes, but not generally arbitrary 3D shapes.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Fabric wrapping using imagemajick

Post by anthony »

The only way to do 3D arbitrary shapes is to define X Y warping maps, background mask, and a lighting shading map.
These are all grayscale images, and can be very hard to generate, but once done, you can apply it over and over with any texture or surface design.

I am sure something like POV (which converts 3D object description into Raytraced images) could be made to generate such maps. I just have not had the time to 'try it'.

Some basics have be exampled for some mathematically shapes, such as spheres and cylinders...
See IM Examples, Image Mapping Effects...
http://www.imagemagick.org/Usage/mapping/

NOTE absolute distortion maps are built into "composite" operation, but are not exampled well. Nor are some lens effect examples (with basically any lens, or warped glass that you can define) which I developed during a discussion with Fred Weinhaus. These are in a "store" directory waiting time for me to convert into proper examples.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Loveleen
Posts: 5
Joined: 2012-02-07T07:52:02-07:00
Authentication code: 8675308

Re: Fabric wrapping using imagemajick

Post by Loveleen »

Thank you for your suggestions. I will try and implement as per your suggestions and post the result once Im done.
Thanks again fmw42 and anthony
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Fabric wrapping using imagemajick

Post by anthony »

Looking at the site link you gave. It looks like they cheated a but.

Select a bolder pattern such as
[img]http://lpi.liquifire.com/lf?lookup=key[ ... ric],table[file:_demos/Norwalk/data.table]&source=url[global.fabric.1]&crop=height[400],width[400]&scale=options[crop],size[30]&brightness=value[90]&sink[/img]

The did a affine warp of the tile pattern for the 'seat' but used the tile as if for the other vertical surfaces.
The only part they did something else was the curve of the arm rest, and they did not do that very well either, as I see a discontinuity on the left side. Shades were also applied as a 'bumpmap' to make it look more realistic.

In otherwords, it is a 'rough cheat', and not a real fabric wrap. Just different areas with different distortions of the tile pattern
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

Re: Fabric wrapping using imagemajick

Post by mahak2050 »

Hi, This is mahak and I used the masking command but there is some problem regarding the platform.
Command I am using is given below :
convert sample.png -background black -gravity south -splice 0x8 \ ( +clone -sparse-color barycentric "0,0 black 69,0 white" \ ) \ ( +clone -function arcsin 0.5 \ ) \ ( -clone 1 -level 25%,75% -function polynomial -4,4,0 -gamma 2 +level 50%,0 \ ) -delete 1 -swap 0,1 miff:- | composite - -virtual-pixel black -displace 17x7 sample_result.png

This is working on Windows platform but when I am using this on my server this is not producing the result, I dont know whats happening :(

Will some one help me to resolve this issue?

Thanks
Mahak
mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

Re: Fabric wrapping using imagemajick

Post by mahak2050 »

One more thing I forget to add,
On my Windows I am Using Version: ImageMagick-6.7.7-Q16

And on Linux I am using Version: ImageMagick 6.2.8

So let me know If Its a version issue and how It could be fixed.

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

Re: Fabric wrapping using imagemajick

Post by fmw42 »

mahak2050 wrote:One more thing I forget to add,
On my Windows I am Using Version: ImageMagick-6.7.7-Q16

And on Linux I am using Version: ImageMagick 6.2.8

So let me know If Its a version issue and how It could be fixed.

Thanks
Mahak

Sparse-color feature was not availabe for 6.2.8.

It was initially available (though other fixes followed) at 6.4.2-9

Only way to use it is to upgrade.

Similarly for -function. It was only available at 6.4.8-8

see
http://www.imagemagick.org/script/changelog.php
juildaes
Posts: 1
Joined: 2012-07-29T23:11:02-07:00
Authentication code: 15

Re: Fabric wrapping using imagemajick

Post by juildaes »

Hi Im also having problems with the masking command.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fabric wrapping using imagemajick

Post by fmw42 »

juildaes wrote:Hi Im also having problems with the masking command.
Please see viewtopic.php?f=1&t=9620

Without more details it is hard to know what you are doing or what to tell you. Please identify your exact command, provide possible input and output images, and certainly identify your platform and version of IM.
mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

Re: Fabric wrapping using imagemajick

Post by mahak2050 »

Hi,

I am trying the below command in IM but Its not working.
convert RIGHT_SIDE_IMAGE30.png -crop 80x100+150+150 RIGHT_SIDE_CROPPED30.png
I have also tried to put the coordinates in the quotes. But no success.
convert RIGHT_SIDE_IMAGE30.png -crop "80x100+150+150" RIGHT_SIDE_CROPPED30.png
IM Version : 6.7 ( Server Linux )

And Its working on Windows same IM version. I have latest version on server of IM.

The same command was working on the lower version on the server.

Will some one help me to resolve this issue?

Thanks
Mahak
mahak2050
Posts: 11
Joined: 2012-07-11T08:55:23-07:00
Authentication code: 13

Re: Fabric wrapping using imagemajick

Post by mahak2050 »

The above command return 1x1 px image.

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

Re: Fabric wrapping using imagemajick

Post by fmw42 »

try

convert RIGHT_SIDE_IMAGE30.png +repage -crop 80x100+150+150 +repage RIGHT_SIDE_CROPPED30.png

if that still does not work, then either post a link to your image or report the information from

convert RIGHT_SIDE_IMAGE30.png -verbose info:
Post Reply