Generic bevel and emboss

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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generic bevel and emboss

Post by fmw42 »

My original implementation allowed different colors for highlights and shadows (and allowed varying transparencies for each), because I implemented my own version of hardlight by thresholding and applying compose overlay to highlights and compose multiply to shadows. But this was very complex (and so even slower) and had some issues of thresholding. So I simplified it when I figured out how to use -shade and then auto-level and then apply contrast change ( which changed the mid value from 50% gray ) by overlaying gray with the thresholded alpha channel as a mask to reset the mid values to 50% gray so that hardlight would work (as it relies upon 50% mid value for thresholding). Note only elevation angle of 30 degrees, creates a mid value of 50% and even then I modify it by using -auto-level and contrast change to get varying depth.

So right now, the answer is no. But with further work, it might still be possible to colorize the beveled area in the outer bevel case. I just assumed that that feature was likely to be used very little and especially did not need different colors for highlight and shadows. So for the sake of simplicity and better speed, I did not work on including that. I think I know how to add it in and will look into it tomorrow. Is it relevant only for outer bevel (and outer bevel part of emboss) or in all cases?

Note, I tried to emulate Photoshop's Bevel/Emboss layer style as much as practical. However, IM -morphology distance gets rather slow even for distances (widths) of 10; whereas PS has somehow implemented this or its equivalent in real time adjustment of its slider. I wish I knew how they did that.

P.S. It is interesting that the outer bevel wants to have a non-linear taper by default whereas the inner bevel was linear. In the outer bevel case I had to add a taper value that was the power of 10 used in -evaluate log to straighten it. It seems to be an effect of inverting the mask and getting the distance measure (or perhaps it just has to do with the shape of the black areas inverted to white. Anthony, do you have any idea why this happens?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Generic bevel and emboss

Post by anthony »

No sorry I don't the Distance function should only result in linear distance effects from the nearest point.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
thevinn
Posts: 18
Joined: 2012-07-31T16:42:11-07:00
Authentication code: 15

Re: Generic bevel and emboss

Post by thevinn »

fmw42 wrote:IM -morphology distance gets rather slow even for distances (widths) of 10; whereas PS has somehow implemented this or its equivalent in real time adjustment of its slider. I wish I knew how they did that.
Photoshop uses the algorithm described by G. Borgefors in the 1986 paper "Distance Transformations in Digital Images". Specifically it is the Chamfer 5-7-11 metric. If you look at Figure 16 in the paper this will be very clear when comparing against Photoshop's output.

Since the distance transform is calculated over all pixels, the performance of the technique is independent of the "size" slider. A setting of "1" will be just as fast as the setting of "250."

There are even faster techniques for computing the distance transform (Meijster provides one in "A General Algorithm for Computing Distance Transforms in Linear Time") but modifying them to operate on grayscale masks is problematic.
Asimov6
Posts: 1
Joined: 2015-07-14T04:01:30-07:00
Authentication code: 1151

Re: Generic bevel and emboss

Post by Asimov6 »

I noticed that when I use the script with the default parameters the resulting image is somewhat lighter than the original. When I compare to the photoshop effect "Bevel & Emboss" this does not happen. Is there a way to prevent this or is this an expected result because of the technique used in the script?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generic bevel and emboss

Post by fmw42 »

asimov9 wrote:I noticed that when I use the script with the default parameters the resulting image is somewhat lighter than the original. When I compare to the photoshop effect "Bevel & Emboss" this does not happen. Is there a way to prevent this or is this an expected result because of the technique used in the script?
In the future, please create a new topic rather than tacking onto an old one.

Please provide more specific information. You have not given me enough to know what is going on.

If you are using my script, bevel, then please identify your version of Imagemagick and platform. Also post your exact command and upload the input and output images you are using to dropbox.com and put the URLs here.

Did you try using my example to see if you can reproduce my result?

One possibility is that your version of IM is old such that IM was using linear color/grayscale rather than sRGB. If that is the case, try upgrading your version of IM to the current version.
Post Reply