How do you select an image from set of slices to change pixel intensity

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

How do you select an image from set of slices to change pixel intensity

mtamimi
Hello I wrote the following macro to make a 10 slices. I need to add a white box in certain location in all the images. I used the macro command setSlice, then setpixel to select slice then change the pixel intensity to 256. his seems to work for slice 1 only. I am not sure why. Is their a different commad o do this? The code: // This macro generate 10 image. width = 500; height = 500; xc = width/2; yc = height/2; newImage("Math", "16-bit black", width, height, 10); //setVoxelSize(width, height, depth, unit) for(z=1; z
Reply | Threaded
Open this post in threaded view
|

Re: How do you select an image from set of slices to change pixel intensity

lechristophe
You should use nSlices() instead of nImages() to return the number of slices
in your stack. nImages() gives you the number of images (i.e. one in your
example, the stack).

Christophe

On Wed, Oct 19, 2011 at 21:56, mtamimi <[hidden email]> wrote:

> Hello
> I wrote the following macro to make a 10 slices. I need to add  a white box
> in certain location in all the images. I used the macro command setSlice,
> then  setpixel to select slice then change the pixel intensity to 256.
> his seems to work for slice 1 only. I am not sure why. Is their a different
> commad o do this?
>
> The code:
>
> // This macro generate 10 image.
>
>  width = 500; height = 500;
>  xc = width/2; yc = height/2;
>  newImage("Math", "16-bit black", width, height, 10);
> //setVoxelSize(width, height, depth, unit)
>    for(z=1; z<nImages+1;z++){
>
>                for (y= 100; y<250; y++) {
>                  for (x= 100; x<250; x++) {
>                                setSlice(z);
>                                setPixel(x, y,256);
>                  }
>          }
>  resetMinAndMax();
> exit;
>
> Thank you in advance for all your input.
> Sincerely,
> Mat M. Al-Tamimi
>
> --
> View this message in context:
> http://imagej.588099.n2.nabble.com/How-do-you-select-an-image-from-set-of-slices-to-change-pixel-intensity-tp6910289p6910289.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: How do you select an image from set of slices to change pixel intensity

Jerome Mutterer-3
In reply to this post by mtamimi
Hi,
There are several small mistakes in your code.
1. you should use nSlices instead of nImages.
2. you forgot the close curly braces for the z loop.
3. you'd rather setSlice(z) outside the x and y loops.
4. white is 255.

So it would look like this.
for(z=1; z<=nSlices;z++){
 setSlice(z);
 for (y= 100; y<250; y++) {
  for (x= 100; x<250; x++) {
   setPixel(x, y,255);
  }
 }
} // this was missing

You could also replace this code by this faster version:

makeRectangle(100, 100, 149, 149);
setForegroundColor(255,255,255);
run("Fill","stack");

Sincerely,
Jerome.



On Wed, Oct 19, 2011 at 9:56 PM, mtamimi <[hidden email]> wrote:

> Hello
> I wrote the following macro to make a 10 slices. I need to add  a white box
> in certain location in all the images. I used the macro command setSlice,
> then  setpixel to select slice then change the pixel intensity to 256.
> his seems to work for slice 1 only. I am not sure why. Is their a different
> commad o do this?
>
> The code:
>
> // This macro generate 10 image.
>
>  width = 500; height = 500;
>  xc = width/2; yc = height/2;
>  newImage("Math", "16-bit black", width, height, 10);
> //setVoxelSize(width, height, depth, unit)
>    for(z=1; z<nImages+1;z++){
>
>                for (y= 100; y<250; y++) {
>                  for (x= 100; x<250; x++) {
>                                setSlice(z);
>                                setPixel(x, y,256);
>                  }
>          }
>  resetMinAndMax();
> exit;
>
> Thank you in advance for all your input.
> Sincerely,
> Mat M. Al-Tamimi
>
> --
> View this message in context:
> http://imagej.588099.n2.nabble.com/How-do-you-select-an-image-from-set-of-slices-to-change-pixel-intensity-tp6910289p6910289.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: How do you select an image from set of slices to change pixel intensity

Glen MacDonald-2
In reply to this post by mtamimi
Dear Mat,
first, the nImages returned the number of open images.  If you 3 open images your macro would create 4 ROIs.  the correct function was nSlices.
Second, the Exit was redundant, since the macro will exit on completion.  I replaced it with a closing '}" for the initial for statement.

Another option is to create the initial ROI and add it to the ROI Manager
// This macro generate 10 image.

   width = 500; height = 500;
   xc = width/2; yc = height/2;
   newImage("Math", "16-bit black", width, height, 10);
//setVoxelSize(width, height, depth, unit)
  //for(z=1; z<nImages+1;z++){
     for(z=1; z<nSlices+1;z++){

for (y= 100; y<250; y++) {
   for (x= 100; x<250; x++) {
setSlice(z);
setPixel(x, y,256);
   }
   }
   resetMinAndMax();
//exit;
     }
Regards,
Glen

Glen MacDonald
Core for Communication Research
Virginia Merrill Bloedel Hearing Research Center
Box 357923
University of Washington
Seattle, WA 98195-7923
(206) 616-4156

On Wed, 19 Oct 2011, mtamimi wrote:

> Hello
> I wrote the following macro to make a 10 slices. I need to add  a white box
> in certain location in all the images. I used the macro command setSlice,
> then  setpixel to select slice then change the pixel intensity to 256.
> his seems to work for slice 1 only. I am not sure why. Is their a different
> commad o do this?
>
> The code:
>
> // This macro generate 10 image.
>
>  width = 500; height = 500;
>  xc = width/2; yc = height/2;
>  newImage("Math", "16-bit black", width, height, 10);
> //setVoxelSize(width, height, depth, unit)
>    for(z=1; z<nImages+1;z++){
>
> for (y= 100; y<250; y++) {
>  for (x= 100; x<250; x++) {
> setSlice(z);
> setPixel(x, y,256);
>  }
>  }
>  resetMinAndMax();
> exit;
>
> Thank you in advance for all your input.
> Sincerely,
> Mat M. Al-Tamimi
>
> --
> View this message in context: http://imagej.588099.n2.nabble.com/How-do-you-select-an-image-from-set-of-slices-to-change-pixel-intensity-tp6910289p6910289.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

RE: How do you select an image from set of slices to change pixel intensity

mtamimi

Hello
Thank you very much. It worked.
Question: The Montage example uses  id=getImageID and then selectImage(id).

When I use this it does not work Do you know why?

 

The code:

=========

// This macro generate 10 image.

 

  width = 500; height = 500;

  xc = width/2; yc = height/2;

  newImage("Math", "16-bit black", width, height, 10);

  //id=getImageID;

//setVoxelSize(width, height, depth, unit)

    for(z=1; z<nSlices+1;z++){

                   for (y= 100; y<250; y++) {

                             for (x= 100; x<250; x++) {

                                      //selectImage(id);

                                      setSlice(z);

                                      setPixel(x, y,256);

                             }

                   }

                   resetMinAndMax();

          }

 

 


From: Glen MacDonald-2 [via ImageJ] [mailto:[hidden email]]
Sent: Wednesday, October 19, 2011 4:47 PM
To: mtamimi
Subject: Re: How do you select an image from set of slices to change pixel intensity

 

Dear Mat,
first, the nImages returned the number of open images.  If you 3 open images your macro would create 4 ROIs.  the correct function was nSlices.
Second, the Exit was redundant, since the macro will exit on completion.  I replaced it with a closing '}" for the initial for statement.

Another option is to create the initial ROI and add it to the ROI Manager
// This macro generate 10 image.

   width = 500; height = 500;
   xc = width/2; yc = height/2;
   newImage("Math", "16-bit black", width, height, 10);
//setVoxelSize(width, height, depth, unit)
  //for(z=1; z<nImages+1;z++){
     for(z=1; z<nSlices+1;z++){

for (y= 100; y<250; y++) {
   for (x= 100; x<250; x++) {
setSlice(z);
setPixel(x, y,256);
   }
   }
   resetMinAndMax();
//exit;
     }
Regards,
Glen

Glen MacDonald
Core for Communication Research
Virginia Merrill Bloedel Hearing Research Center
Box 357923
University of Washington
Seattle, WA 98195-7923
(206) 616-4156

On Wed, 19 Oct 2011, mtamimi wrote:


> Hello
> I wrote the following macro to make a 10 slices. I need to add  a white box
> in certain location in all the images. I used the macro command setSlice,
> then  setpixel to select slice then change the pixel intensity to 256.
> his seems to work for slice 1 only. I am not sure why. Is their a different
> commad o do this?
>
> The code:
>
> // This macro generate 10 image.
>
>  width = 500; height = 500;
>  xc = width/2; yc = height/2;
>  newImage("Math", "16-bit black", width, height, 10);
> //setVoxelSize(width, height, depth, unit)
>    for(z=1; z<nImages+1;z++){
>
> for (y= 100; y<250; y++) {
>  for (x= 100; x<250; x++) {
> setSlice(z);
> setPixel(x, y,256);
>  }
>  }
>  resetMinAndMax();
> exit;
>
> Thank you in advance for all your input.
> Sincerely,
> Mat M. Al-Tamimi
>
> --
> View this message in context: http://imagej.588099.n2.nabble.com/How-do-you-select-an-image-from-set-of-slices-to-change-pixel-intensity-tp6910289p6910289.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>

 


To unsubscribe from How do you select an image from set of slices to change pixel intensity, click here.

Reply | Threaded
Open this post in threaded view
|

RE: How do you select an image from set of slices to change pixel intensity

mtamimi
In reply to this post by lechristophe

Thank you. It worked.

 


From: lechristophe [via ImageJ] [mailto:[hidden email]]
Sent: Wednesday, October 19, 2011 4:47 PM
To: mtamimi
Subject: Re: How do you select an image from set of slices to change pixel intensity

 

You should use nSlices() instead of nImages() to return the number of slices
in your stack. nImages() gives you the number of images (i.e. one in your
example, the stack).

Christophe

On Wed, Oct 19, 2011 at 21:56, mtamimi <[hidden email]> wrote:


> Hello
> I wrote the following macro to make a 10 slices. I need to add  a white box
> in certain location in all the images. I used the macro command setSlice,
> then  setpixel to select slice then change the pixel intensity to 256.
> his seems to work for slice 1 only. I am not sure why. Is their a different
> commad o do this?
>
> The code:
>
> // This macro generate 10 image.
>
>  width = 500; height = 500;
>  xc = width/2; yc = height/2;
>  newImage("Math", "16-bit black", width, height, 10);
> //setVoxelSize(width, height, depth, unit)
>    for(z=1; z<nImages+1;z++){
>
>                for (y= 100; y<250; y++) {
>                  for (x= 100; x<250; x++) {
>                                setSlice(z);
>                                setPixel(x, y,256);
>                  }
>          }
>  resetMinAndMax();
> exit;
>
> Thank you in advance for all your input.
> Sincerely,
> Mat M. Al-Tamimi
>
> --
> View this message in context:
> http://imagej.588099.n2.nabble.com/How-do-you-select-an-image-from-set-of-slices-to-change-pixel-intensity-tp6910289p6910289.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>

 


To unsubscribe from How do you select an image from set of slices to change pixel intensity, click here.

Reply | Threaded
Open this post in threaded view
|

RE: How do you select an image from set of slices to change pixel intensity

mtamimi
In reply to this post by Jerome Mutterer-3

Hello
Thank you very much. That solved the problem.

 

Mat

 


From: Jerome Mutterer-3 [via ImageJ] [mailto:[hidden email]]
Sent: Wednesday, October 19, 2011 4:37 PM
To: mtamimi
Subject: Re: How do you select an image from set of slices to change pixel intensity

 

Hi,
There are several small mistakes in your code.
1. you should use nSlices instead of nImages.
2. you forgot the close curly braces for the z loop.
3. you'd rather setSlice(z) outside the x and y loops.
4. white is 255.

So it would look like this.
for(z=1; z<=nSlices;z++){
 setSlice(z);
 for (y= 100; y<250; y++) {
  for (x= 100; x<250; x++) {
   setPixel(x, y,255);
  }
 }
} // this was missing

You could also replace this code by this faster version:

makeRectangle(100, 100, 149, 149);
setForegroundColor(255,255,255);
run("Fill","stack");

Sincerely,
Jerome.



On Wed, Oct 19, 2011 at 9:56 PM, mtamimi <[hidden email]> wrote:


> Hello
> I wrote the following macro to make a 10 slices. I need to add  a white box
> in certain location in all the images. I used the macro command setSlice,
> then  setpixel to select slice then change the pixel intensity to 256.
> his seems to work for slice 1 only. I am not sure why. Is their a different
> commad o do this?
>
> The code:
>
> // This macro generate 10 image.
>
>  width = 500; height = 500;
>  xc = width/2; yc = height/2;
>  newImage("Math", "16-bit black", width, height, 10);
> //setVoxelSize(width, height, depth, unit)
>    for(z=1; z<nImages+1;z++){
>
>                for (y= 100; y<250; y++) {
>                  for (x= 100; x<250; x++) {
>                                setSlice(z);
>                                setPixel(x, y,256);
>                  }
>          }
>  resetMinAndMax();
> exit;
>
> Thank you in advance for all your input.
> Sincerely,
> Mat M. Al-Tamimi
>
> --
> View this message in context:
> http://imagej.588099.n2.nabble.com/How-do-you-select-an-image-from-set-of-slices-to-change-pixel-intensity-tp6910289p6910289.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>

 


To unsubscribe from How do you select an image from set of slices to change pixel intensity, click here.