create and save a clipping path tp JPEG?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
javaMonk

create and save a clipping path tp JPEG?

Post by javaMonk »

Hi All,

great info on this site/forums re: making transparent images, etc.

I was wondering if the following is possible:

..I need to find the area that would otherwise normally be made transparent (the background of an image around an object) and define that as a clipping path (also sometimes called a working path, or mask path), then save that back into a JPEG.

..I've read lots of info about manipulating images that have a clipping path embedded, but nothing about auto-creating a clipping path and saving it back. Anyone have any thoughts?

..thanks in advance,
javaMonk();
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: create and save a clipping path tp JPEG?

Post by fmw42 »

javaMonk wrote:Hi All,

great info on this site/forums re: making transparent images, etc.

I was wondering if the following is possible:

..I need to find the area that would otherwise normally be made transparent (the background of an image around an object) and define that as a clipping path (also sometimes called a working path, or mask path), then save that back into a JPEG.

..I've read lots of info about manipulating images that have a clipping path embedded, but nothing about auto-creating a clipping path and saving it back. Anyone have any thoughts?

..thanks in advance,
javaMonk();
I don't think IM can create a clipping path. But I am no expert on that aspect. But why do you need the clipping path if you are going to convert it to an image. Just separate the foreground and background using a mask created by thresholding or some other segmentation method.

see my magicwand script for example at http://www.fmwconcepts.com/imagemagick/index.php

Perhaps an example image might help us understand what you want and allow us to try some things that might help.
javaMonk

Re: create and save a clipping path tp JPEG?

Post by javaMonk »

fred- thanks very much for the response. Your scripts are truly awesome.

let me try differently to explain (what I think I want) (-:

..i need to do background detection (i need it to be contiguous) - but not remove the background. Based on the background detection I think I want to generate a mask based on the background detection and save it to an alpha channel.
..is this possible? ..if so, what output format can store the alpha channel? ..i know targa can.. can anything else?

..i think part of my confusion is that alpha channels are sometimes called matte in IM - also, i get confused about what format can store what data. (e.g. JPEG doesn't seem to store alpha channels, but it can store a photoshop "path" - GIMP cannot read a path created in photoshop, but it can write it's own path) bah!

--much thanks! -monk
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: create and save a clipping path tp JPEG?

Post by fmw42 »

javaMonk wrote:fred- thanks very much for the response. Your scripts are truly awesome.

let me try differently to explain (what I think I want) (-:

..i need to do background detection (i need it to be contiguous) - but not remove the background. Based on the background detection I think I want to generate a mask based on the background detection and save it to an alpha channel.
..is this possible? ..if so, what output format can store the alpha channel? ..i know targa can.. can anything else?

..i think part of my confusion is that alpha channels are sometimes called matte in IM - also, i get confused about what format can store what data. (e.g. JPEG doesn't seem to store alpha channels, but it can store a photoshop "path" - GIMP cannot read a path created in photoshop, but it can write it's own path) bah!

--much thanks! -monk
There are many ways in IM to separate foreground and background. They may or may not be contiguous, depending upon what method. You can also use -draw "polygon" to create a "path" and use that to fill the inside with some color thereby creating the foreground and then using -fill +opaque to change the color of the background (non-interior). This can then be put in an alpha channel.

I am no expert on all the image types that will save an alpha channel, but I know that PNG will do that and is a very common format. It can store a grayscale alpha (transparency that can vary continuously). GIF can store a binary alpha (on or off). Also IM MIFF can store alpha, but I expect you want something more portable, like PNG or GIF.

Hopefully Anthony or Magick can give you more details on image types that save alpha channel.
Post Reply