background color after distortion - imagemagick - imagemagick

I am trying to render a text and then apply perspective transformation to that image using imagemagick convert command .
I am trying to use the following command :
convert a.jpg -matte -distort Perspective-Projection '1.0,0.25,0.0,0.0,1,0.0,0.007,0' +repage ' a_new.jpg
The problem is that the resulting image have black background but instead I want it be of same color as that of text background ans same is the case with the color of border . Also ,
the resulting text some times get trimmed , but I want the text content to be preserved . I tried out various combinations of commands but didn't produced the desired result .

Related

Gray scale to text scan image to black/white image with higher resolution

convert 0101.jp2 -threshold 50% -type bilevel -monochrome -compress LZW ../0101.tiff
The resulting image looks jagged when I use the above command to convert a colored scanned text page to a black/white image (must be one bit per pixel). I want to make it of a higher resolution to look smoother. How can I use convert to do so?
Note that SO automatically converts tif image to jpg format so the output image shown below is not the same as the output image. You will need to run the convert command to get the true output image in tif.
If instead of thresholding you apply a strong contrast the gray pixels on the edge remain in a range of grays and the output is not jagged.
convert Original.jpg -sigmoidal-contrast 30 Corrected.jpg
(there are several ways to increase contrast in Magick)

Resizing animated GIF in image creates artifacts

I'm trying to add a blank area around some animated GIFs using imagemagick, but in many cases the resulting larger animations have artifacts. For example, if I start with this image
And run the following command (which has the dispose and coalesce flags which I've thrown in after seeing them online in the hopes they'll help)
convert input.gif -gravity center -dispose previous -extent 500x500 -coalesce output.gif
The result is the following
Is there a different command I can run that wouldn't gave the green splotches invade the original image?
You have your syntax wrong for ImageMagick and also need to use -dispose none. You are adding a new color to your animation which likely already used 256 colors.
Input:
convert -dispose none input.gif -coalesce -gravity center -background green -extent 500x500 -layers optimize output.gif
Change the background color as desired, which you left out of your command.

How to remove specific white space from image using ImageMagick

Currently, I have thousands of pictures where I want to get rid of white space around the object, but not inside the object. However, the white space is not constant. See pictures below.
Picture 1 :
Picture 2 :
Picture 3 :
Options like this don't work as they delete all white space in the images
convert image.png -fuzz 10% -transparent white output.png
Any suggestions?
What do you mean by getting rid of the white space? If you mean make it transparent, then in ImageMagick 6, you can do a whole folder of images using the mogrify command as follows:
The process involves padding the image with 1 pixel border of white to ensure white is all around. Then doing a fuzzy flood fill. Then remove the extra one pixel all around. I have assumed that the background color is nearly white. Change the fuzz value as desired.
Create a new directory to hold the output (or backup your input directory)
Change directory to the one holding your input images
mogrify -path path_to/outdirectory -format png -bordercolor white -border 1 -fuzz 20% -fill none -draw "matte 0,0 floodfill" -shave 1x1 *.png
Here are the resulting images.
Of course you will have to download them to see that they are transparent.
Note that the images that I downloaded were JPG. So if your images are jpg and not png as in your command, then change *.png to *.jpg. Or just use * to change all formats.
See
https://imagemagick.org/Usage/basics/#mogrify
https://imagemagick.org/Usage/draw/#matte
If using ImageMagick 7, change matte to alpha and change mogrify to magick mogrify.

imagemagick - animate, with a static black background?

Just a quickie.
I have a series of images min*.png that I want to animate into a gif.
They are each fully transparent, except for some white dots on the area I want filled in for that frame.
Is there some way to create an animation from these such that the background is black (so that the whtie dots show up?)
I am interested in both:
black background, and paste each successive image on top of the previous ones (so frame i is the black background plus all of the dots up to image i)
each frame consists of just (image i on a black background)
I think for 1. I need to use -dispose none and for 2 I use -dispose background or -dispose previous, but various attempts at actually setting the background to black have failed (I have spent a lot of time reading this imagemagick page but am still learning).
e.g.
convert -background black -dispose background min*.png out.gif
various attempts with -background and -dispose have invariably produced a gif of my min*.png with a transparent background, not a black one. I think I'm close, but not sure.
This may be useful for the black background problem: starting from ImageMagick 6.7.5 you can remove transparency and replace it with a static color; you can read more about this command here
Hope this helps, unfortunately I have an older version of Imagemagick, so i can't try it myself
Example from ImageMagick documentation:
convert moon.png -background tan -alpha remove alpha_remove.png
The color "tan" replaces the transparent areas of the picture
Comment from mathematical.coffee
Using the above answer, I was able to generate the animations I wanted.
1: successive buildup of dots, all on a black background. Turned out to be as simple as creating a black background picture to put at the start of the animation, and using -coalesce:
# where bg.png is a black png of the appropriate size:
convert bg.png min*.png -coalesce out.gif
# in the below the first line creates the black background
# image, same size as my first min00.png image, for me:
convert min00.png -alpha Opaque +level-colors black \
min*.png -coalesce out.gif
2. use the method mentioned above:
convert min000*.png -background black -alpha remove out.gif
In both I was using imagemagick 6.7.something.

How to replace white background color with transparent of an image in ImageMagick?

I have an image in .jpg format with white background color. I want to remove the white background color to transparent in Imagemagick. I tried many ways but still the white background can not be removed. Can some one help me to solve this.
You cannot have transparent background colors in your JPEGs. The JPEG file format doesn't support transparency.
If you need transparent background, you need to convert the JPEG to
either PNG (high quality, filesize possibly larger than JPEG)
or GIF (in case you can tolerate low quality and a range of maximally 255 colors).
Example command:
convert your.jpg -transparent white your.png
First, you need to convert the image format from .jpg to .png format, because JPEG does not support transparency. Then use this command:
convert image1.png -fuzz 20% -transparent white result.png
The -fuzz option allows the specified percentage deviation from the pure white colour to be converted to transparent as well. This is useful, for example, when your image contains noise or subtle gradients.
I just found a very neat thing!
magicwand 1,1 -t 20 -f image -r outside -m overlay -o 0 image.jpg imgOutput.png
It is a Fred Weinhaus bash script that can be downloaded from here (for non commercial use only). Also there has about 250 scripts!! and this one is amazing! it did exactly the trick, to remove all background while keeping the inner image dots untouched!
At his page, there are several images as examples so you pick what you need to put on the command line!
The initial position 1,1 is a general guesser saying all the contour is background.
Pay attention that the output must be ".png"
This is my solution without magicwand (replace magick by convert for im < 7.0):
magick img.png -fuzz 20% -fill none -draw "alpha 1x1 floodfill" result.png
Get the background automatically and remove it :
bg=$(convert input.png -format "%[pixel:p{0,0}]" info:)
convert input.png -fuzz 20% -transparent "$bg" output.png

Resources