how to update ImagePlus in Python

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

how to update ImagePlus in Python

Aryeh Weiss
I have an  ImagePlus that was created by loading a stack from a file.
I am trying to remove a single slice as follows:

# this stack has 6 slices
inputStack = impInput.getImageStack()
inputStack.deleteSlice(6)

impInput.show()

print impInput.getNChannels()
# this command now prints 5

dupStack = inputStack.duplicate()
impTest = ImagePlus("lksdfj", dupStack)
impTest.show()

The original image (impInput), appears with on slice missing (as
expected, but it is the wrong slice, and the information overthe image
is not completely correct (it shows 5 slices, but still thins it has 6
channels).

The duplicated stack (dupStack) was used to create a new imp (impText).
This image is shown correctly, with the correct slice removed.
However, it still says c:5/6 over the image..

What is the correct way to manipulate an ImageStack, and then update the
ImagePlus and ImageProcessr?

I looked in the tutorials (which are very nice), but the examples I
found had the stacks being built "fresh". My confusion is how to deal
with an existing imp. I suppose I could create a new imp each time I do
something, but that does not seem to be the right way.

Thanks in advance.
--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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

Re: how to update ImagePlus in Python

Rasband, Wayne (NIH/NIMH) [E]
On Feb 25, 2015, at 10:40 AM, Aryeh Weiss <[hidden email]> wrote:

>
> I have an  ImagePlus that was created by loading a stack from a file.
> I am trying to remove a single slice as follows:
>
> # this stack has 6 slices
> inputStack = impInput.getImageStack()
> inputStack.deleteSlice(6)
>
> impInput.show()
>
> print impInput.getNChannels()
> # this command now prints 5
>
> dupStack = inputStack.duplicate()
> impTest = ImagePlus("lksdfj", dupStack)
> impTest.show()
>
> The original image (impInput), appears with on slice missing (as expected, but it is the wrong slice, and the information overthe image is not completely correct (it shows 5 slices, but still thins it has 6 channels).
>
> The duplicated stack (dupStack) was used to create a new imp (impText). This image is shown correctly, with the correct slice removed.
> However, it still says c:5/6 over the image..
>
> What is the correct way to manipulate an ImageStack, and then update the ImagePlus and ImageProcessr?

Get the stack, delete or add slices, set the stack. Here is a JavaScript example:

  img = IJ.openImage("http://imagej.nih.gov/ij/images/t1-rendering.zip");
  img.show();
  stack = img.getStack();
  stack.deleteSlice(20);
  img.setStack(stack);

-wayne


> I looked in the tutorials (which are very nice), but the examples I found had the stacks being built "fresh". My confusion is how to deal with an existing imp. I suppose I could create a new imp each time I do something, but that does not seem to be the right way.
>
> Thanks in advance.
> --aryeh
>
> --
> Aryeh Weiss
> Faculty of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051
>
> --
> 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: how to update ImagePlus in Python

Aryeh Weiss
On 2/25/15 9:55 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Feb 25, 2015, at 10:40 AM, Aryeh Weiss <[hidden email]> wrote:
>> I have an  ImagePlus that was created by loading a stack from a file.
>> I am trying to remove a single slice as follows:
>>
>> # this stack has 6 slices
>> inputStack = impInput.getImageStack()
>> inputStack.deleteSlice(6)
>>
>> impInput.show()
>>
>> print impInput.getNChannels()
>> # this command now prints 5
>>
>> dupStack = inputStack.duplicate()
>> impTest = ImagePlus("lksdfj", dupStack)
>> impTest.show()
>>
>> The original image (impInput), appears with on slice missing (as expected, but it is the wrong slice, and the information overthe image is not completely correct (it shows 5 slices, but still thins it has 6 channels).
>>
>> The duplicated stack (dupStack) was used to create a new imp (impText). This image is shown correctly, with the correct slice removed.
>> However, it still says c:5/6 over the image..
>>
>> What is the correct way to manipulate an ImageStack, and then update the ImagePlus and ImageProcessr?
> Get the stack, delete or add slices, set the stack. Here is a JavaScript example:
>
>    img = IJ.openImage("http://imagej.nih.gov/ij/images/t1-rendering.zip");
>    img.show();
>    stack = img.getStack();
>    stack.deleteSlice(20);
>    img.setStack(stack);
>
> -wayne
>
Thank you Wayne -- works as advertised.

I still see that at the top of the image, the information shows (for
example for the first image in the stack):
1/5 (c:1/6 - Series 1); ...

Before I removed a slice it showed:
1/6 (c:1/6 - Series 1); ...

This occurs also if I use the GUI to remove a slice  -- it is not
related to the scripting.

Is this a bug, or is it expected, and there is a way to update the part
with c: 1/6?

--aryeh



>> I looked in the tutorials (which are very nice), but the examples I found had the stacks being built "fresh". My confusion is how to deal with an existing imp. I suppose I could create a new imp each time I do something, but that does not seem to be the right way.
>>
>> Thanks in advance.
>> --aryeh
>>
>> --
>> Aryeh Weiss
>> Faculty of Engineering
>> Bar Ilan University
>> Ramat Gan 52900 Israel
>>
>> Ph:  972-3-5317638
>> FAX: 972-3-7384051
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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

Re: how to update ImagePlus in Python

Rasband, Wayne (NIH/NIMH) [E]
On Feb 25, 2015, at 10:46 PM, Aryeh Weiss <[hidden email]> wrote:

>
> On 2/25/15 9:55 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:
>> Get the stack, delete or add slices, set the stack. Here is a JavaScript example:
>>
>>   img = IJ.openImage("http://imagej.nih.gov/ij/images/t1-rendering.zip");
>>   img.show();
>>   stack = img.getStack();
>>   stack.deleteSlice(20);
>>   img.setStack(stack);
>>
>> -wayne
>>
> Thank you Wayne -- works as advertised.
>
> I still see that at the top of the image, the information shows (for example for the first image in the stack):
> 1/5 (c:1/6 - Series 1); ...
>
> Before I removed a slice it showed:
> 1/6 (c:1/6 - Series 1); ...
>
> This occurs also if I use the GUI to remove a slice  -- it is not related to the scripting.
>
> Is this a bug, or is it expected, and there is a way to update the part with c: 1/6?

This is expected. The text in the stack subtitle between “(“ and “)” is the slice label, which does not change when you delete or add slices. You can retrieve the slice label of the nth slice using the ImageStack.getSliceLabel(n) method and set it using ImageStack.setSliceLabel("text",n). It a macro, use getMetadata(“Label") and setMetadata(“Label","text”).

-wayne


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

can the summary table become a results table?

Aryeh Weiss
Wayne -- thank you for your explanation of the slice labels.

I have a question about the Summary table generated by the analyzer.

I would like to add a column to it, the way one might do with the
results table.

I came up with the following:
      IJ.renameResults("Summary", "Results")

     rtSummary = ResultsTable.getResultsTable()

     rtSummary.setValue("Slice", rtSummary.getCounter()-2,
channelLabels[channel-1]+"_bg")
     rtSummary.setValue("WeightedMean", rtSummary.getCounter()-2,
bgMeanWeighted)
     rtSummary.setValue("Slice", rtSummary.getCounter()-1,
channelLabels[channel-1]+"_cells")
     rtSummary.setValue("StdDev", rtSummary.getCounter()-1, stdDev)
     IJ.renameResults("Results", "Summary")

So I rename the summary table, and then I use getResultsTable() to
assign it to rtSummary.
This works -- each call to the analyzer adds to the Summary table, and
then I add my items as above.

It would be nice to  be able to hand the Summary table to a results
table constructor, like:
rtSummary = ResultsTable("Summary")

Is there a better way to do this? (Or more correctly -- what is the best
way to do this?)

--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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

Re: can the summary table become a results table?

Rasband, Wayne (NIH/NIMH) [E]
On Feb 26, 2015, at 2:30 PM, Aryeh Weiss <[hidden email]> wrote:
>
> Wayne -- thank you for your explanation of the slice labels.
>
> I have a question about the Summary table generated by the analyzer.
>
> I would like to add a column to it, the way one might do with the results table.

The summary tables created by the particle analyzer are results tables. Here is a JavaScript example that creates a Summary table and adds two columns to it:

  img = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
  title = img.getTitle();
  IJ.setAutoThreshold(img, "Huang dark");
  IJ.run(img, "Analyze Particles...", "size=1000 summarize stack");
  frame = WindowManager.getFrame("Summary of "+title);
  rt = frame.getTextPanel().getResultsTable();
  for (i=0; i<rt.size(); i++) {
     rt.setValue("Extra1", i, i*100);
     rt.setValue("Extra2", i, "Row "+(i+1));
  }
  rt.show("Summary of "+title);

-wayne


> I came up with the following:
>     IJ.renameResults("Summary", "Results")
>
>    rtSummary = ResultsTable.getResultsTable()
>
>    rtSummary.setValue("Slice", rtSummary.getCounter()-2, channelLabels[channel-1]+"_bg")
>    rtSummary.setValue("WeightedMean", rtSummary.getCounter()-2, bgMeanWeighted)
>    rtSummary.setValue("Slice", rtSummary.getCounter()-1, channelLabels[channel-1]+"_cells")
>    rtSummary.setValue("StdDev", rtSummary.getCounter()-1, stdDev)
>    IJ.renameResults("Results", "Summary")
>
> So I rename the summary table, and then I use getResultsTable() to assign it to rtSummary.
> This works -- each call to the analyzer adds to the Summary table, and then I add my items as above.
>
> It would be nice to  be able to hand the Summary table to a results table constructor, like:
> rtSummary = ResultsTable("Summary")
>
> Is there a better way to do this? (Or more correctly -- what is the best way to do this?)
>
> —aryeh



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

Re: can the summary table become a results table?

Aryeh Weiss
On 2/27/15 5:20 AM, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Feb 26, 2015, at 2:30 PM, Aryeh Weiss <[hidden email]> wrote:
>> Wayne -- thank you for your explanation of the slice labels.
>>
>> I have a question about the Summary table generated by the analyzer.
>>
>> I would like to add a column to it, the way one might do with the results table.
> The summary tables created by the particle analyzer are results tables. Here is a JavaScript example that creates a Summary table and adds two columns to it:
>
>    img = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
>    title = img.getTitle();
>    IJ.setAutoThreshold(img, "Huang dark");
>    IJ.run(img, "Analyze Particles...", "size=1000 summarize stack");
>    frame = WindowManager.getFrame("Summary of "+title);
>    rt = frame.getTextPanel().getResultsTable();
>    for (i=0; i<rt.size(); i++) {
>       rt.setValue("Extra1", i, i*100);
>       rt.setValue("Extra2", i, "Row "+(i+1));
>    }
>    rt.show("Summary of "+title);
>
> -wayne
>
Thank you -- this is just what I wanted..
However, in my my python script, the Summary window has the title
"Summary",, while in your js script
the Summary Window has the title "Summary of "+title.
Why is that?

One other question. Is there a way to find all of the classes in which a
given method is implemented. For example, Can I search the API to find
all of the classes for which getResultsTable() is implemented?

--aryeh

>> I came up with the following:
>>      IJ.renameResults("Summary", "Results")
>>
>>     rtSummary = ResultsTable.getResultsTable()
>>
>>     rtSummary.setValue("Slice", rtSummary.getCounter()-2, channelLabels[channel-1]+"_bg")
>>     rtSummary.setValue("WeightedMean", rtSummary.getCounter()-2, bgMeanWeighted)
>>     rtSummary.setValue("Slice", rtSummary.getCounter()-1, channelLabels[channel-1]+"_cells")
>>     rtSummary.setValue("StdDev", rtSummary.getCounter()-1, stdDev)
>>     IJ.renameResults("Results", "Summary")
>>
>> So I rename the summary table, and then I use getResultsTable() to assign it to rtSummary.
>> This works -- each call to the analyzer adds to the Summary table, and then I add my items as above.
>>
>> It would be nice to  be able to hand the Summary table to a results table constructor, like:
>> rtSummary = ResultsTable("Summary")
>>
>> Is there a better way to do this? (Or more correctly -- what is the best way to do this?)
>>
>> —aryeh
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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

Re: can the summary table become a results table?

Michael Schmid
Hi Aryeh,

> However, in my my python script, the Summary window has the title "Summary",, while in your js script
> the Summary Window has the title "Summary of "+title.
> Why is that?
Maybe the title of your ImagePlus is the empty String ""?

> One other question. Is there a way to find all of the classes in which a given method is implemented. For example, Can I search the API to find all of the classes for which getResultsTable() is implemented?
Probably the easiest way is searching for the String in the sources.
Quick&dirty: Google search for
 site:rsb.info.nih.gov/ij/developer/source getResultsTable
Better:
Download the sources and search the directory on your computer, e.g. using
 grep -R sources/ij getResultsTable
in the Linux/MacOS command line.

Michael
________________________________________________________________
On Feb 27, 2015, at 12:35, Aryeh Weiss wrote:

> On 2/27/15 5:20 AM, Rasband, Wayne (NIH/NIMH) [E] wrote:
>> On Feb 26, 2015, at 2:30 PM, Aryeh Weiss <[hidden email]> wrote:
>>> Wayne -- thank you for your explanation of the slice labels.
>>>
>>> I have a question about the Summary table generated by the analyzer.
>>>
>>> I would like to add a column to it, the way one might do with the results table.
>> The summary tables created by the particle analyzer are results tables. Here is a JavaScript example that creates a Summary table and adds two columns to it:
>>
>>  img = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
>>  title = img.getTitle();
>>  IJ.setAutoThreshold(img, "Huang dark");
>>  IJ.run(img, "Analyze Particles...", "size=1000 summarize stack");
>>  frame = WindowManager.getFrame("Summary of "+title);
>>  rt = frame.getTextPanel().getResultsTable();
>>  for (i=0; i<rt.size(); i++) {
>>     rt.setValue("Extra1", i, i*100);
>>     rt.setValue("Extra2", i, "Row "+(i+1));
>>  }
>>  rt.show("Summary of "+title);
>>
>> -wayne
>>
> Thank you -- this is just what I wanted..
> However, in my my python script, the Summary window has the title "Summary",, while in your js script
> the Summary Window has the title "Summary of "+title.
> Why is that?
>
> One other question. Is there a way to find all of the classes in which a given method is implemented. For example, Can I search the API to find all of the classes for which getResultsTable() is implemented?
>
> --aryeh
>>> I came up with the following:
>>>    IJ.renameResults("Summary", "Results")
>>>
>>>   rtSummary = ResultsTable.getResultsTable()
>>>
>>>   rtSummary.setValue("Slice", rtSummary.getCounter()-2, channelLabels[channel-1]+"_bg")
>>>   rtSummary.setValue("WeightedMean", rtSummary.getCounter()-2, bgMeanWeighted)
>>>   rtSummary.setValue("Slice", rtSummary.getCounter()-1, channelLabels[channel-1]+"_cells")
>>>   rtSummary.setValue("StdDev", rtSummary.getCounter()-1, stdDev)
>>>   IJ.renameResults("Results", "Summary")
>>>
>>> So I rename the summary table, and then I use getResultsTable() to assign it to rtSummary.
>>> This works -- each call to the analyzer adds to the Summary table, and then I add my items as above.
>>>
>>> It would be nice to  be able to hand the Summary table to a results table constructor, like:
>>> rtSummary = ResultsTable("Summary")
>>>
>>> Is there a better way to do this? (Or more correctly -- what is the best way to do this?)
>>>
>>> —aryeh
>>
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
>
> --
> Aryeh Weiss
> Faculty of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051
>
> --
> 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: can the summary table become a results table?

Aryeh Weiss
Hi Michael

On 2/27/15 4:52 PM, Michael Schmid wrote:
> Hi Aryeh,
>
>> However, in my my python script, the Summary window has the title "Summary",, while in your js script
>> the Summary Window has the title "Summary of "+title.
>> Why is that?
> Maybe the title of your ImagePlus is the empty String ""?
>
Wayne sent me a reply off-list that explains it. He wrote:

/With stacks, the particle analyzer names the window "Summary of “+title. //
//With single images, it names it “Summary”. I would make it consistent
but that would break existing macros and plugins. /

In my case it is a single image, so the Summary window is called "Summary".

Best regards
--aryeh


>> One other question. Is there a way to find all of the classes in which a given method is implemented. For example, Can I search the API to find all of the classes for which getResultsTable() is implemented?
> Probably the easiest way is searching for the String in the sources.
> Quick&dirty: Google search for
>   site:rsb.info.nih.gov/ij/developer/source getResultsTable
> Better:
> Download the sources and search the directory on your computer, e.g. using
>   grep -R sources/ij getResultsTable
> in the Linux/MacOS command line.
>
> Michael
> ________________________________________________________________
> On Feb 27, 2015, at 12:35, Aryeh Weiss wrote:
>
>> On 2/27/15 5:20 AM, Rasband, Wayne (NIH/NIMH) [E] wrote:
>>> On Feb 26, 2015, at 2:30 PM, Aryeh Weiss <[hidden email]> wrote:
>>>> Wayne -- thank you for your explanation of the slice labels.
>>>>
>>>> I have a question about the Summary table generated by the analyzer.
>>>>
>>>> I would like to add a column to it, the way one might do with the results table.
>>> The summary tables created by the particle analyzer are results tables. Here is a JavaScript example that creates a Summary table and adds two columns to it:
>>>
>>>   img = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
>>>   title = img.getTitle();
>>>   IJ.setAutoThreshold(img, "Huang dark");
>>>   IJ.run(img, "Analyze Particles...", "size=1000 summarize stack");
>>>   frame = WindowManager.getFrame("Summary of "+title);
>>>   rt = frame.getTextPanel().getResultsTable();
>>>   for (i=0; i<rt.size(); i++) {
>>>      rt.setValue("Extra1", i, i*100);
>>>      rt.setValue("Extra2", i, "Row "+(i+1));
>>>   }
>>>   rt.show("Summary of "+title);
>>>
>>> -wayne
>>>
>> Thank you -- this is just what I wanted..
>> However, in my my python script, the Summary window has the title "Summary",, while in your js script
>> the Summary Window has the title "Summary of "+title.
>> Why is that?
>>
>> One other question. Is there a way to find all of the classes in which a given method is implemented. For example, Can I search the API to find all of the classes for which getResultsTable() is implemented?
>>
>> --aryeh
>>>> I came up with the following:
>>>>     IJ.renameResults("Summary", "Results")
>>>>
>>>>    rtSummary = ResultsTable.getResultsTable()
>>>>
>>>>    rtSummary.setValue("Slice", rtSummary.getCounter()-2, channelLabels[channel-1]+"_bg")
>>>>    rtSummary.setValue("WeightedMean", rtSummary.getCounter()-2, bgMeanWeighted)
>>>>    rtSummary.setValue("Slice", rtSummary.getCounter()-1, channelLabels[channel-1]+"_cells")
>>>>    rtSummary.setValue("StdDev", rtSummary.getCounter()-1, stdDev)
>>>>    IJ.renameResults("Results", "Summary")
>>>>
>>>> So I rename the summary table, and then I use getResultsTable() to assign it to rtSummary.
>>>> This works -- each call to the analyzer adds to the Summary table, and then I add my items as above.
>>>>
>>>> It would be nice to  be able to hand the Summary table to a results table constructor, like:
>>>> rtSummary = ResultsTable("Summary")
>>>>
>>>> Is there a better way to do this? (Or more correctly -- what is the best way to do this?)
>>>>
>>>> —aryeh
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> --
>> Aryeh Weiss
>> Faculty of Engineering
>> Bar Ilan University
>> Ramat Gan 52900 Israel
>>
>> Ph:  972-3-5317638
>> FAX: 972-3-7384051
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


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