Averaging over a ring in ImageJ

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

Averaging over a ring in ImageJ

verified.human
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Averaging over a ring in ImageJ

Frederic V. Hessman
The aperture photometry plugins of the astronomy packages do this kind of thing (for determining the background).  Try http://www.astro.physik.uni-goettingen.de/~hessman/ImageJ/Astronomy/   The correlation part you'd have to do by hand.....

Rick

On 7 May 2012, at 17:58, Tom Runia wrote:

> Hi all,
>
> I am working on an algorithm for which I need to compute the correlation
> coefficient between rings of two different images. The following image
> makes this somewhat more clear:
> http://tweakers.net/ext/f/ZnXN3zSic04FIlLYVi3lfLXX/full.png
> In order to calculate the correlation coefficient I need to obtain the
> average pixel value over both rings. Since writing all the code to achieve
> this myself is a lot of work, I was wondering whether anybody knows a
> plug-in that can do this?
>
> So, my question is: "Does there exist an ImageJ plug-in that can calculate
> the average pixel value over a ring?"
> Any help would be appreciated, Thanks!!
>
> Best,
>
> Tom
Reply | Threaded
Open this post in threaded view
|

Re: Averaging over a ring in ImageJ

Michael Elbaum
In reply to this post by verified.human
Radial Profile should work. You can search the plugins page for "radial" and see if some of the others would be better suited.
Michael

________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of Tom Runia [[hidden email]]
Sent: Monday, May 07, 2012 6:58 PM
To: [hidden email]
Subject: Averaging over a ring in ImageJ

Hi all,

I am working on an algorithm for which I need to compute the correlation
coefficient between rings of two different images. The following image
makes this somewhat more clear:
http://tweakers.net/ext/f/ZnXN3zSic04FIlLYVi3lfLXX/full.png
In order to calculate the correlation coefficient I need to obtain the
average pixel value over both rings. Since writing all the code to achieve
this myself is a lot of work, I was wondering whether anybody knows a
plug-in that can do this?

So, my question is: "Does there exist an ImageJ plug-in that can calculate
the average pixel value over a ring?"
Any help would be appreciated, Thanks!!

Best,

Tom
Reply | Threaded
Open this post in threaded view
|

Re: Averaging over a ring in ImageJ

Cammer, Michael
In reply to this post by verified.human
It's not elegant, but I think this will do what you want on a band ROI.  
-Michael

________________________________________________________
Michael Cammer, Assistant Research Scientist
Skirball Institute of Biomolecular Medicine
Lab: (212) 263-3208  Cell: (914) 309-3270


//**************************************************************
//Macros to implement Pearson's coefficient analysis of digital images.      
//[hidden email]
//Pearson's section written and tested  10 March 2004.
//Additions written October 2010.
//This version requires two stacks.  
//**************************************************************

macro "Pearson's coefficient of ROI [F7]" {
  requires('1.32c');
  // This section gets the titles of the images to operate on and converts them to PIDs.
  if (nImages<1) exit ("No image windows are open");  
  titlelist = newArray(nImages);                                      // titles of all open windows
  for (i=1; i<=nImages; i++) {
    selectImage(i);
    titlelist[i-1] = getTitle;
    run("Put Behind [tab]");
  }
  Dialog.create("scatterplot two images")
  Dialog.addMessage("Please pick two images to be compared.\nIf two different images have the same file name, results are unpredictable.");
  Dialog.addChoice("first image", titlelist);
  reversetitlelist = Array.invert(titlelist);
  Dialog.addChoice("second image", reversetitlelist);
  Dialog.show();
  image1 = Dialog.getChoice();
  image2 = Dialog.getChoice();
  print(image1, image2);
  selectWindow(image1);              // get image names and convert them to PIDs because these are more robust for use later.
  image1n = getImageID;
  selectWindow(image2);
  image2n = getImageID;

  for (i=1; i<=nSlices; i++){
    convertISlicesTo1Darrays(image1, image2, i);
  }
}  // end macro Pearson's


//***********************************************************************
// function convertImagesTo1Darrays(image1n, image2n);
// image1 and image2 are the PIDs of the stacks to be compared.
// The images are converted to 1D arrays that can be compared directly without graphics calls.
//***********************************************************************
function convertISlicesTo1Darrays(image1, image2, slice) {
  pixels = getWidth() * getHeight();
  cf = newArray(pixels);
  pip = newArray(pixels);
    arrayindex=0;
    selectImage(image1);  
    setSlice(slice);
    for (x=0; x<getWidth(); x++)
      for (y=0; y<getHeight(); y++){
        cf[arrayindex] = getPixel(x, y);
        arrayindex++;
      } // end for x and y loops
   
    arrayindex=0;
    selectImage(image2);
    setSlice(slice);
    for (x=0; x<getWidth(); x++)
      for (y=0; y<getHeight(); y++){
        pip[arrayindex] = getPixel(x, y);
        arrayindex++;
      } // end for x and y loops
     
  coef = calculateCoefficient(cf, pip);  
}  //end function convertSlicesTo1Darrays()


//*****************************************************************
// function calculateCoefficient(a, b);
// The function is passed two arrays of integers.  The arrays must be of
// equal length.  They are compared using Pearson's coeffiicent.
// Values of Zero are not considered.
//*****************************************************************
function calculateCoefficient(a, b) {
  if (a.length != b.length) exit ('arrays of unequal length');
  n = a.length;
  sXY=0;  sX=0;  sY=0;  sX2=0;  sY2=0; nn = 0;
  for (i=0; i<n; i++){
    if ((a[i] != 0) && (b[i] != 0)) {
      sXY = sXY + (a[i] * b[i]);
      sX = sX + a[i];
      sY = sY + b[i];
      sX2 = sX2 + (a[i] * a[i]);
      sY2 = sY2 + (b[i] * b[i]);
      nn++;
    }  // if
  } // for
  top = sXY - ((sX * sY) / nn);
  bottomleft = sX2 - ((sX * sX) / nn);
  bottomright = sY2 - ((sY * sY) / nn);
  bottom = pow((bottomleft*bottomright),0.5);
  Pearson = top / bottom;
   
  //print('sXY='+sXY+'  sX='+sX+'  sY='+sY+'  sX2='+sX2+'  sY2='+sY2+'  n='+n+' nn='+nn+'  top='+top+'  Pearson='+Pearson);
  print(Pearson);
  selectWindow("Log");
  return Pearson;
} //calculateCoefficient

// Make noisy image for Pearson's test
//********************************************************************
//macro 'make noisy image for test'{
//  run("New...", "name='noisy image' type=32-bit fill=Ramp width=64 height=64 slices=2");
//  for (z=1;z<=nSlices();z++) {run("Set Slice...", "slice="+z);
//    for (x=0;x<getWidth();x++) for (y=0;y<getHeight();y++)
//      putPixel(x,y,random());
//  } // z
//}

//macro "test the array"{
//  testa = newArray(3);  testb = newArray(3);
//  testa[0]=1;  testa[1]=2;  testa[2]=3;  testb[0]=2;  testb[1]=5;  testb[2]=6;
//  //testa[0]=1;  testa[1]=1;  testa[2]=1;  testb[0]=1;  testb[1]=1;  testb[2]=1;
//  coef = calculateCoefficient(testa, testb);  
//}  // END OF PEARSON'S MACROS

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Tom Runia
Sent: Monday, May 07, 2012 11:58 AM
To: [hidden email]
Subject: Averaging over a ring in ImageJ

Hi all,

I am working on an algorithm for which I need to compute the correlation coefficient between rings of two different images. The following image makes this somewhat more clear:
http://tweakers.net/ext/f/ZnXN3zSic04FIlLYVi3lfLXX/full.png
In order to calculate the correlation coefficient I need to obtain the average pixel value over both rings. Since writing all the code to achieve this myself is a lot of work, I was wondering whether anybody knows a plug-in that can do this?

So, my question is: "Does there exist an ImageJ plug-in that can calculate the average pixel value over a ring?"
Any help would be appreciated, Thanks!!

Best,

Tom
Reply | Threaded
Open this post in threaded view
|

Re: Averaging over a ring in ImageJ

LesleyIlic
In reply to this post by verified.human
To select the values of the resistors, you need to know the frame voltage and the short circuit current. The maximum torque occurs approximately at the point where the rotor reactance equals the termination resistance. The final stage of the resistance should always be designed for a maximum torque close to full speed to ring slip prevent a very large step in current when shorting the final stage of resistance. If a single stage was used and the maximum torque occured at 50% speed, then motor may accelerate to 60% speed, depending on the load. If the rotor was shorted at this speed, the motor would draw a very high current (typically around 1400% FLC) and produce very little torque, and would most probably stall!