Trim non-uniform backgrounds
Posted: 2015-07-10T01:43:35-07:00
I have a number of product images that I need to process to convert from landscape/portrait into square images. The approach I have taken is to:
1. Trim
2. Add border
3. Pad to square
This is being done via im4java on OSX with ImageMagick 6.9.1-1.
I have some working commands for this process but a number of images are not being trimmed correctly due to artefacts in the image or non-uniform background. The trim command is very basic:
convert ./input.jpg -trim cropped.jpg
I think I need an additional step before the trim to clean up the background of the images but have no idea of the best way to do this. Samples of the images are below:
Image 1 - https://www.dropbox.com/s/5u9adlgxij05j ... 1.jpg?dl=0
Image 1 (adjusted to show issues) - https://www.dropbox.com/s/nuxzffapl58a8 ... d.jpg?dl=0
Image 2 - https://www.dropbox.com/s/94pvlwn8lkgvq ... 2.jpg?dl=0
Image 2 (adjusted to show issues) - https://www.dropbox.com/s/0j05upma44x9x ... d.jpg?dl=0
These images have all been processed quite heavily and I am looking for a way to ensure that they can be trimmed correctly.
As a bonus the 3rd example is on that appears to have got through without the processing (Background not set to white). I'm ok if I need to use a service like http://uk.pixelz.com/pricing/ for the few images that are like this but would be interested in whether ImageMagick can handle it.
Image 3 - https://www.dropbox.com/s/z519ingxhoomx ... 3.jpg?dl=0
For this one the entire background needs to be set to white so that is can be trimmed and re shaped withe a uniform white background.
If you think you can help please PM and let me know if you need any more info.
1. Trim
2. Add border
3. Pad to square
This is being done via im4java on OSX with ImageMagick 6.9.1-1.
I have some working commands for this process but a number of images are not being trimmed correctly due to artefacts in the image or non-uniform background. The trim command is very basic:
convert ./input.jpg -trim cropped.jpg
I think I need an additional step before the trim to clean up the background of the images but have no idea of the best way to do this. Samples of the images are below:
Image 1 - https://www.dropbox.com/s/5u9adlgxij05j ... 1.jpg?dl=0
Image 1 (adjusted to show issues) - https://www.dropbox.com/s/nuxzffapl58a8 ... d.jpg?dl=0
Image 2 - https://www.dropbox.com/s/94pvlwn8lkgvq ... 2.jpg?dl=0
Image 2 (adjusted to show issues) - https://www.dropbox.com/s/0j05upma44x9x ... d.jpg?dl=0
These images have all been processed quite heavily and I am looking for a way to ensure that they can be trimmed correctly.
As a bonus the 3rd example is on that appears to have got through without the processing (Background not set to white). I'm ok if I need to use a service like http://uk.pixelz.com/pricing/ for the few images that are like this but would be interested in whether ImageMagick can handle it.
Image 3 - https://www.dropbox.com/s/z519ingxhoomx ... 3.jpg?dl=0
For this one the entire background needs to be set to white so that is can be trimmed and re shaped withe a uniform white background.
If you think you can help please PM and let me know if you need any more info.