How to remove one portion of image using imagemagick - imagemagick

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

Related

How to crop or chop the images at the L shaped corner edges with imagemagick

[]
I use imagemagick -6 for conversion.
I have an image like above. Actual image resides in the rectangular area. I need to remove the L shaped corner edges as you see. I tried with lots of options available in : https://imagemagick.org/Usage/crop/#splice . As crop/chop and shave options applicable symmetrical to both sides. I was thinking If I can just splice the un-wanted L shaped areas.
I tried with convert -background blue -gravity East -splice 10x10 +repage but of no luck. It basically adds a cross in horizontal and vertical in the middle of the image. Please advise if it possible just to erase/chop a particular area. e.g. some portion of an edge and not the complete edge. The reason here is I don't want to chop-off any part of rectangular shape but the L shapes above and below. Basically looking for removing/splicing with white color just L shaped one corner at a time if possible using Imagemagick-6. As I don't know about the pixel size in advance. I don't know if one liner solution will work.
Many thanks!
I think you mean this:
magick image.png -crop 305x365+232+58 result.png

Trim image with transparency around and know it's location

I know it is possible to trim all transparency around image to make image smaller and contain only the image. But is it also possible to somehow know the location of "box", that contains the image?
For example I have 100x100 transparent image, which contains something at 10x10 box having topleft corner at x=15,y=15. Rest is all transparent.
I'd like to end up with 10x10 image, all transparency around trimmed, but also having that 15,15 information. Those are probably 2 separate actions. How do I do this in a script?
Just fyi - I am having bunch of images like this and they are layers, that I need to trim and stack onto eachother to make them clickable.
There are lots and lots of words but no image in your question so I am trying to guess what you want. I made this input image:
magick -size 100x100 xc:black -fill white -draw "rectangle 10,20 50,80" image.png
And I think you want to know the trim box, which is where it would trim to if you ran -trim:
magick image.png -format "%#" info:
41x61+10+20
So that's a 41x61 box with the top-left at (10,20).

Imagemagick how to delete all colors expect black

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

Finding the Largest Connected Blob Starting from Selected Point

I am trying to extract a region from an image that is already marked with a certain color. In the picture below
I would like to extract only the pixels which belong to the sidewalk, that is, all pixels that belong to the black blob that is connected to the mid-lower part of the image. There are black dots outside that blob which I am not interested in. So if I could get roughly the region shown below
it would be perfect. Does anyone know of some common algorithms that can do this? Morphology? Region growing using a kind of flooding algorithm?
Thanks,
You can do that quite easily with a flood fill. If I use ImageMagick to demonstrate at the command line because it is installed on most Linux distros and is available for macOS and Windows.
So, bearing in mind that the pixel you identified as your seed is at around 440,520 in the image you supplied that includes the axes, we can floodfill all pixels that match that colour and touch the seed with cyan using:
convert scene.png -fill cyan -draw 'color 440,520 floodfill' result.png
Or, we can make a mask by changing the non-cyan pixels to white and the cyan pixels to black:
convert scene.png -fill cyan -draw 'color 440,520 floodfill' -fill white +opaque cyan -fill black -opaque cyan z.png
There are a thousand other things you can simply do from the command line to take this further... fill small holes in the mask, make a transparency layer from the mask - just ask more questions if you need a hand.
If you want to close the holes in your image, you probably want to use morphological functions. I am away from any computers with ImageMagick for a week so I can only tell you in general terms. Start with the pure black and white (no grey) picture above and try:
convert image.png -morphology open disk:3 result.jpg
Try replacing the word open above with close, erode or dilate. Experiment with disk, disk:3 disk:7 and so on.

ImageMagick : remove white lines

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:

Resources