Page 1 of 1

Chaining operations to make a single set of images from 1.

Posted: 2012-04-16T07:48:35-07:00
by RQuadling
Hello.

The following code works for what it does.

It takes an image and produces several images, but only works with images with a solid white background.

Code: Select all

convert B.jpg \
-fuzz 3.8% -trim +repage -write B_trim.jpg \
\
\( +clone -rotate 90 +clone -mosaic +level-colors white \) +swap -gravity center -composite -write mpr:original \
\
\( +clone -resize 300x300 +repage -write B_large.jpg  +delete \) \
\( +clone -resize 150x150 +repage -write B_medium.jpg +delete \) \
\( +clone -resize 100x100 +repage -write B_small.jpg  +delete \) \
\( +clone -resize  60x60  +repage -write B_tiny.jpg   +delete \) \
\
\( +clone -fx 'p { 0, 0 }' \) \
\
-compose Difference -composite -modulate 100,0 -alpha off -threshold 3.8% -blur 0x1 mpr:original +swap -alpha Off -compose CopyOpacity -composite \
\
\( +clone -trim                 +repage -write B_original.png +delete \) \
\( +clone -trim -resize 300x300 +repage -write B_trim.png     +delete \) \
\( +clone       -resize 150x150 +repage -write B_medium.png   +delete \) \
\( +clone       -resize 100x100 +repage -write B_small.png    +delete \) \
\( +clone       -resize  60x60  +repage -write B_tiny.png     +delete \) \
\
B_original.jpg

What I want to do is extend this to non white solid or near solid colours.

Image, Image, Image

There are various ideas that come to mind. And all the automatic image manipulation output is verified by a man (he's called Steve - everyone say "Hello, Steve!").

Using -edge 1 on these images produces a nice looking mask. If there was a way to use a mask for the initial edge detection, then ... how?

I'm sure there is an easy way to do this, but I can't seem to cast the appropriate magick spell.

Any help would be really appreciated.

Regards,

Richard Quadling.

Re: Chaining operations to make a single set of images from

Posted: 2012-04-16T10:59:03-07:00
by fmw42
I am not following the issue? Are you just trying to make the background some solid color such as black or white? Do you want to get a mask of the shirt.

try

convert upload1021977025338634797.jpg -fuzz 22% -fill black +opaque white -fill white -opaque white upload1021977025338634797_mask.png

However, it will not be perfect and the fuzz level will need to be different for each image as the background is not solid. Some imperfections can be removed with -morphology

see
http://www.imagemagick.org/Usage/morphology/
http://www.imagemagick.org/Usage/photos/#chroma_key

Re: Chaining operations to make a single set of images from

Posted: 2012-04-17T08:18:35-07:00
by RQuadling
OK. I'll try to explain.

We have a web site which pulls in thousands of images a month. The images are clothing, shoes, jewellery, etc.

We take these images and, in essence, extract the product from the background and make several other images from it. These new images are fixed sizes and a combination of solid white background images and some transparent background images.

At the moment, if the image has a pure white background, we are able to use the image and process it.

We want to be able to handle images where the background is not solid white. In the main it is a grey colour or a gradient.

I think I need to create a mask based upon the -edge feature, but I don't know how to 'fill' in the mask so that holes in the image (like the ones created by the arms in the first example image supplied) are catered for.

I'm not an image manipulation expert, and I don't know what terminology I should be using.

I know I can't just use colour replacement, so edge detection and masking I think are the order of the game. But I don't know how to chain all the parts together.

Richard.

Re: Chaining operations to make a single set of images from

Posted: 2012-04-17T09:49:22-07:00
by fmw42

Re: Chaining operations to make a single set of images from

Posted: 2012-04-17T18:03:40-07:00
by anthony
But it will be 'aliased' :-)
I hate aliased edges!

Re: Chaining operations to make a single set of images from

Posted: 2012-04-17T18:20:36-07:00
by fmw42
anthony wrote:But it will be 'aliased' :-)
I hate aliased edges!
Once you get a binary mask, you can "feather" the edges to create an "anti-aliasing" effect.