Save and restore settings in a JS script

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

Save and restore settings in a JS script

lechristophe
Hi,

I'd like to change some IJ settings during execution (like the background
color etc.) but restore the initial settings at the end of the script. Does
someone know how to save and restore all settings in a JS script? Something
equivalent to saveSettings/restoreSettings functions in the macro language?
Or do I have to deal with them individually?

Thanks for your help,

Christophe

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

Re: Save and restore settings in a JS script

Jan Eglinger
Hi Christophe,

On 28.09.2012 10:21 AM, Christophe Leterrier wrote:
> I'd like to change some IJ settings during execution (like the background
> color etc.) but restore the initial settings at the end of the script. Does
> someone know how to save and restore all settings in a JS script? Something
> equivalent to saveSettings/restoreSettings functions in the macro language?

I'm not sure if that works, but you can try using exactly the same macro
commands via the Interpreter class:

//importClass(Packages.ij.macro.Interpreter);
var intp = new Interpreter();
intp.run("saveSettings();");
// do the processing here, changing some settings
intp.run("restoreSettings();");

Let me know if that helped,
Jan

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

bug of no negative values ......

周鑫
Dear all,

I didn't follow any official imagej tutorial before starting developing application with ImageJ.

It is always confusing for me about the way that imagej stock and get pixel in an image.

I think there are some basic concept that I did not clearly understand.

for example, when I use a simple Sobel filter, I code the following things:

static int[] sobelX = new int[]{-1,0,1,-2,0,2,-1,0,1};
 static int[] sobelY = new int[]{-1,-2,-1,0,0,0,1,2,1};

ImageProcessor iprocX = ip.duplicate();
ImageProcessor iprocY = ip.duplicate();  
iprocX.convolve3x3(Gradient2D.sobelX);
iprocY.convolve3x3(Gradient2D.sobelY);

I thought the program did what I wanted, which is doing a convolution using sobel filter with the image, and get gradient on X and Y for all the pixels

It was recently that I found a bug in this very simple program:

there is no negative values after the convolution!!!!

In matlab, I did the same thing with the same image, half of pixels became negative....

but in ImageJ, there are no negative values, no matter which method I choose to get the pixel value

 (there are two, getPixel and getPixelValue, it is already very confusing for me)

Can anybody tell me why this happens???

 

Also, when I read some dicom image that contains negative values (CT image for example), then I want to adjust the dynamic range....

I use image->adjust->Brightness/Contrast, then I found that the min value is 0.... Negative part is not show in the histogram......

I think ImageJ should be able to handle negative values, right? Do you know how to enable the negative pixel values????

Many thanks, Xin



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

Re: bug of no negative values ......

Gabriel Landini
On Friday 28 Sep 2012 13:08:33 周鑫 wrote:
> I thought the program did what I wanted, which is doing a convolution using
> sobel filter with the image, and get gradient on X and Y for all the
> pixels
 
> It was recently that I found a bug in this very simple program:
> there is no negative values after the convolution!!!!

Probably you are using the wrong container (type of image)?
If it is an 8 bit image, you have values 0-255, no negative ones.

If you convert the image to 32bit type, do you still get only positive values?

Cheers

Gabriel

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

Re: bug of no negative values ......

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by 周鑫
On Sep 28, 2012, at 8:08 AM, 周鑫 wrote:

> Dear all,
>
> I didn't follow any official imagej tutorial before starting developing application with ImageJ.
>
> It is always confusing for me about the way that imagej stock and get pixel in an image.
>
> I think there are some basic concept that I did not clearly understand.
>
> for example, when I use a simple Sobel filter, I code the following things:
>
> static int[] sobelX = new int[]{-1,0,1,-2,0,2,-1,0,1};
> static int[] sobelY = new int[]{-1,-2,-1,0,0,0,1,2,1};
>
> ImageProcessor iprocX = ip.duplicate();
> ImageProcessor iprocY = ip.duplicate();
> iprocX.convolve3x3(Gradient2D.sobelX);
> iprocY.convolve3x3(Gradient2D.sobelY);
>
> I thought the program did what I wanted, which is doing a convolution using sobel filter with the image, and get gradient on X and Y for all the pixels
>
> It was recently that I found a bug in this very simple program:
>
> there is no negative values after the convolution!!!!
Convert the image to 32-bits (float) before doing the convolution. Here is an example:

   ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif");
   ImageProcessor ip = imp.getProcessor();
   ip = ip.convertToFloat();
   int[] sobelX = new int[]{-1,0,1,-2,0,2,-1,0,1};
   int[] sobelY = new int[]{-1,-2,-1,0,0,0,1,2,1};
   ImageProcessor iprocX = ip.duplicate();
   ImageProcessor iprocY = ip.duplicate();
   iprocX.convolve3x3(sobelX);
   iprocY.convolve3x3(sobelY);
   new ImagePlus("Sobel X", iprocX).show();
   new ImagePlus("Sobel Y", iprocY).show();

[cid:[hidden email]]

-wayne

> In matlab, I did the same thing with the same image, half of pixels became negative....
>
> but in ImageJ, there are no negative values, no matter which method I choose to get the pixel value
>
> (there are two, getPixel and getPixelValue, it is already very confusing for me)
>
> Can anybody tell me why this happens???
>
>
>
> Also, when I read some dicom image that contains negative values (CT image for example), then I want to adjust the dynamic range....
>
> I use image->adjust->Brightness/Contrast, then I found that the min value is 0.... Negative part is not show in the histogram......
>
> I think ImageJ should be able to handle negative values, right? Do you know how to enable the negative pixel values????
>
> Many thanks, Xin
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

SobelFilters.jpg (119K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: bug of no negative values ......

周鑫
In reply to this post by Gabriel Landini
Hello Gabriel,

Yes, I tried with convertToFloat() function.
Then I did the same thing.

The result is the same. No negative values.

Any other ideas? Xin

> -----原始邮件-----
> 发件人: "Gabriel Landini" <[hidden email]>
> 发送时间: 2012年9月28日 星期五
> 收件人: [hidden email]
> 抄送:
> 主题: Re: bug of no negative values ......
>
> On Friday 28 Sep 2012 13:08:33 周鑫 wrote:
> > I thought the program did what I wanted, which is doing a convolution using
> > sobel filter with the image, and get gradient on X and Y for all the
> > pixels
>  
> > It was recently that I found a bug in this very simple program:
> > there is no negative values after the convolution!!!!
>
> Probably you are using the wrong container (type of image)?
> If it is an 8 bit image, you have values 0-255, no negative ones.
>
> If you convert the image to 32bit type, do you still get only positive values?
>
> Cheers
>
> Gabriel
>
> --
> 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: bug of no negative values ......

dscho
Hi Xin,

On Sat, 29 Sep 2012, 周鑫 wrote:

> Yes, I tried with convertToFloat() function.
> Then I did the same thing.
>
> The result is the same. No negative values.

It works for me. Maybe you want to show us your code, that should make it
easier to identify the issue (I *guess* that you simply called
ip.convertToFloat() but did not assign the result to the variable 'ip',
but that is just a guess, and guessing is not a terribly efficient method
to identify problems).

Hth,
Johannes

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

Re: bug of no negative values ......

周鑫
Hello Johannes,

Yes, that's the reason!!!

Today I just added ipX = ip.duplicate().convertToFloat();

and now it works.

Yesterday this problem blocks me for one day.

Thank you for your help!!!!

Xin

> -----原始邮件-----
> 发件人: "Johannes Schindelin" <[hidden email]>
> 发送时间: 2012年9月29日 星期六
> 收件人: [hidden email]
> 抄送:
> 主题: Re: bug of no negative values ......
>
> Hi Xin,
>
> On Sat, 29 Sep 2012, 周鑫 wrote:
>
> > Yes, I tried with convertToFloat() function.
> > Then I did the same thing.
> >
> > The result is the same. No negative values.
>
> It works for me. Maybe you want to show us your code, that should make it
> easier to identify the issue (I *guess* that you simply called
> ip.convertToFloat() but did not assign the result to the variable 'ip',
> but that is just a guess, and guessing is not a terribly efficient method
> to identify problems).
>
> Hth,
> Johannes
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html




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