Using ImageMagick, I want to find any pixels that are white and make them transparent. I'm thinking the key is -threshold but I can't work out how to change a white pixel to transparent using -threshold. Any suggestions most appreciated.
convert input.png -fuzz 10% -transparent white output.png
Note that the order of the arguments is important - -fuzz must come before -transparent.
Would something like this work?
convert input.jpg -fuzz 5% -fill to_color -opaque from_color output.jpg
Related
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
I have scanned books with black imitation leather as background.
The text recognition unfortunately recognizes text on this background. I like to color the border black, so that the program does not find any text at the edge. Is this possible with tools like ImageMagick or GraphicsMagick?
Here is an example (original is in tif):
Perhaps a combination of floodfill and fuzz?
convert input.png -fill white -fuzz 20% -draw 'color 1,1 floodfill' output.png
Also checkout Fred's awesome textcleaner script.
emcconville has an excellent solution. I might add just a bit to it to include some deskew and trim/shave, since your margins are large enough to permit shaving the excess black that remains after a trim. The deskew might help in the OCR.
convert image.png -bordercolor black -border 1 -background black -deskew 40% -fuzz 50% -trim +repage -shave 10x10 result.png
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
I want to convert the background of a image to transparent. I have used the below script for converting. Also i am converting the image to png.
convert -resample 300x300 -depth 8 "%1"[0] -fuzz 10% -transparent white -flatten -resize 1260x1260 -quality 80 "%2".
I also tried below command:
convert -resample 300x300 -depth 8 "%1"[0] -background none -flatten -resize 1260x1260 -quality 80 "%2"
but using the above script background is not converted to transparent.
Can you please let me know the Imagemagick script for converting the background.
Thanks in advance.
Updated Answer
You really need to show your image, but if the background his white as you say, this should work:
convert start.png -fuzz 40% -transparent white result.png
If that doesn't work, I really cannot help till you show the image.
Original Answer
You need to be clearer as to what colour the background currently is, and how it can be identified - or show your image.
If we assume this is your starting image:
then we can make the blue pixels transparent like this:
convert start.png -fuzz 10% -transparent blue result.png
If we take this as your start image:
and set the fuzz to "within 10% of black", we will do this:
convert start.png -fuzz 10% -transparent black result.png
whereas if we make pixels within 30% of black become transparent:
convert start.png -fuzz 30% -transparent black result.png
we will get this:
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