export ROI as svg

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

export ROI as svg

Rizwan Mumtaz
Hello there,

Is it possible to convert the ROI to support vector graphics format so that
it could be used by Inkscape or similar softwares?

Thanks and regards,
Rizwan

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: export ROI as svg

dscho
Hi Rizwan,

On Mon, 7 Oct 2013, Rizwan Mumtaz wrote:

> Is it possible to convert the ROI to support vector graphics format so
> that it could be used by Inkscape or similar softwares?

Should be very easy as a macro... I would start by exporting a plain .svg
of a simple polygon from Inkscape, look at the file contents and then
imitate that with a macro using the getSelectionCoordinates function.

Hth,
Johanes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: export ROI as svg

dscho
Hi Rizwan,

On Mon, 7 Oct 2013, Rizwan Mumtaz wrote:

> [hidden email]> wrote:
>
> > On Mon, 7 Oct 2013, Rizwan Mumtaz wrote:
> >
> > > Is it possible to convert the ROI to support vector graphics format so
> > > that it could be used by Inkscape or similar softwares?
> >
> > Should be very easy as a macro... I would start by exporting a plain .svg
> > of a simple polygon from Inkscape, look at the file contents and then
> > imitate that with a macro using the getSelectionCoordinates function.
>
> Thank you for your response. I am a little new to ImageJ and programming in
> general. Could you elaborate a little more on what you said? As far as I
> understand, Inkskape only exports to bmp and also svg can not be imported
> by imageJ (please correct me if I am wrong). Is my understanding correct?

You are correct, File>Export does not let you choose "Plain SVG". But
"Save As" or "Save a Copy" does. The idea was anyway to save an example
file from Inkscape.

I just did that and got a file that starts with

        <?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <!-- Created with Inkscape (http://www.inkscape.org/) -->
        ...

I tried to abridge the content a little and this is what I came up with:

        <svg>
                <g>
                        <path d="m 194,203 231,2 31,180 -108,125 z" />
                </g>
        </svg>

It appears that the first coordinate is absolute, followed by relative
ones. So this simple macro should output the current ROI as a string that
can be saved to a .svg file that Inkscape imports:

-- snip --
getSelectionCoordinates(x, y);
text = "<svg><g><path d='m";
x2 = y2 = 0;
for (i = 0; i < x.length; i++) {
        text = text + " " + (x[i] - x2) + "," + (y[i] - y2);
        x2 = x[i];
        y2 = y[i];
}
text = text + " z' /></g></svg>";
print(text);
-- snap --

As you can see, it is not really complicated. You might want to learn the
macro language to adjust this little snippet to your needs. In any case,
learning the macro language will enable you to solve so many more problems
in the future, and it is not really involved to learn it anyway.

Ciao,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html