Adding text "Destructively" to the image

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding text "Destructively" to the image

davek604
Hello

I'm writing a plugin to add text permanently to an image. It forms part of a loop which moves through an image stack adding numbers (as text) where required. I'm using the code below to add the text

               String TheText = Integer.toString(count);
        Font font = new Font("SansSerif", Font.PLAIN, 9);
        TextRoi roi = new TextRoi(Xval, Yval, TheText, font);
        roi.setStrokeColor(Color.white);
        Overlay overlay = new Overlay();
        overlay.add(roi);
        Dupimp.setOverlay(overlay);

This adds the text as an overlay which can't then be made part of the image. The Draw command will do this but the text would have to be a selection which I can't work out how to do. Any suggestions as to how I can make the text permanent would be appreciated.

Regards

David  
Reply | Threaded
Open this post in threaded view
|

Re: Adding text "Destructively" to the image

Graeme Ball-3
Hi Dave,

For an overlay, I think you can use:
  ImagePlus imp2 = imp.flatten();

Regards,

Graeme

--
---------------------------
Dr. Graeme Ball
Dundee Imaging Facility
College Of Life Sciences
University of Dundee
Dow Street
DD1 5EH
Email: [hidden email]
Phone: +44-1382-385741
---------------------------


On Wed, Feb 3, 2016 at 3:07 PM, davek604 <[hidden email]> wrote:

> Hello
>
> I'm writing a plugin to add text permanently to an image. It forms part of
> a
> loop which moves through an image stack adding numbers (as text) where
> required. I'm using the code below to add the text
>
>                String TheText = Integer.toString(count);
>                 Font font = new Font("SansSerif", Font.PLAIN, 9);
>                 TextRoi roi = new TextRoi(Xval, Yval, TheText, font);
>                 roi.setStrokeColor(Color.white);
>                 Overlay overlay = new Overlay();
>                 overlay.add(roi);
>                 Dupimp.setOverlay(overlay);
>
> This adds the text as an overlay which can't then be made part of the
> image.
> The Draw command will do this but the text would have to be a selection
> which I can't work out how to do. Any suggestions as to how I can make the
> text permanent would be appreciated.
>
> Regards
>
> David
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Adding-text-Destructively-to-the-image-tp5015530.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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

Re: Adding text "Destructively" to the image

CARL Philippe (LBP)
In reply to this post by davek604
Dear David,
You can permanently add the selection to the picture through Edit->Draw
(Ctrl+D) or if you prefer in java: IJ.run(imp, "Draw", "slice");
My best regards,
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de
davek604
Envoyé : mercredi 3 février 2016 16:07
À : [hidden email]
Objet : Adding text "Destructively" to the image

Hello

I'm writing a plugin to add text permanently to an image. It forms part of a
loop which moves through an image stack adding numbers (as text) where
required. I'm using the code below to add the text

               String TheText = Integer.toString(count);
        Font font = new Font("SansSerif", Font.PLAIN, 9);
        TextRoi roi = new TextRoi(Xval, Yval, TheText, font);
        roi.setStrokeColor(Color.white);
        Overlay overlay = new Overlay();
        overlay.add(roi);
        Dupimp.setOverlay(overlay);

This adds the text as an overlay which can't then be made part of the image.
The Draw command will do this but the text would have to be a selection
which I can't work out how to do. Any suggestions as to how I can make the
text permanent would be appreciated.

Regards

David  



--
View this message in context:
http://imagej.1557.x6.nabble.com/Adding-text-Destructively-to-the-image-tp50
15530.html
Sent from the ImageJ mailing list archive at Nabble.com.

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

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

Re: Adding text "Destructively" to the image

davek604
In reply to this post by davek604
Hello Graeme/Philippe.

I'd tried both those options but IJ.run(imp, "Draw", "slice"); requires the text to be selected which I can't figure out how to do via a plugin.
The flatten option does work but it makes a copy of the slice out of the image so I could end up with a lot of slices to save. I might try and rebuild a stack with just the flattened extracted slices which would probably work if the user wants it that way.

Thanks both for the advice

Regards

David
Reply | Threaded
Open this post in threaded view
|

Re: Adding text "Destructively" to the image

Jan Eglinger
Hi David,

On 04.02.2016 12:18, davek604 wrote:
> I'd tried both those options but IJ.run(imp, "Draw", "slice"); requires the
> text to be selected which I can't figure out how to do via a plugin.

An overlay can be activated as a selection by Alt-clicking on it.
In Java, one way to achieve this would be:

Roi[] ovlArray = imp.getOverlay().toArray();
for (Roi roi: ovlArray) {
     imp.setRoi(roi);
     IJ.run(imp, "Draw", "slice");
}


> The flatten option does work but it makes a copy of the slice out of the
> image so I could end up with a lot of slices to save.

You can use

     imp.flattenStack();

to flatten the image stack in-place.
See the javadoc here:
http://javadoc.imagej.net/ImageJ1/index.html?ij/ImagePlus.html

Hope that helps,
Jan

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

Re: Adding text "Destructively" to the image

davek604
Hello Jan

Thanks for that, it works exactly as I wanted

Regards

David