Page 1 of 2

B/W Halftone Dither

Posted: 2010-11-02T05:21:08-07:00
by nimbus
Hi everyone,

I have checked manual, examples and this board.

This is what I get when using the -ordered-dither with h8x8o option:
Image

Which looks a bit fuzzy ...
How can I force IM to use clean circle spots like in this example I've made with Photoshop?

Image

Maybe some kind of pattern added to the dither-function?
Any help is greatly appreciated.
Thank you.

Re: B/W Halftone Dither

Posted: 2010-11-02T10:30:22-07:00
by fmw42
try

convert h8x8o.png -morphology open diamond:1 h8x8o_open_d1.png


see http://www.imagemagick.org/Usage/morphology/

Re: B/W Halftone Dither

Posted: 2010-11-02T11:07:46-07:00
by nimbus
Very interesting, but unfortunately it doesn't make any change at all?!
I followed the morpholgy document a bit and tried several other options ...

E.g. for my understanding, an option like "-morphology open disk:2.5" would not only use round shapes, but resize everything. Am I right?
But why is there no change on the final image?

Here's what I do using this image:
Image

Code: Select all

convert sw.jpg -colorspace GRAY -resize 500 png:out.png
convert out.png -ordered-dither h8x8o png:out.png
convert out.png -morphology smooth Disk:2.5 png:out.png
convert out.png -normalize png:-
Any hint?
Thanks alot!

Re: B/W Halftone Dither

Posted: 2010-11-02T15:39:29-07:00
by fmw42
Your version of IM may be too old. Try upgrading.

I was not trying to make the dither into circle, only to clean it up a bit.

When I did


convert h8x8o.png -morphology open diamond:1 h8x8o_open_d1.png


this is what I got. You can try diamond:2 or another shape, but keep it small size.


Image

Or try

convert h8x8o.png -median 1 h8x8o_med1.png

Image

convert h8x8o.png -median 2 h8x8o_med1.png

Image

Re: B/W Halftone Dither

Posted: 2010-11-02T21:43:42-07:00
by anthony
nimbus wrote: How can I force IM to use clean circle spots like in this example I've made with Photoshop?
This great example of the difference between a thresholded ordered-dither pattern and true half-tone offset printing.

The -ordered-dither is not really a true-halftone effect but a threshold pattern to generate an image using only pure black and white. It is not trying to generate circles, just generate a shading effect with pure black and white only.

If you look closely you will see that the second photoshop image is not actually Black and white!!! It is a Greyscale generated by drawing anti-aliased circles, in a diamond (angled) matrix.

Or more specifically it contains only perfect black anti-aliased circles. No white anti-aliased circles are being generated. Basically it is a white image covered in black circles of varying sizes. If this was color, a range of CYMK circles would probably have been generated.

Presumably each circle is being sized based purely on the color of the pixel at the very center of each circle, or (based on the pattern, the diamond shaped area the circle would cover at full size. Also note that circle coverage (final shade value) and the circle size is not a linear relationship, as at one point the circles overlap.

It is a most interesting effect, and one that I think would make a great addition to IM.

First step however would be to work out the exact algorithm to use and generate a, "proof of concept" script that is a simple as posible. It would be nice it it also handled angled offset printing with CMYK coloring, as you would get in real halftone offset printing.

I think Fred (fmw42) has already shown an interested in this, though some research on exact circle size to intensity value relationships would also be needed.

Re: B/W Halftone Dither

Posted: 2010-11-03T01:37:35-07:00
by nimbus
Dear Anthony,
thank you for your reply.
I know that Photoshop does some antialising, but in my case, this is not important.
In fact, I'd rather have no anti-aliasing at all, because I actually need to convert the bitmap to vector art afterwards.
But anyway, it would be great if IM would be able to create the Photoshop filter effect.
Best regards.

Re: B/W Halftone Dither

Posted: 2010-11-03T17:42:25-07:00
by fmw42
Here is a short script that creates circle patterns as a mask and composites it with the image or with a 2color b/w version of the image. It creates a set of 5 circles, then tiles that out to the size of the image, then compose multiply composite to make the result. You can try thresholding in place of -colors or any other way to get a b/w base image, if that is desirable. Or change the circle rad (size) or spacing between circles (dist). For the circle drawing, see http://www.imagemagick.org/Usage/draw/#circles



convert sw.jpg -resize 50% sw2.jpg

infile="sw2.jpg"
inname=`convert $infile -format "%t" info:`
dim=`convert $infile -format "%wx%h" info:`
size=3
dist=14
dist2=`convert xc: -format "%[fx:$dist/2]" info:`
convert \( -size ${dist}x${dist} xc:white -fill black \
-draw "translate 0,0 circle 0,0 $size,0" \
-draw "translate $dist,0 circle 0,0 $size,0" \
-draw "translate $dist,$dist circle 0,0 $size,0" \
-draw "translate 0,$dist circle 0,0 $size,0" \
-draw "translate $dist2,$dist2 circle 0,0 $size,0" \
-write mpr:tile +delete \
-size $dim tile:mpr:tile \) \
\( $infile +dither -colors 2 -auto-level \) \
+swap -compose multiply -composite \
${inname}_2colors_circles_r${size}_d${dist}.gif
Image


infile="sw2.jpg"
inname=`convert $infile -format "%t" info:`
dim=`convert $infile -format "%wx%h" info:`
size=3
dist=14
dist2=`convert xc: -format "%[fx:$dist/2]" info:`
convert \( -size ${dist}x${dist} xc:white -fill black \
-draw "translate 0,0 circle 0,0 $size,0" \
-draw "translate $dist,0 circle 0,0 $size,0" \
-draw "translate $dist,$dist circle 0,0 $size,0" \
-draw "translate 0,$dist circle 0,0 $size,0" \
-draw "translate $dist2,$dist2 circle 0,0 $size,0" \
-write mpr:tile +delete \
-size $dim tile:mpr:tile \) \
$infile +swap -compose multiply -composite \
${inname}_circles_r${size}_d${dist}.gif
Image


infile="sw2.jpg"
inname=`convert $infile -format "%t" info:`
dim=`convert $infile -format "%wx%h" info:`
size=3
dist=14
dist2=`convert xc: -format "%[fx:$dist/2]" info:`
convert \( -size ${dist}x${dist} xc:white -fill black \
-draw "translate 0,0 circle 0,0 $size,0" \
-draw "translate $dist,0 circle 0,0 $size,0" \
-draw "translate $dist,$dist circle 0,0 $size,0" \
-draw "translate 0,$dist circle 0,0 $size,0" \
-draw "translate $dist2,$dist2 circle 0,0 $size,0" \
-write mpr:tile +delete \
-size $dim tile:mpr:tile \) \
\( $infile -monochrome \) \
+swap -compose multiply -composite \
${inname}_monochrome_circles_r${size}_d${dist}.gif
Image


NOTE: this is not a dither pattern, just an overlay. It does not make the spacing between the circles closer where the base image is darker.

Re: B/W Halftone Dither

Posted: 2010-11-05T05:37:32-07:00
by magick
You can add your own threshold patterns to thresholds.xml. For example, Glenn Randers-Pehrson added 5x5, 6x6, and 7x7 ordered circular thresholding to the ImageMagick distribution recently. Here is the 7x7 threshold:

Code: Select all

  <threshold map="o7x7c" alias="7x7">
    <description>Ordered 7x7 Circular</description>
    <levels width="7" height="7" divisor="50">
       49 42 32 18 19 33 48
       41 31 17 10 11 20 34
       40 30  9  2  3 12 21
       39 29  8  1  4  5 22
       43 28 16  7  6 13 23
       44 38 27 15 14 24 35
       46 45 37 26 25 36 47
    </levels>
  </threshold>
He says:
I found that an attractive halftone image can be obtained by using one of these, pre-rotating the image 45 degrees then rotating back and cropping to the original dimensions.

Re: B/W Halftone Dither

Posted: 2010-11-05T06:40:19-07:00
by glennrp
I got a clean halftone using the new 7x7 level map and this script:

Code: Select all

# make dimensions evenly divisible by 7
convert -bordercolor black -border 2x2 sw.jpg sw.ppm
convert -gamma .45455 -resize 113x113 sw.ppm sw_o7.ppm
convert -sample 791x791 sw_o7.ppm sw_clean.ppm
# diagonal halftone dither
convert -rotate 45 -ordered-dither 7x7 -rotate -45 sw_clean.ppm \
           -gravity center -crop 787x787+0+0 sw77.jpg
Image
"7x7" (black circles) on the left, "o7x7wc" (white circles) on the right.
Full size at http://glennrp.net/cns/halftoning/sw77g.jpg

Re: B/W Halftone Dither

Posted: 2010-11-05T08:36:12-07:00
by nimbus
Thank you all for your help, I have made a combination of IM and a simple PHP script to create the results I need.
IM rocks, keep up the good work!

Re: B/W Halftone Dither

Posted: 2010-11-05T10:03:13-07:00
by fmw42
Results look very good.

Please note that your IM syntax should be in your commands

convert input options output

to be fully compatible. Most of the time the old syntax format will suffice, but you may get into problems with certain things.

see http://www.imagemagick.org/Usage/basics/#cmdline

Re: B/W Halftone Dither

Posted: 2010-11-06T18:39:19-07:00
by anthony
magick wrote:You can add your own threshold patterns to thresholds.xml. For example, Glenn Randers-Pehrson added 5x5, 6x6, and 7x7 ordered circular thresholding to the ImageMagick distribution recently. Here is the 7x7 threshold:

Code: Select all

  <threshold map="o7x7c" alias="7x7">
    <description>Ordered 7x7 Circular</description>
    <levels width="7" height="7" divisor="50">
       49 42 32 18 19 33 48
       41 31 17 10 11 20 34
       40 30  9  2  3 12 21
       39 29  8  1  4  5 22
       43 28 16  7  6 13 23
       44 38 27 15 14 24 35
       46 45 37 26 25 36 47
    </levels>
  </threshold>
He says:
I found that an attractive halftone image can be obtained by using one of these, pre-rotating the image 45 degrees then rotating back and cropping to the original dimensions.
Thank you Glenn Randers-Pehrson for your additions to the threshold patterns,

However the added patterns should NOT be called o7x7c
'o' is for ordered-diffused pixel threshold patterns (what is typically used by -ordered-dither, and that is definatally not a diffused pattern.
It probably should be a 'h' pattern which is used to generate "psuedo" halftone threshold patterns.

As these are meant to produce circles. rather than a 'dimond' 50% threshold pattern, perhaps they should have a 'c' prefix.

Re: B/W Halftone Dither

Posted: 2010-11-06T19:18:18-07:00
by anthony
The threshold pattern naming has been updated... Use thsi command to see the threshold patterns available

Code: Select all

convert -list threshold
Threshold Maps for Ordered Dither Operations

PATH: /usr/share/ImageMagick-6.6.5/config/thresholds.xml

Map Alias Description
----------------------------------------------------
threshold 1x1 Threshold 1x1 (non-dither)
checks 2x1 Checkerboard 2x1 (dither)
o2x2 2x2 Ordered 2x2 (dispersed)
o3x3 3x3 Ordered 3x3 (dispersed)
o4x4 4x4 Ordered 4x4 (dispersed)
o8x8 8x8 Ordered 8x8 (dispersed)
h4x4a 4x1 Halftone 4x4 (angled)
h6x6a 6x1 Halftone 6x6 (angled)
h8x8a 8x1 Halftone 8x8 (angled)
h4x4o Halftone 4x4 (orthogonal)
h6x6o Halftone 6x6 (orthogonal)
h8x8o Halftone 8x8 (orthogonal)
h16x16o Halftone 16x16 (orthogonal)
c5x5b c5x5 Circles 5x5 (black)
c5x5w Circles 5x5 (white)
c6x6b c6x6 Circles 6x6 (black)
c6x6w Circles 6x6 (white)
c7x7b c7x7 Circles 7x7 (black)
c7x7w Circles 7x7 (white)

PATH: /home/anthony/.magick/thresholds.xml

Map Alias Description
----------------------------------------------------
diag5x5 diag Simple Diagonal Line Dither
hlines2x2 hlines2 Horizontal Lines 2x2
hlines2x2a Horizontal Lines 2x2 (bounds adjusted)
hlines6x4 Horizontal Lines 6x4
hlines12x4 hlines Horizontal Lines 6x4
Note that the last sections are 'personal' patterns which I use for my own purposes, as well as in IM examples Ordered Dither

Re: B/W Halftone Dither

Posted: 2010-11-06T19:29:54-07:00
by anthony
However initial testing shows that the 'white' and 'black' circles do not really complement each other (at time of writing)

Code: Select all

 convert -size 20x640  gradient: -rotate 90  gradient.png
convert gradient.png   -ordered-dither c7x7b      od_c7x7b.gif
convert gradient.png   -ordered-dither c7x7w      od_c7x7w.gif
Image
Image

Re: B/W Halftone Dither

Posted: 2010-11-29T21:54:10-07:00
by glennrp
I revised the c7x7b and c7x7w maps to be more complementary to each other, in Svn head and IM-6.6.6-2.
In this image, the top bar is the c7x7w negated and flopped, the middle bar is c7x7b, and the bottom bar is c7x7w.
Image