Black & White conversion with Gorman-Holbert method

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?".
Post Reply
xaser
Posts: 6
Joined: 2010-01-13T14:16:56-07:00
Authentication code: 8675309

Black & White conversion with Gorman-Holbert method

Post by xaser »

Hello!

I am looking for a way to make a script in IM, in order to do the Gorman-Holbert process to get B&W conversion with good results, but I wouldlike to ask if there is some script already made for this.

If not I would like to ask if could be possible some help in translate the steps of the method to IM syntax commnads in order to try to make the script.

The Gorman-Holbert method is described here in some detail:

http://www.blackandwhitedigital.com/Con ... orman.html

This is a somewhat long article about variations, but seems that the basic process is covered in the previous link.

http://www.botzilla.com/blog/archives/000649.html

I was following the process manual in Gimp, but translate the process to a script in IM or Gimp seems some above my knowledge by now.

Thanks for any help and best regards
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Black & White conversion with Gorman-Holbert method

Post by fmw42 »

My best guess at what it does:

Grayscale only:

# first line creates L channel from Lab
# second line sharpens and blends
convert \( Sample9Color.gif -colorspace Lab -channel r -separate +channel \) \
\( -clone 0 -sharpen 0x3 \) -compose dissolve -define compose:args=20,100% -composite \
Sample9Color_test1.png


Colorized:

# first line creates negated L channel from Lab
# second line clones and negates and creates colorized layer and reverses the order
# third line composites them together via the first line image as a mask
# fourth line creates sharpened version and blends with previous result
convert \( Sample9Color.gif -colorspace Lab -channel r -separate +channel -negate \) \
\( -clone 0 -negate \) \( -clone 0 -fill gold -colorize 100% \) -reverse \
-compose multiply -composite \
\( -clone 0 -sharpen 0x3 \) -compose dissolve -define compose:args=20,100% -composite \
Sample9Color_test2.png


In these examples, you can change the color and percent colorized, the sharpening amount and the amount the sharpened image is blended with the unsharpened image.

You can speed this up a bit by leaving out the dissolve and just changing the amount of sharpening
xaser
Posts: 6
Joined: 2010-01-13T14:16:56-07:00
Authentication code: 8675309

Re: Black & White conversion with Gorman-Holbert method

Post by xaser »

Hi Fred!

Thank You very much for take time to help and your kind info.

I just checked the your script commands guess, but seems that the results are different from the expected of the gorman processs, however, I am very gratefull for your examples since them shows me some of the syntax of IM that are very complex to me in replicating the steps of the method.

By now, I have a doubt, in the part: -colorspace Lab -channel r
in the IM options doc page, seems that r refers to red channel of the picture, but I wonder if after a Lab colorspace conversion, r start to refer to the first channel and in that case it will be luminosity; so, in this point following the method described, the next part tell discard the channels a and b of Lab separated, and from then the method continues changing again the Luminosity remaining channel to RGB (after deletion of a and b channels), and from then the method continues... so I wonder if the first line of Your suggestion may need to change to the form:

convert \( Sample9Color.gif -colorspace Lab -channel r -separate -delete 1,2 -negate -colorspace RGB +channel \) \

in order to discard a and b channels (step 3 of method), I presume that in that way the remainig L channell will be selected by default of be the 0 layer (and also the grey layer in gorman method) in IM context, so then, negate to invert (to select shadows) and later change again to RGB in order to follow the method and converting the luminosity channel in a RGB image in grey (and setting +channel, so the following steps will affect all the channels of the Luminosity channel converted to a greyscale image)

Please excuse me if I make a mess of this or bother too much, but I hope that may could explain myself enoughas far I am following and study Your valuable examples.

Thanks again for Your kind attention and any other help/clue will be welcome and very gratefull

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

Re: Black & White conversion with Gorman-Holbert method

Post by fmw42 »

convert \( Sample9Color.gif -colorspace Lab -channel r -separate -delete 1,2 -negate -colorspace RGB +channel \) \
Yes, after a color change, -channel r, refers to first channel of the new colorspace, which is L. Thus I am only saving the one L channel by the -separate . The negate has to come after the +channel otherwise, you get false colors because of the other two channels have not been properly reset.

In IM, you don't need the -colorspace RGB as you have one single grayscale. But IM treats all images as if they are 3 channel RGB but all channels are the same. So you can drop the -colorspace RGB. You can leave it if you want, but there is no difference. The +channel is there to ensure that -channel r is turned off for other later steps (though you might be able to remove it, if you put -respect-parenthesis after the convert -- not sure without testing).

In the grayscale method, the negate was not necessary as the result has the correct polarity. I checked that.

In the color method, you need to negate it and then negate back the clone so that the mask has the correct polarity and grayscale image is just the opposite.

The best way to view what is happenning is to put -write tmpX.png after each step that you want to review. change X each time from 0, 1, 2, ... Then look at the tmpX.png images that will be saved. That way you can follow each step and see what is produced. That is what I did while experimenting to make sure the steps were working correctly.

See
http://www.imagemagick.org/script/comma ... .php#write

My results may not perfectly match the reference you had, because I don't know exactly what photoshop uses for its high pass filter. So I just used IM's -sharpen radiusxsigma with radiusxsigma=0x3 for a nominal value. This is a Gaussian sharpening filter. (radius=0 means sigma determines the radius automatically but is about radius=3*sigma). There are other arguments that you can change as I mentioned before. You will have to tune it to your preferences or to make it match as well as possible. Leaving colorize at 100% appears to simulate what the reference was doing functionally, but you can lower that to make the color less prominent. I used the 20% for the mixing of the sharpened image as per the reference. But as I said, you can use that or not, since in IM you can change the sharpen value directly. Thus you can remove the 20% and lower the sharpen or increase the sharpen and change the 20% to make it match as well as possible to the reference paper.

P.S Using white for the color in the color method, should nearly reproduce the Grayscale method for the most part, so you need use only one method. There may be some difference due to the mixing using the 20%. I have not checked this. That I believe is why they selected white in the example in the reference when doing the grayscale result. So if you want to match their algorithm, use the color method with color=white to make the grayscale result.
xaser
Posts: 6
Joined: 2010-01-13T14:16:56-07:00
Authentication code: 8675309

Re: Black & White conversion with Gorman-Holbert method

Post by xaser »

Hi Fred!

Wow! What a kind of reply and explanation!... Thank You very much for kind info, and for take time to help. :-)

Well, after such good guide, I will be following your suggestions, and do my tests on my side and checking online IM docs.

Thanks again and best regards!
xaser
Posts: 6
Joined: 2010-01-13T14:16:56-07:00
Authentication code: 8675309

Re: Black & White conversion with Gorman-Holbert method

Post by xaser »

Hi Fred!

Well, I was able to track what happen, since my results was very weird from the expected, but, lucky I found the issue is the version of IM that I was using in Kubuntu 11.10, and it is IM version 6.6.0 which seems that have a big bug in LAB conversion part, but lucky I test on a Lubuntu 11.04 and was able to check with a IM version 6.6.2 that have the LAB bug fixed and Your script Work WODERFULL!

I now triying to add a Vignette effect, but the info of the Vignette command is very short since the only info that I found from IM options docs was:

-vignette radius{xsigma}{+-}x{+-}y{%}

soften the edges of the image in vignette style.

But I didnt found info about how radius, sigma are interpreted by IM in order make the vignette with a really soft and very graduated edge. Also I wonder what means the settings {+-}x{+-}y{%}.

I found a previous example from You with the command:

convert source.jpg -background black -vignette 100x65000 result.png

but wonder if sigma need a so high number as 65000 and I suppose that if my picture would be around 2400px high and want a very low graduated vignette (of around 1/4 of size), then radius would be around 400-600px.

Thanks again for Your previous help and kind attention!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Black & White conversion with Gorman-Holbert method

Post by fmw42 »

convert source.jpg -background black -vignette 100x65000 result.png
radiusxsigma allows a gaussian roll off of the vignette, esp if you use radius=0 and just sigma, as radius will then be computed automatically as approx radius=3xsigma. So 3xsigma is about the distance for the vignette from 0 to full black.

On the other hand if you want a linear roll off, then use radiusx65000 where 65000 is just a number much greater than radius. Thus the gaussian is turned into a linear roll off function of distance = radius. So in the above, I wanted a linear roll off as it was more gradual and even roll off over 100 pixels

See my script, vignette, if on Unix, at the link below.

Also see http://www.imagemagick.org/Usage/transform/#vignette


I suspect the +X+Y allows the vignette to be shifted from the center. But I am not positive of that as I have never tried it.
Post Reply