Hello there,
I want to trim the dimensions, dimension lines which are present around the window drawing and preserve only the window image. How can do that using Image Magick ?
Version: ImageMagick 7.0.5-5 Q16 x86_64 2017-04-25
Running on macOS Sierra 10.12.5
Can anyone please help?
Thanks in advance.
Cheers,
Ashish
[HELP] Trim the dimensions around diagram
-
- Posts: 5
- Joined: 2017-06-06T07:49:46-07:00
- Authentication code: 1151
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: [HELP] Trim the dimensions around diagram
Please do not double post to two different forums.
Do you want to trim this diagram or an image to this format? If the latter, then please supply an input image. If the former, what area do you want left -- the white center only?
Do you want to trim this diagram or an image to this format? If the latter, then please supply an input image. If the former, what area do you want left -- the white center only?
-
- Posts: 5
- Joined: 2017-06-06T07:49:46-07:00
- Authentication code: 1151
Re: [HELP] Trim the dimensions around diagram
Thanks for your swift response fmw42.
The input image is the one which I have shared earlier.
The resultant image should look like this :
Cheers,
Ashish
The input image is the one which I have shared earlier.
The resultant image should look like this :
Cheers,
Ashish
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: [HELP] Trim the dimensions around diagram
Is this what you want? I change all white to black, then get the trim coordinates, then crop the originals using the trim coordinates. You would be better off using a non-compressed format for your diagram, such as png or tif.
Code: Select all
magick UY6RfhU.jpg -write mpr:img -fuzz 10% -fill black -opaque white -set option:cropvals "%@" +delete mpr:img -crop "%[cropvals]" +repage UY6RfhU_crop.png
-
- Posts: 5
- Joined: 2017-06-06T07:49:46-07:00
- Authentication code: 1151
Re: [HELP] Trim the dimensions around diagram
Thanks a lot for the response fmw42.
I tried the command on my system, unfortunately, it is not working.
Can you please give this same effect with mogrify?
Also it would be great if you can explain how this command actually works.
Cheers,
Ashish
I tried the command on my system, unfortunately, it is not working.
Can you please give this same effect with mogrify?
Also it would be great if you can explain how this command actually works.
Cheers,
Ashish
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: [HELP] Trim the dimensions around diagram
The command probably will not work in mogrify. The explanation is above my result.
-write mpr:img (saves a copy of the input)
-fuzz 10% -fill black -opaque white (changes all white to black)
-set option:cropvals "%@" (saves the trim values as cropvals without having to use -trim)
+delete mpr:img (deletes the previous version that had black replacing white and reloads the input image)
-crop "%[cropvals]" +repage (crops the input image using the stored cropvals)
My command works on IM 7.0.5-10 Q16 Mac OSX Sierra. So perhaps you need to upgrade ImageMagick, unless you copied the command and it got split to more than one line. If so, make sure you edit the command so that it is one command on one long line of text. Then copy that and paste into a terminal window.
I suggest if you want to use this on lots of images, you write a script loop over each image and then call this command.
One issue is that your images are jpg. This means they are compressed and the solid areas of colors are not going to be perfectly uniform. Thus the -fuzz 10% may need to be changed for each image. That is why I suggested that your input images be non-lossy-compressed formats such as png or tif. Then the -fuzz should not be needed. However, you cannot just change jpg to png, since the loss is already there now.
-write mpr:img (saves a copy of the input)
-fuzz 10% -fill black -opaque white (changes all white to black)
-set option:cropvals "%@" (saves the trim values as cropvals without having to use -trim)
+delete mpr:img (deletes the previous version that had black replacing white and reloads the input image)
-crop "%[cropvals]" +repage (crops the input image using the stored cropvals)
My command works on IM 7.0.5-10 Q16 Mac OSX Sierra. So perhaps you need to upgrade ImageMagick, unless you copied the command and it got split to more than one line. If so, make sure you edit the command so that it is one command on one long line of text. Then copy that and paste into a terminal window.
I suggest if you want to use this on lots of images, you write a script loop over each image and then call this command.
One issue is that your images are jpg. This means they are compressed and the solid areas of colors are not going to be perfectly uniform. Thus the -fuzz 10% may need to be changed for each image. That is why I suggested that your input images be non-lossy-compressed formats such as png or tif. Then the -fuzz should not be needed. However, you cannot just change jpg to png, since the loss is already there now.
Re: [HELP] Trim the dimensions around diagram
One thing I would do to neaten up the image would be to add a couple of pixel wide black border.
-
- Posts: 5
- Joined: 2017-06-06T07:49:46-07:00
- Authentication code: 1151
Re: [HELP] Trim the dimensions around diagram
Thanks for the super explanationfmw42 wrote: ↑2017-06-06T10:53:09-07:00 The command probably will not work in mogrify. The explanation is above my result.
-write mpr:img (saves a copy of the input)
-fuzz 10% -fill black -opaque white (changes all white to black)
-set option:cropvals "%@" (saves the trim values as cropvals without having to use -trim)
+delete mpr:img (deletes the previous version that had black replacing white and reloads the input image)
-crop "%[cropvals]" +repage (crops the input image using the stored cropvals)
My command works on IM 7.0.5-10 Q16 Mac OSX Sierra. So perhaps you need to upgrade ImageMagick, unless you copied the command and it got split to more than one line. If so, make sure you edit the command so that it is one command on one long line of text. Then copy that and paste into a terminal window.
I suggest if you want to use this on lots of images, you write a script loop over each image and then call this command.
One issue is that your images are jpg. This means they are compressed and the solid areas of colors are not going to be perfectly uniform. Thus the -fuzz 10% may need to be changed for each image. That is why I suggested that your input images be non-lossy-compressed formats such as png or tif. Then the -fuzz should not be needed. However, you cannot just change jpg to png, since the loss is already there now.
The crop issue was resolved as I upgraded the Image Magick to version 7.0.5-10 Q16.
I will surely incorporate your suggestion of working with png/tiff images.
Thanks a lot again.
Cheers,
Ashish
-
- Posts: 5
- Joined: 2017-06-06T07:49:46-07:00
- Authentication code: 1151