ImageProcessor.setLineWidth() isn't changing the line width state

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

ImageProcessor.setLineWidth() isn't changing the line width state

Junkshops
Hi all,

I must be doing something very wrong here as this seems so simple, but
I'm at a loss to figure out what. I can't seem to set the line thickness
on an ImageProcessor:

import ij.ImagePlus;
import ij.process.ByteProcessor;

public class IJtest {
   
    static int lineWidth = 5;
   
    public static void main(String[] args) {
        //ImagePlus newCell = IJ.createImage("", "8-bit", 512, 512, 1);
        ImagePlus newCell = new ImagePlus("foo", new ByteProcessor(512,
512));
        newCell.getProcessor().setLineWidth(lineWidth);
        System.out.println("" + newCell.getProcessor().getLineWidth());
//prints 1  
    }
}


Obviously if I draw a line on the image and show() it, the line is also
width 1.

The getters and setters in the ImageProcessor code don't do anything
special other than set the line width to 1 if it's < 1, so there's no
reason the state shouldn't be saved that I can see.

Can anyone tell me what I'm doing wrong?

Thanks very much.
Reply | Threaded
Open this post in threaded view
|

Re: ImageProcessor.setLineWidth() isn't changing the line width state

Rasband, Wayne (NIH/NIMH) [E]
On Apr 3, 2011, at 2:46 AM, Junkshops wrote:

> Hi all,
>
> I must be doing something very wrong here as this seems so simple, but
> I'm at a loss to figure out what. I can't seem to set the line thickness
> on an ImageProcessor:
>
> import ij.ImagePlus;
> import ij.process.ByteProcessor;
>
> public class IJtest {
>
>    static int lineWidth = 5;
>
>    public static void main(String[] args) {
>        //ImagePlus newCell = IJ.createImage("", "8-bit", 512, 512, 1);
>        ImagePlus newCell = new ImagePlus("foo", new ByteProcessor(512,
> 512));
>        newCell.getProcessor().setLineWidth(lineWidth);
>        System.out.println("" + newCell.getProcessor().getLineWidth());
> //prints 1  
>    }
> }
>
> Obviously if I draw a line on the image and show() it, the line is also
> width 1.
>
> The getters and setters in the ImageProcessor code don't do anything
> special other than set the line width to 1 if it's < 1, so there's no
> reason the state shouldn't be saved that I can see.
>
> Can anyone tell me what I'm doing wrong?

The ImagePlus.getProcessor() method sets the line width to the current line width, which is set by using Edit>Options>Line Width or by double clicking on the line tool. You can avoid this problem by saving the ImageProcessor as a variable, for example:

   lineWidth = 5;
   imp = new ImagePlus("foo", new ByteProcessor(512, 512));
   ip = imp.getProcessor();
   ip.setLineWidth(lineWidth);
   print(ip.getLineWidth()); // prints 5

-wayne