Coffee mug with artwork painted on it (Snibgo's POV-Ray + IM)

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
rime
Posts: 5
Joined: 2018-01-25T08:42:47-07:00
Authentication code: 1152

Coffee mug with artwork painted on it (Snibgo's POV-Ray + IM)

Post by rime »

Hello,
Following this tutorial: http://im.snibgo.com/coffmug.htm the final mug image ithat I'm getting is incorrect - upper part of "painted" artwork is distorted. All of the intermediate image files seems to be correct, if compared to one in the article. I've only changed chequer pattern to white floor in cm_scene.pov. I'm using ImageMagick-7.0.7-22.

cm_scene.pov output:
Image

Mug mask:
Image

Image mask:
Image

Displacement map:
Image
cm_i_disp.png
Image

Extended displacement map:
Image
cm_i_extdisp.png:
Image
Notice single color bar on top. Is this correct?

Script output:
Used artwork file (cm_3.png): http://r1me.pl/development/mug/cm_3.png (1200x400)
Original snibgo logo/text gets distorted too, I've used different artwork file to make distortion more visible.

Code: Select all

call wrapImage ^
  cm_3.png ^
  cm_white_mug.png ^
  cm_extdisp_map.png ^
  cm_image_mask.png ^
  2 ^
  cm_snibgo_mug_im.png
Notice distortion and missing mug itself (second one is not an issue since it can be easily merged later)
Image

I'm quite sure the article was written with older version of IM.
IM requires now input and output file for convert operation, but article instructs creation of displacement map image like this:

Code: Select all

%IM%convert ^
  -sparse-color Bilinear ^
0,0,#008,^
%%[fx:w-1],0,#f08,^
0,%%[fx:h-1],#0f8,^
%%[fx:w-1],%%[fx:h-1],#ff8 ^
  -colorspace RGB ^
  cm_i_disp.png
I actually had to call it like this:

Code: Select all

%IM% convert cm_i_disp_w.png ^
  -sparse-color Bilinear ^
0,0,#008,^
1199,0,#f08,^
0,399,#0f8,^
1199,399,#ff8 ^
  -colorspace RGB ^
  cm_i_disp.png
where cm_i_disp_w.png is an empty 1199x399 image.

Are my displacement map files correct? What's causing artwork distortion ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Coffee mug with artwork painted on it (Snibgo's POV-Ray + IM)

Post by fmw42 »

What is your IM version and platform/OS? Please always provide that. If using a Unix-like system, see my scripts, cylinderize and cylinderwarp at my link below.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Coffee mug with artwork painted on it (Snibgo's POV-Ray + IM)

Post by snibgo »

On cm_i_disp.png, the identity displacement mask: you are correct, the code doesn't work. It should make a displacement map that is the same size as the artwork that is to be wrapped around the mug. On my page, that artwork is cm_samp.png which is 1200x400 pixels, so code that works is:

Code: Select all

%IM%convert ^
  cm_samp.png ^
  -sparse-color Bilinear ^
0,0,#008,^
%%[fx:w-1],0,#f08,^
0,%%[fx:h-1],#0f8,^
%%[fx:w-1],%%[fx:h-1],#ff8 ^
  -colorspace RGB ^
  +depth ^
  x.png
The output is the required 1200x400, not 1199x399. The "-sparse-color" refers to the coordinates of the pixels at the four corners of the image. (This one-pixel error will make almost no difference.)

On my page, there isn't enough emphasis on precision. (I will add this.) The displacement maps should be at least 16 bits/channel/pixel. Your cm_3.png is only 8 bits/channel/pixel, so the displacement file is only 8 b/c/p. This means there are only 256 possible values for the horizontal displacement, and you need 1200, so you get a blocky result.

I have added "+depth" to the command above. If you are using IM Q16 or better, this gives the required precision.

With that changed command, re-building the Coffee Mug page with your cm_3.png gives the final result:

Image

The result looks good to me.

I haven't tested the commands with IM v7.

Incidentally, I have added a page showing the equivalent steps with Blender instead of POV-ray, on a tee-shirt instead of a coffee mug: Painting people.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Coffee mug with artwork painted on it (Snibgo's POV-Ray + IM)

Post by snibgo »

I have now tested the Coffee Mug page with IM v7.0.3-5.

There is a problem with cm_mug_shad_wh.png, because v7 thinks the mean value "%[fx:mean*100]" of sRGB(57%,55%,54%) is 41.3%. I suppose this is a v7 bug, probably corrected in more recent versions.

There is a problem with cm_base.png, not helped by me forgetting to double the "%" in "-sigmoidal-contrast 5,50%". After correcting that, v7 gives a wrong result from "-auto-level". Again, perhaps this has since been fixed.
snibgo's IM pages: im.snibgo.com
Post Reply