ImageMagick replace white with red not working - imagemagick

This is the image:
The light part isn't perfect white but FDFDFD
I tried:
old.png -fuzz 5% -fill red -opaque white new.png
but the white becomes black!

Your image is greyscale. Try making it colour first:
magick old.png -colorspace sRGB -fuzz 5% -fill red -opaque white new.png

Related

Imagemagick - Inverse

I've a png image containing transparent pixels and colored pixels (mainly white).
I'd like to transform all transparent pixels to white pixels and all white pixels to transparent pixels within a given rectangle.
My idea would be to
convert the white pixels to red
the transparent colors to white
and the red colors to transparent
. Here' s my code:
1) convert ldl_0.png -fuzz 10% -fill red -opaque white lx.png
2) convert lx.png -background white -alpha remove -alpha off lx2.png
However I can' t figure out how do I transform red colors to transparent. How do I do that?
Also how can I force to do this only within a given rectangle?
Thank You.
-----
Try this in ImageMagick. Negate the alpha channel and turn the whole RGB channels to white.
convert in.png -channel a -negate +channel -fill white -colorize 100 out.png

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

I have the following bar chart:
I transformed it to greyscale using the following command:
convert image.tif -set colorspace Gray -separate -average image_greyscale.tif
and my result was
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:
How can I do it? Remake the bar charts again, with a greyscale palette, is not possible right now.
I think what you want to do in ImageMagick is simpler than your command. Just do
Input:
convert barchart.png -colorspace gray result.png
Result:
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
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

Auto crop text(signature) from image and change background color using Imagemagick

Need to auto crop text(signature)from an images(sample image:Image1 )and Need to change background color of cropped image.
Need to achieve this using Imagemagick.
Is it any possible way to achieve these ?
I am using version ImageMagick 7.0.7-28
williamson image
example image
What do you mean by auto-crop? You can use ImageMagick -trim to get the signature cropped to its bounding box and then use -fuzz -opaque to change the background.
Input:
magick signature.png -fuzz 20% -trim +repage -fill pink -opaque white result.png
Or you can just make the background transparent.
magick signature.png -fuzz 20% -trim +repage -transparent white result2.png
I do not see any color change in the text, though it is not quite as smooth. Adjust the fuzz value as desired to remove the gray and keep the text as smooth as you can.
Input:
ImageMagick 7 command:
magick signature3.jpeg -fuzz 15% -fill white +opaque "#5B000C" -trim +repage result.png

How to filter 4 different colours on ImageMagick?

I'm using ImageMagick to transform an image into x and y cartesian co-ordinates. The code that I am using in the command line does fine to make all the lines appear as fully black and the blank spaces appear as fully white. Is there a way to also filter for more colours? For example, if the image consists of multiple colours, is there a way to make all the red-type colours fully red, all the blue-type colours fully blue and the other non-white colours as black? Then the background would just be seen as fully white (most images I am using as a picture on a white background). The command line text is:
convert "imagename".png -white-threshold 50% -black-threshold 50% txt:
Using Mark Setchell's code from below, I tried to convert this basic image that I created using paint to test the abilities of IM.
I edited the code slightly so that the background fill would be white instead of black as such;
convert q.png -write MPR:orig -delete 0 -compose lighten ^ ( MPR:orig -fuzz 10% -fill red -opaque red -fill white +opaque red ) ^ ( MPR:orig -fuzz 10% -fill blue -opaque blue -fill white +opaque blue ) -composite ^ ( MPR:orig -fuzz 10% -fill lime -opaque lime -fill white +opaque lime ) -composite ^ f.png
However, the entire image just shows white. Any tips?
Not exactly sure what you want, but maybe this will get us closer. So, we start with this:
And we then do this, which says "make anything within 10% of red into solid red, anything within 25% of blue into solid blue, and so on":
convert start.png -fuzz 10% \
-fill red -opaque red \
-fuzz 25% \
-fill blue -opaque blue \
-fill lime -opaque lime \
-fill white -opaque white result.png
Or maybe more like this:
convert start.png -write MPR:orig -delete 0 -compose lighten \
\( MPR:orig -fuzz 10% -fill red -opaque red -fill black +opaque red \) \
\( MPR:orig -fuzz 20% -fill blue -opaque blue -fill black +opaque blue \) -composite \
\( MPR:orig -fuzz 30% -fill lime -opaque lime -fill black +opaque lime \) -composite \
result.png
That says... "Take the original image and make a copy in the Magick Persistent Register called orig then delete the original. Set the blending mode to select the lightest pixel at each location for any future composite commands. Now make a new layer, fill it with the original image, make anything within 10% of red into solid red and make anything else black. Now do the same for colours within 20% of blue and blend taking the lighter layer - so the blues and reds show instead of the blacks which will always be darkest. Do the same again for lime - which is how ImageMagick refers to pure green.""
Note how the green is larger than the blue which, in turn, is larger than the red because of the differing amounts of fuzz I applied - i.e. 30%, 20% 10%.
I think that looks like this with Windows-style quoting:
convert start.png -write MPR:orig -delete 0 -compose lighten ^
( MPR:orig -fuzz 10% -fill red -opaque red -fill black +opaque red ) ^
( MPR:orig -fuzz 20% -fill blue -opaque blue -fill black +opaque blue ) -composite ^
( MPR:orig -fuzz 30% -fill lime -opaque lime -fill black +opaque lime ) -composite ^
result.png

ImageMagick: How to make both black and white transparent?

Converting black and dark shades to transparent works fine with ImageMagick.
I even managed to perform a crop and resize in the same line.
convert input.png -background none -fuzz 45% -transparent black -flatten -crop 640x480+12+9 -resize 105% output.png
However, the input image also contains a number of almost white lines, which I also would like to convert to transparent in the output.
How do I go about that? Is it possible to do it within the same command line?
Sure, just add a second -transparent.
convert -size 512x512 gradient:black-white a.png # create initial black-to-white gradient
convert -fuzz 20% a.png -transparent black -transparent white result.png # lose 20% off black end and white end
Or, with extra fuzz...
convert -fuzz 40% a.png -transparent black -transparent white result.png

Resources