random regions of interest

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

random regions of interest

Ray Gilbert
Is there any way in Image J to sample random regions of interest of
fixed size within a defined area in a larger image?

 

 

 

Failing that is it possible to set the grid up within a specified area
rather than over the entire image?

 

 

 

Thanks

 

--

Ray Gilbert

Senior Research Assistant

Lactation Gene Expression Project

Molecular and Chemical Neuroanatomy Group

Dept of Anatomy with Radiology

Faculty of Medical and Health Sciences

University of Auckland

Private Bag 92019

Auckland

New Zealand

Ph 0064 9 3737 599 ext 86022

fax 0064 9 3737484

[hidden email] <mailto:[hidden email]>  

 
Reply | Threaded
Open this post in threaded view
|

Re: random regions of interest

dksamuel
can a mask be loaded into imageJ like we do in Photoshop

On 10/13/05, Ray Gilbert <[hidden email]> wrote:

>
> Is there any way in Image J to sample random regions of interest of
> fixed size within a defined area in a larger image?
>
>
>
>
>
>
>
> Failing that is it possible to set the grid up within a specified area
> rather than over the entire image?
>
>
>
>
>
>
>
> Thanks
>
>
>
> --
>
> Ray Gilbert
>
> Senior Research Assistant
>
> Lactation Gene Expression Project
>
> Molecular and Chemical Neuroanatomy Group
>
> Dept of Anatomy with Radiology
>
> Faculty of Medical and Health Sciences
>
> University of Auckland
>
> Private Bag 92019
>
> Auckland
>
> New Zealand
>
> Ph 0064 9 3737 599 ext 86022
>
> fax 0064 9 3737484
>
> [hidden email] <mailto:[hidden email]>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: random regions of interest

Bo de Lange
In reply to this post by Ray Gilbert
Ray Gilbert wrote:

I wanted to do exactly that some time ago and adapted this macro
http://rsb.info.nih.gov/ij/macros/RandomSampleAndMeasure.txt.

// RandomSampleAndMeasureWithinSelection-1step.txt
// Randomly places predefined Regions of Interest completely within
// the boundaries of a larger Region of Interest, measures and labels them
// G. Landini at bham. ac. uk and Bo de Lange
// Start with opening the image, and drawing the large ROI (MUST be
smaller than total image).

macro "RandomSampleAndMeasureWithinROI [F1]" {
  run("Select None");    

  saveSettings();
  original=getTitle();
  setForegroundColor(255,0,0);

  width = getWidth()-30;   // width of the randomly placed ROI
  height = getHeight()-30; // height of the randomly placed ROI
  RoisN =50; // number of ROIs
  trials=100 ; //maximum trials to avoid infinite loop

  i=0;
  j=0;

  xa=newArray(RoisN);
  ya=newArray(RoisN);

  run("Duplicate...", "title=Reference");




  selectWindow("Reference");
  run("8-bit"); //makes it greyscale
  run("RGB Color"); //RGB to display colours
  run("Restore Selection");
  run("Make Inverse");
  run("Fill");
  run("Select None");
 



   while (i<RoisN && j<trials){
        w = 30;
        h = 30;
        x = random()*width;
        y = random()*height;
        j++;
        //Check for pixels with value (255,0,0):
        flag= -1;
        makeRectangle(x, y, w, h);
        //Scanning the rectangle perimeter should be faster than
scanning the whole box.
        //This is slower, as checks all the points in the box:
        for (xs=x;xs<x+w;xs++){
            for (ys=y;ys<y+h;ys++){
                if (getPixel(xs,ys)==-65536) // pixel is (255,0,0)
                    flag=0;
            }
        }
        if (flag==-1){
            xa[i]=x;
            ya[i]=y;
            run("Fill");
            i++;
        }
   }
     

  close();
  selectWindow(original);
  setForegroundColor(255,255,0);
  for (j=0;j<i;j++){
    makeRectangle(xa[j], ya[j], w, h);
      run("Measure");
      run("Label");
  }
 restoreSettings();      
 run("Select None");
 run("Jpeg...", "save");
 run("Close");

}

>Is there any way in Image J to sample random regions of interest of
>fixed size within a defined area in a larger image?
>
>
>
>
>
>
>
>Failing that is it possible to set the grid up within a specified area
>rather than over the entire image?
>
>
>
>
>
>
>
>Thanks
>
>
>
>--
>
>Ray Gilbert
>
>Senior Research Assistant
>
>Lactation Gene Expression Project
>
>Molecular and Chemical Neuroanatomy Group
>
>Dept of Anatomy with Radiology
>
>Faculty of Medical and Health Sciences
>
>University of Auckland
>
>Private Bag 92019
>
>Auckland
>
>New Zealand
>
>Ph 0064 9 3737 599 ext 86022
>
>fax 0064 9 3737484
>
>[hidden email] <mailto:[hidden email]>  
>
>
>  
>


--
R.P.J. de Lange, PhD
Rudolf Magnus Institute of Neurosciences
P.O. box 80040
3508 TA Utrecht
The Netherlands

visiting address:
Stratenum, room 4.241
Universiteitsweg 100
3584 CG Utrecht

tel: +31-30-253 8924
        +31-30-253 8837 (lab)
fax: +31-30-253 9032
Reply | Threaded
Open this post in threaded view
|

Re: random regions of interest

Wayne Rasband
In reply to this post by dksamuel
> can a mask be loaded into imageJ like we do in Photoshop

In ImageJ, masks are 8-bit binary images consisting of zero and 255.
Masks are created by Edit>Selection>Create Mask and by Analyze>Analyze
Particles when "Masks" is selected from the  "Show:" drop down menu.
Masks created by these two commands use inverting lookup table so that
zero pixels are white and 255 pixels are black. Use the Edit>Paste
Control tool or the Process>Image Calculator to apply masks to images.
The Paste Controller is particularly useful since it allows you to
interactively try different operators like AND, OR, XOR and Multiply.

The Hypermedia Image processing Reference has a masking tutorial at

       http://homepages.inf.ed.ac.uk/rbf/HIPR2/mask.htm#1

-wayne