Color Modes

カラーしきい値処理

カラーしきい値処理を使用してカラー範囲を指定し、白黒画像を返します。スタートカラーとストップカラー(両方を含む)の間のすべてのカラーは白色になり、画像ピクセルの残りは黒色になります。2 つのカラーは、その間にハイフンで区切られます。しきい値処理は、デフォルトでは、sRGB カラー空間に適用されます。-colorspace を使用すると、代替カラー空間にしきい値処理を適用できます(現在は、sRGB、グレイ、HSV、HSL、HCL、HSB、および HSW に限定されています)。開始カラーと停止カラーは、ImageMagick で認識されるカラー空間で指定できますが、一般的には、-colorspace オプションに対応するカラー空間で指定することをお勧めします。グレイのカラー空間の場合は、停止値よりも開始値が低くなるようにしてください。色相は循環するため、0 と 360 は同じになります。ただし、色相 = 0 にまたがるカラーの範囲は、開始色相値が停止色相値よりも高い場合でも引き続き役に立つ可能性があります。

開始カラーと停止カラーのカラー空間、および画像のカラー空間を混在させるときは注意が必要です。あるカラー空間の広い範囲は、別のカラー空間では狭い範囲にのみマップされる場合があります。たとえば、sRGB(0,0,0) から sRGB(255,255,255) までにした場合、-colorspace HSV を使用していても、すべてのカラーを取得して白い画像が生成されると単純に考えるかもしれません。しかし、これらの 2 色は黒と白であり、hsv(0,0%,0%)hsv(0,0%,100%) としてグレースケールの範囲にのみマップされます。カラー画像の場合、あまりにも多くのグレイのピクセルは見つからないでしょう。

カラーしきい値処理の動作を図解するには、この画像を使用します

convert input-image -colorspace XXX -color-threshold "start - stop" output-image

次に、一般的な使用例をいくつか示します

    [Color Thresholding]

まず、1 つの sRGB カラー(画像のどこかで、この場合は花の黄色)を選択し、低く、高くオフセットして 2 つの sRGB カラーを作成します。より低い値が開始カラーを形成し、より高い値が停止カラーを形成します。sRGB(183,132,20) から始めます。開始カラー(-)と停止カラー(+)を特定するために、その値を +-20 オフセットします。つまり、R=183+-20、G=132+-20、B=40+-20

magick monet.jpg -color-threshold 'sRGB(163,112,0)-sRGB(203,152,40)' monet.gif

これにより、花びらのアウトラインが返されます

    [Color Thresholding]

次に、2 つの RGB カラー (sRGB(159,150,0)sRGB(205,100,45):) を選択します。

magick monet.jpg -color-threshold 'sRGB(159,150,0)-sRGB(205,100,45)' monet.gif

    [Color Thresholding]

Next, select one sRGB color and convert it to HSV and offset its values low and high to generate the start and stop HSV colors. Use -colorspace HSV to convert the image to HSV. For our HSV example, we pick sRGB(183,132,20) and convert to HSV:

magick xc:"srgb(183,132,20)" -colorspace HSV txt:
# ImageMagick pixel enumeration: 1,1,65535,hsv
0,0: (41.227,89.071%,71.7647%) #1D51E405B7B7 hsv(41.227,89.071%,71.7647%)

Now, offset its HSV values as H=41+-20, S=89+-10, and V=72+-10, to create the start color (-) and stop color (+):

magick monet.jpg -colorspace HSV -color-threshold 'hsv(21,79%,62%)-hsv(61,99%,85%)' monet.gif
    [Color Thresholding]

Next, pick two RGB colors. Use -colorspace HSV to convert the image to HSV, and apply the RGB start and stop colors. Choose sRGB(158,77,33) and sRGB(213,217,2):

magick monet.jpg -colorspace HSV -color-threshold "sRGB(158,77,33)-sRGB(213,217,2)" monet.gif

Here is the expected results:

    [Color Thresholding]

Next, choose two sRGB colors and convert them to gray. Now convert the image to gray and use the gray thresholding colors.

magick xc:"sRGB(159,150,0)" -colorspace gray txt:
# ImageMagick pixel enumeration: 1,1,65535,gray
0,0: (36259.1) #8DA38DA38DA3 gray(55.3278%)

magick xc:"sRGB(205,100,45)" -colorspace gray txt:
# ImageMagick pixel enumeration: 1,1,65535,gray
0,0: (30418.2) #76D276D276D2 gray(46.4152%)

Notice that the start intensity must be smaller than stop intensity:

magick monet.jpg -colorspace gray -color-threshold 'gray(46.4152%)-gray(55.3278%)' monet.gif

Here is the results of the color thresholding operation:

    [Color Thresholding]