Get name of stack or how to choose an inactive window

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

Get name of stack or how to choose an inactive window

KJ-2-3
Hi everybody

Im working with a macro which basically takes a stack and converting it into
images - no problems until now.

However my problem is when I'm trying to get the first image in the stack
(ie. not the active image).

The stack is divided into images with "name of stack"-0001 and so on.

I've figured that I most likely could use the command:

selectWindow('-0001');

But how do I get the "name of the stack" or how do I choose the first window
(the "name of the stack"-0001)

Sincerely
Kristian
Reply | Threaded
Open this post in threaded view
|

Re: Get name of stack or how to choose an inactive window

Knut Kvaal
Hello Kristian
Could this be to any help?

----fragment of a plugin

    public int setup(String arg, ImagePlus imp) {
        if (imp != null && !showDialog()) {
            return DONE;
        }
        rt.reset();
        sliceNumber = 0;
        numChan = imp.getImageStack().getSize();
        sliceName = imp.getImageStack().getSliceLabels();
        // prepare direct save of results
        tw.append("slice asm contrast correlation idm Entropy suma");
        cycleNo++;
        return DOES_8G + DOES_STACKS + SUPPORTS_MASKING;
    }

    public void run(ImageProcessor ip) {

        byte[] pixels = (byte[]) ip.getPixels();
        int width = ip.getWidth();
        Rectangle r = ip.getRoi();
        int a; // actual pixel in scope
        int b; // neighbour pixel

        // compute the glcm matrix
        double[][] glcm = new double[256][256];


        glcm = doGLCM(selectedDirection, step, ip);

        // Make a stack of GLCM images
        float[][] glcmf = new float[256][256];
        for (a = 0; a < 256; a++) {
            for (b = 0; b < 256; b++) {
                glcmf[a][b] = (float) glcm[a][b];
            }
        }
        FloatProcessor fp = new FloatProcessor(glcmf);


        ImagePlus glcmImage = new ImagePlus("glcm", fp);


        glcmStack.addSlice(selectedDirection, fp);
        sliceNumber++;
        glcmStack.setSliceLabel(sliceName[sliceNumber - 1], sliceNumber); // Different start!


        if (glcmStack.getSize() == numChan) {
            new ImagePlus("Stack" + cycleNo, glcmStack).show();
        }


Regards
Knut


On 19.03.10 12.40, "KJ" <[hidden email]> wrote:

Hi everybody

Im working with a macro which basically takes a stack and converting it into
images - no problems until now.

However my problem is when I'm trying to get the first image in the stack
(ie. not the active image).

The stack is divided into images with "name of stack"-0001 and so on.

I've figured that I most likely could use the command:

selectWindow('-0001');

But how do I get the "name of the stack" or how do I choose the first window
(the "name of the stack"-0001)

Sincerely
Kristian


_____________________________
Knut Kvaal, Associate Professor
Department of Mathematical Sciences and Technology
P.O.Box 5003
Norwegian University of Life Sciences (UMB) N - 1432 Ås NORWAY

Tel:  +47 64965394 (Norway)
Cell: +47 90920332 (Norway)

Personal Homepage: http://knut.kvaal.net <http://knut.kvaal.net/>
Reply | Threaded
Open this post in threaded view
|

Re: Get name of stack or how to choose an inactive window

KJ-2-3
Well unfortunately not, since there is no command for choosing the first
image of the stack (as far as I can see), but thanks a lot for coming with
suggestions.

Sincerely
Kristian



On Fri, Mar 19, 2010 at 12:56 PM, Knut Kvaal <[hidden email]> wrote:

> Hello Kristian
> Could this be to any help?
>
> ----fragment of a plugin
>
>    public int setup(String arg, ImagePlus imp) {
>        if (imp != null && !showDialog()) {
>            return DONE;
>        }
>        rt.reset();
>        sliceNumber = 0;
>        numChan = imp.getImageStack().getSize();
>        sliceName = imp.getImageStack().getSliceLabels();
>        // prepare direct save of results
>        tw.append("slice asm contrast correlation idm Entropy suma");
>        cycleNo++;
>        return DOES_8G + DOES_STACKS + SUPPORTS_MASKING;
>    }
>
>    public void run(ImageProcessor ip) {
>
>        byte[] pixels = (byte[]) ip.getPixels();
>        int width = ip.getWidth();
>        Rectangle r = ip.getRoi();
>        int a; // actual pixel in scope
>        int b; // neighbour pixel
>
>        // compute the glcm matrix
>        double[][] glcm = new double[256][256];
>
>
>        glcm = doGLCM(selectedDirection, step, ip);
>
>        // Make a stack of GLCM images
>        float[][] glcmf = new float[256][256];
>        for (a = 0; a < 256; a++) {
>            for (b = 0; b < 256; b++) {
>                glcmf[a][b] = (float) glcm[a][b];
>            }
>        }
>        FloatProcessor fp = new FloatProcessor(glcmf);
>
>
>        ImagePlus glcmImage = new ImagePlus("glcm", fp);
>
>
>        glcmStack.addSlice(selectedDirection, fp);
>        sliceNumber++;
>        glcmStack.setSliceLabel(sliceName[sliceNumber - 1], sliceNumber); //
> Different start!
>
>
>        if (glcmStack.getSize() == numChan) {
>            new ImagePlus("Stack" + cycleNo, glcmStack).show();
>        }
>
>
> Regards
> Knut
>
>
> On 19.03.10 12.40, "KJ" <[hidden email]> wrote:
>
> Hi everybody
>
> Im working with a macro which basically takes a stack and converting it
> into
> images - no problems until now.
>
> However my problem is when I'm trying to get the first image in the stack
> (ie. not the active image).
>
> The stack is divided into images with "name of stack"-0001 and so on.
>
> I've figured that I most likely could use the command:
>
> selectWindow('-0001');
>
> But how do I get the "name of the stack" or how do I choose the first
> window
> (the "name of the stack"-0001)
>
> Sincerely
> Kristian
>
>
> _____________________________
> Knut Kvaal, Associate Professor
> Department of Mathematical Sciences and Technology
> P.O.Box 5003
> Norwegian University of Life Sciences (UMB) N - 1432 Ås NORWAY
>
> Tel:  +47 64965394 (Norway)
> Cell: +47 90920332 (Norway)
>
> Personal Homepage: http://knut.kvaal.net <http://knut.kvaal.net/>
>



--

----------------------------
Kristian Jensen

BSc.
Molekylærbiologi og Kemi
v. Roskilde Universitetscenter

Branddamsvej 201 1tv
2860 Søborg
51899229
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Get name of stack or how to choose an inactive window

Michael Schmid
In reply to this post by KJ-2-3
Hi Kristian,

part of your question seems to be the most frequent one in this  
mailing list.
For String concatenation the operator is '+' in java and in the macro  
language as well.

  namePrefix="my first images";
  selectWindow(namePrefix + "-0001");

this will select the window named "my first images-0001" (in the  
title bar)

Howver, if you want to select a slice of a stack (i.e. multiple  
images in a single window, with a slider at the bottom), select the  
window by its name, then use the setSlice(n) macro command.

Michael
________________________________________________________________

On 19 Mar 2010, at 12:40, KJ wrote:

> Hi everybody
>
> Im working with a macro which basically takes a stack and  
> converting it into
> images - no problems until now.
>
> However my problem is when I'm trying to get the first image in the  
> stack
> (ie. not the active image).
>
> The stack is divided into images with "name of stack"-0001 and so on.
>
> I've figured that I most likely could use the command:
>
> selectWindow('-0001');
>
> But how do I get the "name of the stack" or how do I choose the  
> first window
> (the "name of the stack"-0001)
>
> Sincerely
> Kristian
Reply | Threaded
Open this post in threaded view
|

Re: Get name of stack or how to choose an inactive window

Gabriel Landini
> > But how do I get the "name of the stack" or how do I choose the
> > first window
> > (the "name of the stack"-0001)

When you just selected the image or after loading it you use
myName=getTitle();

G
Reply | Threaded
Open this post in threaded view
|

Re: Get name of stack or how to choose an inactive window

KJ-2-3
In reply to this post by Michael Schmid
Hi Michael

Thanks a lot for giving me a push in the right direction.
A slight change to your suggestion gave me the wanted:

namePrefix=File.nameWithoutExtension
selectWindow(namePrefix + '-0001');

Hence now it can be any name, instead of a "known" name, but again thanks
for the guiding.

Sincerely
Kristian

On Fri, Mar 19, 2010 at 1:49 PM, Michael Schmid <[hidden email]>wrote:

> Hi Kristian,
>
> part of your question seems to be the most frequent one in this mailing
> list.
> For String concatenation the operator is '+' in java and in the macro
> language as well.
>
>  namePrefix="my first images";
>  selectWindow(namePrefix + "-0001");
>
> this will select the window named "my first images-0001" (in the title bar)
>
> Howver, if you want to select a slice of a stack (i.e. multiple images in a
> single window, with a slider at the bottom), select the window by its name,
> then use the setSlice(n) macro command.
>
> Michael
> ________________________________________________________________
>
>
> On 19 Mar 2010, at 12:40, KJ wrote:
>
>  Hi everybody
>>
>> Im working with a macro which basically takes a stack and converting it
>> into
>> images - no problems until now.
>>
>> However my problem is when I'm trying to get the first image in the stack
>> (ie. not the active image).
>>
>> The stack is divided into images with "name of stack"-0001 and so on.
>>
>> I've figured that I most likely could use the command:
>>
>> selectWindow('-0001');
>>
>> But how do I get the "name of the stack" or how do I choose the first
>> window
>> (the "name of the stack"-0001)
>>
>> Sincerely
>> Kristian
>>
>


--

----------------------------
Kristian Jensen

BSc.
Molekylærbiologi og Kemi
v. Roskilde Universitetscenter

Branddamsvej 201 1tv
2860 Søborg
51899229
[hidden email]