Marcus Nunes
Marcus Nunes

Reputation: 861

Convert RGB to Grayscale in ImageMagick (but not the entire image)

I have the following bar chart:

enter image description here

I transformed it to greyscale using the following command:

convert image.tif -set colorspace Gray -separate -average image_greyscale.tif

and my result was

enter image description here

It is greyscale indeed, but the axes and the legend are grey as well. This is obvious now, but I'd like them to be black, like in the original image. Something like this:

enter image description here

How can I do it? Remake the bar charts again, with a greyscale palette, is not possible right now.

Upvotes: 3

Views: 1166

Answers (2)

fmw42
fmw42

Reputation: 53174

I think what you want to do in ImageMagick is simpler than your command. Just do

Input:

enter image description here

convert barchart.png -colorspace gray result.png

Result:

enter image description here

Upvotes: 3

Mark Setchell
Mark Setchell

Reputation: 207863

You can select the plum colour and change that to gray20 and then select the lime colour and change it to gray80 like this:

magick chart.png -fuzz 10%               \
   -fill gray20 -opaque "rgb(68,1,84)"   \
   -fill gray80 -opaque "rgb(122,209,81)"  result.png

enter image description here

Or, as a one-liner:

    magick chart.png -fuzz 10% -fill gray20 -opaque "rgb(68,1,84)" -fill gray80 -opaque "rgb(122,209,81)"  result.png

Upvotes: 1

Related Questions