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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
RQuadling
Posts: 38
Joined: 2006-12-04T02:48:33-07:00
Location: Plymouth, Devon, UK
Contact:

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
RQuadling
Posts: 38
Joined: 2006-12-04T02:48:33-07:00
Location: Plymouth, Devon, UK
Contact:

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post by anthony »

But it will be 'aliased' :-)
I hate aliased edges!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
Post Reply