I'm trying to remove white lines which cute in pieces an image.
I'm using :
convert input.png -fill white +opaque "#e6e6e6" -fill black -opaque "#e6e6e6" -median 2 -magnify result.png
to remove the background with the following output :
How could I remove those white lines using ImageMagick ?
Thanks
You could use the morphological operators that have been introduced into ImageMagick, specifically the dilation operator. It grows the white regions of the image, which is the opposite of what you want so we negate the image first, making blacks white, do the morphology then negate back to your original.
As the gaps are along a horizontal line, we want a vertical structuring element for the morphology, so we can use a vertical line one pixel wide and several pixels tall - I chose 9 pixels. So, all in all, your command looks like this:
convert in.jpg -negate -morphology dilate rectangle:1x9 -negate out.jpg
The result looks like this:
Related
I would like to ignore/filter white and those that are close to white when using this type of command
convert $file -colors 10 -format "%c" histogram:info:
I have some images that are predominantly white in their content and i'd like to focus on the other colours.
I thought i could use something like -fuzz 20% -fill "#0000ff" -opaque white to change all white and white'ish into a simple blue which i could then grep out in the histogram output but no luck.
Can anyone point me in the correct direction or offer an example please ?
Let's say for example i have a photo that contains a very overexposed sky i.e lot's of white. I'd like the histogram output to ignore that part of the photo and instead output the other top 10 colours that are in the photo.
Thanks
fLo
I have a image like below:
And I wanted to convert into something like below using imagemagick 6. How is that possible? I have gone through chop/shave/crop they all applicable to all sides symmetrically what I need is a partially chopped edges as below:
I have gone through https://www.imagemagick.org/Usage/crop/#chop but it helps to chop an entire edge/side but I need to remove edges partially.
You can achieve that by drawing a simple, white-filled polygon:
magick start.png -fill white -draw "polygon 0,0 60,0 60,16 16,16, 16,60 0,60" result.png
I have used a series of CLI statements to take any (simple) picture to a printable dxf file.
I have used a mixture of ImageMagick and potrace to get this to work as I like, however, I would like to combine this all into one process, whether that be through a python library or some other language?
What I have done so far:
original oddish
magick convert oddish.bmp -colorspace gray oddishBW.bmp
oddish black and white
magick convert oddishBW.bmp -negate oddishBwB.bmp
oddish black and white inverted
magick convert oddishBwB.bmp -morphology dilate Disk oddishBWBD.bmp
oddish black and white inverted with thicker lines
magick convert oddishBwBD.bmp -negate oddishbwbdw.bmp
oddish with thicker lines inverted to normal
potrace --svg oddishbwbdw.bmp -o oddishbwbdw.svg
final svg of oddish
Name explanations:
bw is standing for black and white
bwb is black white black (negate makes the colors opposite)
bwbd is black white black dilate (for increasing line thickness)
In addition: I realize the python libraries for imagemagickpython haven't been updated for a long time and don't include morphology features?
I have question. Is it possible to delete all colors from image, but save the black color? I have a picture with several unknown colors. (Therefore I can't just replace e.g red color with white color). I have an image like this:
And I am trying to delete this "Text2" and "Text3". Is that possible? Which option in Imagemagick should I use?
Mark's answer is probably the best if you easily can separate the black region from the rest of the image, since it preserves the antialiased text better. However, if not then you can do something similar to Bonzo's command. Here is another variation of that.
convert EWwSX.jpg -fuzz 40% -fill white +opaque black result.png
Not sure I understand your question - you can't really delete a colour in an image. What would be left? I understand you can't replace the red with white because you have reds elsewhere in your image.
I guess the easiest thing to do is draw a white rectangle over the unwanted text:
convert text.jpg -fill white -draw "rectangle 20,72 100,150" result.jpg
Not a great result but with some tweeking or work you could improve it:
convert EWwSX.jpg -threshold 20% black.png
I have used the following imagemagick command for the image below:
convert img.png -define morphology:compose=darken -morphology Thinning Rectangle:17x1+0+0\< tmp.png
This removes ALL lines from the image, but I just want to remove the small horizontal and vertical lines on the right and bottom of the number in top left corner of each block. I want to preserve the main column and row lines. Can anyone tell me how to do it?
This is what I get (notice the long lines dividing the image content into columns and rows are also gone. I want those line to stay):
I notice the script is finer/thinner and less regular than the lines so it is more susceptible to eroding techniques. With that in mind we can ditch the text like this:
convert vcards.png -colorspace gray -threshold 50% -morphology erode disk:1.5 +repage z1.png
That's a good start, but if we use that as a mask, we will lose the long horizontal lines in your original image. So, we can find all those by projecting all the rows into a single-pixel wide tall column and thresholding all the rows that are more than 80% white. Then widen the image back out to its original width.
convert z1.png -colorspace gray -resize 1x\! +repage -threshold 80% -scale 810x1518\! +repage z2.png
Now combine the two masks so they only do the lower and right sides of your little title box things.
convert z1.png \( z2.png -negate \) -compose darken -composite z3.png
Finally, fatten that mask up a bit because it may have shifted around during previous processing, and apply it to your original image.
convert vcards.png \( z3.png -morphology dilate disk:2 -negate \) -compose darken -composite result.png
It could all be combined into a single command, but I won't do that, because some aspects may not work for all your images and while they are all individually implemented and documented, they are simpler to improve or correct individually.
you can use the followin code for horizontal an change it slightly for vertical lines
magick 21.gif -monochrome ( +clone -negate -statistic median 219x1 ) -compose lighten -composite q1.png