possible bug with -threshold and/or histogram?

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug with -threshold and/or histogram?

Post by fmw42 »

IM 6.5.9-10 Q16 Mac OSX Tiger

1) I created an image as follows:

convert -background black -fill white -font Candice -pointsize 36 -kerning 5 +dither label:"ABCDEFGHIJKLMNOPQRSTUVWXYZ" -threshold 50% alphabet.gif

Image

but when I do

identify -verbose alphabet.gif

Class: PseudoClass
Geometry: 975x40+0+0
Resolution: 72x72
Print size: 13.5417x0.555556
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 65279 (1)
Histogram:
25151: ( 0, 0, 0) #000000 black
13849: (255,255,255) #FFFFFF white

Why am I not getting max of 65535 (since I included -threshold 50%)?


2) I then took that image and coded each letter with an graylevel starting at 1 and increasing by 1 for each character.

Image

This looks totally black, but looking at the histogram, I see each graylevel

identify -verbose alphabet_m1.gif

Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 975x40+0+0
Resolution: 72x72
Print size: 13.5417x0.555556
Units: Undefined
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 13338 (0.101961)
mean: 4.67 (0.0183137)
standard deviation: 7.68574 (0.0301402)
kurtosis: 0.606938
skewness: 1.43078
Histogram:
25151: ( 0, 0, 0) #000000 black
599: ( 1, 1, 1) #010101 rgb(1,1,1)
544: ( 2, 2, 2) #020202 rgb(2,2,2)
585: ( 3, 3, 3) #030303 grey1
565: ( 4, 4, 4) #040404 rgb(4,4,4)
429: ( 5, 5, 5) #050505 grey2
599: ( 6, 6, 6) #060606 rgb(6,6,6)
590: ( 7, 7, 7) #070707 rgb(7,7,7)
450: ( 8, 8, 8 ) #080808 grey3
545: ( 9, 9, 9) #090909 rgb(9,9,9)
577: ( 10, 10, 10) #0A0A0A grey4
648: ( 11, 11, 11) #0B0B0B rgb(11,11,11)
558: ( 12, 12, 12) #0C0C0C rgb(12,12,12)
485: ( 13, 13, 13) #0D0D0D grey5
541: ( 14, 14, 14) #0E0E0E rgb(14,14,14)
547: ( 15, 15, 15) #0F0F0F grey6
536: ( 16, 16, 16) #101010 rgb(16,16,16)
525: ( 17, 17, 17) #111111 rgb(17,17,17)
430: ( 18, 18, 18) #121212 grey7
481: ( 19, 19, 19) #131313 rgb(19,19,19)
620: ( 20, 20, 20) #141414 grey8
595: ( 21, 21, 21) #151515 rgb(21,21,21)
558: ( 22, 22, 22) #161616 rgb(22,22,22)
568: ( 23, 23, 23) #171717 grey9
495: ( 24, 24, 24) #181818 rgb(24,24,24)
373: ( 25, 25, 25) #191919 rgb(25,25,25)
406: ( 26, 26, 26) #1A1A1A grey10

It is strange, but I thought the raw values would be in the range of 0-65535 and not 0-26? Am I misunderstanding the histogram?


Can someone please clarify these 2 questions.

Thanks

Fred
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug with -threshold and/or histogram?

Post by magick »

We can reproduce the problem and have a patch to fix the problem for ImageMagick 6.6.0 Beta available by sometime tomorrow. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug with -threshold and/or histogram?

Post by fmw42 »

IM 6.6.0-0 Q16 Mac OSX Tiger

This bug still exists and now seems worse. Note the -threshold 50%

convert -background black -fill white -font Candice -pointsize 36 -kerning 5 +dither label:"ABCDEFGHIJKLMNOPQRSTUVWXYZ" -threshold 50% alphabet1.gif

$ identify -verbose alphabet1.gif
Image: alphabet1.gif
Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 975x40+0+0
Resolution: 72x72
Print size: 13.5417x0.555556
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 255 (1)
mean: 90.5512 (0.355103)
standard deviation: 122.029 (0.478544)
kurtosis: -1.63328
skewness: 0.605576
Histogram:
25151: ( 0, 0, 0) #000000 black
13849: (255,255,255) #FFFFFF white


Correct me if I am wrong, but on Q16, should not the min, max and mean raw values be in range 0-65535 and not 0-255, even when specifying -depth 8?

Likewise, I thought the histogram raw values would be in range 0-65535 and not 0-255.

Am I mistaken?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug with -threshold and/or histogram?

Post by magick »

The verbose identify information is reported at the depth of the image. Your image is 8-bits so the max intensity would be 255.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug with -threshold and/or histogram?

Post by fmw42 »

OK thanks for correcting me on that.

Fred
Post Reply