Using cursor lock on multiple images

Hi,

I’ve been successful in using getcursorlock in a single image, however I’m having issues applying it correctly to multiple images. I have 4 images that I’m trying to extract the x,y pixel value and then automatically close once it measures, I think that has been done successfully.

Currently when I have 4 images open, the first image declares the pixel value and closes as required. Upon subsequent measurements, the other three close abruptly without me being able to make my measurement, however the cursorlock x,y value is posted in results. Any thoughts would be appreciated.

alt=8;
leftButton=16;
insideROI = 32; // requires 1.42i or later
i=0;

centre_x=0;
centre_y=0;
centreValue = getPixel(centre_x,centre_y);

xi=newArray(1);
yi=newArray(1);
x2=-1; y2=-1; z2=-1; flags2=-1;
QAReady=0;
while (QAReady==0 ) {
getCursorLoc(x, y, z, flags);
if (x!=x2 || y!=y2 || z!=z2 || flags!=flags2) {
s = " ";
{

    index = Centre.indexAt(x,y);
	if((flags&alt!=0)&(flags&leftButton!=0)) {  
    print(x,y);
	drawLine(x-5,y,x+5,y);
	drawLine(x,y-5,x,y+5);
    close();
 }
		
	}
   }
  }

x2=x; y2=y; z2=z; flags2=flags;
      wait(100);

Hi.
There are several issues with your macro:
You never exit the while loop : while (QAReady==0 ) {…
You never reach lines 32-33
Centre.indexAt(x,y); is not a valid macro language function.
variables index, s, centreValue are never used.

What exactly is the workflow you’re trying to achieve? Pick 4 different points in 4 different images?

Jerome

Hi Jerome, thanks for the reply, so I actually want to perform two functions. First is to assign a circle to the image and call the centroid, then using cursorlock, manually extract the x,y pixel value using an alt+mouse click, and then measure the distance between them. This would be completed for four images. I think I need arrays to store values to then perform the distance measurements.

//PW = 0.40096 //pixel width 0.390625

   dir = getDirectory( "Choose the Directory" );
   list = getFileList( dir );
   for ( i=0; i<list.length; i++ ) {
   open( dir + list[i] );
    }
   
   //setBatchMode(true);
   count = 0;
   countFiles(dir);
   n = 0;
   processFiles(dir);
   print(count+" files processed");
   
  
   function countFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              countFiles(""+dir+list[i]);
          else
              count++;
        }
    }
	
   function processFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              processFiles(""+dir+list[i]);
          else {
             showProgress(n++, count);
             path = dir+list[i];
             processFile(path);
          }
      }
  }

//complete a measurement of the centroid
function processFile(path) {
if (endsWith(path, “.dcm”)){ {
open(path);
setAutoThreshold(“Shanbhag”);
setThreshold(0, 27310);
setOption(“BlackBackground”, false);
run(“Convert to Mask”);
run(“Analyze Particles…”, “size=100-99999 circularity=0.6-1.00 exclude display”);
//run(“Measure”);
//close();
//proceed with the manual click of the central spot using getCursorLock
}
alt=8;
leftButton=16;
insideROI = 32; // requires 1.42i or later
i=0;

			centre_x=0;
			centre_y=0;
			centreValue = getPixel(centre_x,centre_y);

			x2=-1; y2=-1; z2=-1; flags2=-1;
			QAReady=0;
			while (QAReady==0 ) {
			getCursorLoc(x, y, z, flags);
			if (x!=x2 || y!=y2 || z!=z2 || flags!=flags2) {
			s = " ";
			{
      
			if((flags&alt!=0)&(flags&leftButton!=0)) {  
			print(x,y);
			drawLine(x-5,y,x+5,y);
			drawLine(x,y-5,x,y+5);
			close();
			}
		
		}
	}
 }

}
x2=x; y2=y; z2=z; flags2=flags;
wait(100);

	updateResults();  // Update the results table so it shows the filenames

		
	dir=getDirectory("image");
	name = "Results"; 
	index = lastIndexOf(name, "\\"); 
	if (index!=-1) name = substring(name, 0, index); 
	name = name + ".txt"; 
	saveAs("Measurements", dir+name);

so I think my attempts so far are a little messy, but I’m giving it a crack…Capture

I would advise that you first try to have your process running for one image, then only try to apply it to your set of images.

Here is one suggestion of how to perform your task, although you have to adapt it because I used the posted exemple only.

1 is the detected circle; 2 is the picked point; 3 is the line between circle centroid and picked point.

image

and here is the code, in which the macro stops and asks the user to pick a point with the point tool. I think it will be easier than including your code in a dedicated macro tool while loop.

roiManager("reset");
setThreshold(85, 110);
run("Analyze Particles...", "size=1000-Infinity circularity=0.70-1.00 add");
roiManager("Select", 0);
xc = getValue("X");
yc = getValue("Y");
run("Select None");
resetThreshold();
setTool("point");
run("Point Tool...", "type=Cross color=Yellow size=Small");
roiManager("Show None");
waitForUser("Pick a point and press OK");
roiManager("add");
getSelectionBounds(xp, yp, width, height);
makeLine(xc,yc,xp,yp);
myLength = getValue("Length");
roiManager("add");
roiManager("Show All");
print ("length: "+myLength);

Jerome.

1 Like