Created
September 20, 2024 10:26
-
-
Save ekatrukha/105553627f1bee01367faae153bfe5c0 to your computer and use it in GitHub Desktop.
ComDet particle radius/cell periphery distance calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//script needs 2 ROIs to be present in the ROI manager | |
//+ image itself | |
//+ Results table with particle coordinates | |
// First ROI is an outline of the cell (FREEHAND selection) | |
// The second ROI is a Point ROI of the cell's center | |
// Partice/vesicles coordinates colum names in Results table | |
// should start with X,Y | |
origID=getImageID(); | |
getPixelSize(unit,pxW,pxH); | |
//print(pxW); | |
dW=getWidth(); | |
dH=getHeight(); | |
maxR=sqrt(dW*dW+dH*dH); | |
xL=newArray(nResults); | |
yL=newArray(nResults); | |
Dialog.create("Particle XY coordinate units"); | |
items = newArray(2); | |
items[0]="pixels"; | |
items[1]="same units as the current image pixel size"; | |
Dialog.addChoice("Particle XY coords are in", items); | |
Dialog.show(); | |
nXYUnitType = Dialog.getChoice(); | |
print(nXYUnitType); | |
headings = split(String.getResultsHeadings,'\t'); | |
xCoordHead="ZZZ"; | |
yCoordHead="ZZZ"; | |
for (col=0; col<lengthOf(headings); col++) | |
{ | |
if(startsWith(headings[col],"X")) | |
{ | |
xCoordHead=headings[col]; | |
} | |
if(startsWith(headings[col],"Y")) | |
{ | |
yCoordHead=headings[col]; | |
} | |
} | |
if(startsWith(xCoordHead, "ZZ")||startsWith(yCoordHead, "ZZ")) | |
{ | |
exit("Cannot find Results Table or columns with X and Y coordinates"); | |
} | |
for (i = 0; i < nResults(); i++) { | |
xL[i] = getResult(xCoordHead, i); | |
yL[i] = getResult(yCoordHead, i); | |
if(startsWith(nXYUnitType, "same")) | |
{ | |
toUnscaled(xL[i], yL[i]); | |
} | |
//makePoint(xL[i], yL[i], "small yellow hybrid"); | |
//roiManager("Add"); | |
} | |
//get coordinates of the center | |
roiManager("Select", 1); | |
Roi.getCoordinates(xpoints, ypoints); | |
//print(xpoints[0]); | |
//print(ypoints[0]); | |
xC=xpoints[0]; | |
yC=ypoints[0]; | |
newImage("Untitled", "8-bit black", dW, dH, 1); | |
mask=getImageID(); | |
setForegroundColor(255, 255, 255); | |
setBackgroundColor(0, 0, 0); | |
roiManager("Select", 0); | |
run("Fill", "slice"); | |
//for (k = 0; k < 1; k++) | |
for (k = 0; k < nResults(); k++) | |
{ | |
linevectX=xL[k]-xC; | |
linevectY=yL[k]-yC; | |
norm = sqrt(linevectX*linevectX+linevectY*linevectY); | |
linevectX=linevectX/norm; | |
linevectY=linevectY/norm; | |
makeLine(xC, yC, xC+linevectX*maxR, yC+linevectY*maxR); | |
//roiManager("Add"); | |
//print(toString(k)); | |
profile = getProfile(); | |
deriv = newArray(profile.length-1); | |
for ( r = 1; r < profile.length; r++ ) | |
{ | |
deriv[r-1]=abs( profile[r] - profile[r-1] ); | |
} | |
maxPos = Array.findMaxima( deriv, 0, 1 ); | |
crosss=maxPos[0]; | |
//print(crosss); | |
//makePoint(xC+linevectX*crosss, yC+linevectY*crosss, "small yellow hybrid"); | |
xpoints = newArray(2); | |
ypoints = newArray(2); | |
xpoints[0]=xL[k]; | |
ypoints[0]=yL[k]; | |
xpoints[1]=xC+linevectX*crosss; | |
ypoints[1]=yC+linevectY*crosss; | |
//makeSelection("point", xpoints, ypoints); | |
//roiManager("Add"); | |
if(startsWith(nXYUnitType, "pixel")) | |
{ | |
setResult("Dist_center_(pixels)", k, norm); | |
setResult("Dist_periphery_(pixels)", k, (crosss-norm)); | |
} | |
else | |
{ | |
setResult("Dist_center_("+unit+")", k, norm*pxW); | |
setResult("Dist_periphery_("+unit+")", k, (crosss-norm)*pxW); | |
} | |
} | |
selectImage(mask); | |
close(); | |
selectImage(origID); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment