forked from ethanzhao9/imagej1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
687 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Adds particle analyzer ROIs to the ROI Manager | ||
if (nResults==0) | ||
return "Results table is empty"; | ||
if (isNaN(getResult('XStart', 0))) | ||
return "Run the particle analyzer with \"Clear Results\" \nand \"Record Starts\" checked, then try again."; | ||
for (i=0; i<nResults; i++) { | ||
x = getResult('XStart', i); | ||
y = getResult('YStart', i); | ||
doWand(x,y); | ||
roiManager("add"); | ||
} | ||
return ""; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Converts a stack to binary using locally calculated thresholds | ||
|
||
setBatchMode(true); | ||
run("Select None"); | ||
run("8-bit"); | ||
id = getImageID; | ||
for (i=1; i<=nSlices; i++) { | ||
setSlice(i); | ||
run("Duplicate...", "title=temp"); | ||
run("Convert to Mask"); | ||
invertingLUT = is("Inverting LUT"); | ||
run("Copy"); | ||
close; | ||
selectImage(id); | ||
run("Paste"); | ||
if (i==1 && invertingLUT != is("Inverting LUT")) | ||
run("Invert LUT"); | ||
} | ||
run("Select None"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// This macro expands or shrinks a selection by | ||
// a specified distance. if the distance is zero, | ||
// it will attempt to convert a composite selection | ||
// into a polygon selection. | ||
|
||
pixels = parseFloat(getArgument()); | ||
if (isNaN(pixels)) exit("Distance is invalid: "+getArgument()); | ||
saveSettings(); | ||
getPixelSize(unit, pixelWidth, pixelHeight); | ||
n = pixels*pixelWidth; | ||
decimalPlaces = 0; | ||
if (floor(n)!=n) decimalPlaces = 2; | ||
Dialog.create("Enlarge Selection"); | ||
Dialog.addNumber(" Enlarge by", n, decimalPlaces, 4, unit); | ||
Dialog.addMessage("Enter negative number to shrink"); | ||
Dialog.show(); | ||
n = Dialog.getNumber(); | ||
pixels = n/pixelWidth; | ||
if (n==0) | ||
convertToPolygon(); | ||
else | ||
enlarge(pixels); | ||
restoreSettings(); | ||
return toString(pixels); | ||
|
||
function enlarge(n) { | ||
if (selectionType==0 || selectionType==1) { | ||
enlargeRectOrOval(n); | ||
return; | ||
} | ||
if (isOpen("Mask")) { | ||
selectImage("Mask"); | ||
close(); | ||
} | ||
if (n<0) { | ||
shrink(-n); | ||
return; | ||
} | ||
if (pixels > 255) | ||
exit("Cannot enlarge by more than 255 pixels"); | ||
id = getImageID(); | ||
setBatchMode(true); | ||
run("Options...", "iterations=1 count=1"); | ||
run("Create Mask"); | ||
run("Invert"); | ||
run("Distance Map"); | ||
setThreshold(0, n); | ||
run("Create Selection"); | ||
close(); | ||
selectImage(id); | ||
run("Restore Selection"); | ||
} | ||
|
||
// Convert composite selection to polygon selection | ||
function convertToPolygon() { | ||
if (selectionType!=9) return; | ||
id = getImageID(); | ||
getSelectionBounds(xbase, ybase, width, height); | ||
width = getWidth; | ||
height = getHeight; | ||
setBatchMode(true); | ||
run("Create Mask"); | ||
for (i=0;i<10000; i++) { | ||
x = xbase + width*random(); | ||
y = ybase + height*random(); | ||
v = getPixel(x,y); | ||
if (v>0) { | ||
doWand(x, y); | ||
close(); | ||
selectImage(id); | ||
run("Restore Selection"); | ||
return; | ||
} | ||
} | ||
close(); | ||
exit("Unable to convert to polygon selection"); | ||
} | ||
|
||
function enlargeRectOrOval(n) { | ||
getBoundingRect(x, y, width, height); | ||
x -= n; | ||
y -= n; | ||
width = width + 2*n; | ||
height = height + 2*n; | ||
if (width>0 && height>0) { | ||
if (selectionType==0) | ||
makeRectangle(x, y, width, height); | ||
else | ||
makeOval(x, y, width, height); | ||
} | ||
} | ||
|
||
function shrink(n) { | ||
if (pixels>255) | ||
exit("Cannot shrink by more than 255 pixels"); | ||
id = getImageID(); | ||
setBatchMode(true); | ||
width = getWidth(); | ||
height = getHeight(); | ||
getBoundingRect(xbase, ybase, roiWidth, roiHeight); | ||
touchingEdge = xbase<=0||ybase<=0||xbase+roiWidth>=width||ybase+roiHeight>=height; | ||
run("Options...", "iterations=1 count=1"); | ||
run("Create Mask"); | ||
if (touchingEdge) | ||
run("Canvas Size...", "width="+width+2+" height="+height+2+" position=Center zero"); | ||
run("Distance Map"); | ||
if (touchingEdge) | ||
run("Canvas Size...", "width="+width+" height="+height+" position=Center zero"); | ||
setThreshold(n+1, 255); | ||
run("Create Selection"); | ||
close(); | ||
selectImage(id); | ||
run("Restore Selection"); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// This macro implements the Image>HyperStacks>New HyperStack command. | ||
|
||
defaults = "8-bit Color 300 200 3 10 5 1"; | ||
if (is("applet")) | ||
prefs = split(defaults); | ||
else | ||
prefs = split(call("ij.Prefs.get", "hyperstack.new", defaults)); | ||
if(prefs.length<8) prefs = split(defaults); | ||
type = prefs[0]; | ||
mode = prefs[1]; | ||
width = parseInt(prefs[2]); | ||
height = parseInt(prefs[3]); | ||
c = parseInt(prefs[4]); | ||
z = parseInt(prefs[5]); | ||
t = parseInt(prefs[6]); | ||
label = parseInt(prefs[7]); | ||
title = "HyperStack"; | ||
Dialog.create("HyperStack"); | ||
Dialog.addString("Title:", title); | ||
Dialog.addChoice("Type:", newArray("8-bit", "16-bit", "32-bit", "RGB"), type); | ||
Dialog.addChoice("Display Mode:", newArray("Composite", "Color", "Grayscale"), mode); | ||
Dialog.addNumber("Width:", width); | ||
Dialog.addNumber("Height:", height); | ||
Dialog.addNumber("Channels (c):", c); | ||
Dialog.addNumber("Slices (z):", z); | ||
Dialog.addNumber("Frames (t):", t); | ||
Dialog.addCheckbox("Label Images", label); | ||
Dialog.show; | ||
title = Dialog.getString(); | ||
type = Dialog.getChoice(); | ||
mode = Dialog.getChoice(); | ||
width = Dialog.getNumber; | ||
height = Dialog.getNumber; | ||
c = Dialog.getNumber; | ||
z = Dialog.getNumber; | ||
t = Dialog.getNumber; | ||
label = Dialog.getCheckbox; | ||
batch = is("Batch Mode"); | ||
if (!batch) setBatchMode(true); | ||
if (label) | ||
type2 = type + " ramp"; | ||
else | ||
type2 = type + " black"; | ||
newImage(title, type2, width, height, c*z*t); | ||
run("Properties...", "channels="+c+" slices="+z+" frames="+t); | ||
showStatus(""); | ||
channel=1; slice=1; frame=1; | ||
setFont("SansSerif", 24); | ||
if (label) { | ||
yloc = 30; | ||
for (i=1; i<=nSlices; i++) { | ||
showProgress(i, nSlices); | ||
setSlice(i); | ||
setColor(0, 0, 0); | ||
fillRect(0, 0, width, yloc); | ||
fillRect(0, yloc+15, width, height-(yloc+15)); | ||
setColor(255, 255, 255); | ||
drawString("c="+pad(channel)+", z="+pad(slice)+", t="+pad(frame), 5, yloc); | ||
if (i<=c) { | ||
setFont("SansSerif", 12, "antialiased"); | ||
msg = "Press shift-z (Image>HyperStacks>Channels)\n"+ | ||
"to open the \"Channels\" window, which will\n"+ | ||
"allow you switch to composite color mode\n"+ | ||
"and to enable/disable channels.\n"; | ||
drawString(msg, 25, 80); | ||
setFont("SansSerif", 24); | ||
} | ||
channel++; | ||
if (channel>c) { | ||
channel = 1; | ||
slice++; | ||
if (slice>z) { | ||
slice = 1; | ||
frame++; | ||
if (frame>t) frame = 1; | ||
} | ||
} | ||
} | ||
} | ||
setSlice(1); | ||
if (c>1 && bitDepth!=24) | ||
run("Make Composite", "display="+mode); | ||
setOption("OpenAsHyperStack", true); | ||
if (!batch) setBatchMode(false); | ||
prefs = type+" "+mode+" "+width+" "+height+" "+c+" "+z+" "+t+" "+label; | ||
if (!is("applet")) | ||
call("ij.Prefs.set", "hyperstack.new", prefs); | ||
exit; | ||
|
||
|
||
function pad(n) { | ||
str = toString(n); | ||
while (lengthOf(str)<3) | ||
str = "0" + str; | ||
return str; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// This macro imports a saved ImageJ results table, | ||
// or any tab or comma-separated data file. | ||
|
||
lineseparator = "\n"; | ||
cellseparator = ",\t"; | ||
|
||
// copies the whole table to an array of lines | ||
lines=split(File.openAsString(""), lineseparator); | ||
if (lines.length==0) return; | ||
path = File.directory + File.name; | ||
|
||
// get the columns headers | ||
labels=split(lines[0], cellseparator); | ||
if (labels.length==1) | ||
exit("This is not a tab or comma delimited text file."); | ||
if (labels[0]==" ") | ||
k=1; // it is an ImageJ Results table, skip first column | ||
else | ||
k=0; // it is not a Results table, load all columns | ||
|
||
// is this a Results table? | ||
if (k==1 || lines.length<2) | ||
{importResults(); exit;} | ||
items = split(lines[1]); | ||
nonNumericItems = false; | ||
for (i=0; i<items.length; i++) { | ||
if (isNaN(parseFloat(items[i]))) nonNumeric=true; | ||
} | ||
if (nonNumeric) | ||
importTable(); | ||
else | ||
importResults(); | ||
exit; | ||
|
||
function importResults() { | ||
for (j=k; j<labels.length; j++) | ||
setResult(labels[j],0,0); | ||
run("Clear Results"); | ||
if (k==1) | ||
call("ij.plugin.filter.Analyzer.setDefaultHeadings"); | ||
for (i=1; i<lines.length; i++) { | ||
items=split(lines[i], cellseparator); | ||
for (j=k; j<items.length; j++) | ||
setResult(labels[j],i-1,items[j]); | ||
} | ||
updateResults(); | ||
} | ||
|
||
function importTable() { | ||
name = "["+File.name+"]"; | ||
if (!isOpen(File.name)) | ||
run("New... ", "name="+name+" type=Table"); | ||
f = name; | ||
print(f, "\\Headings:"+lines[0]); | ||
for (i=1; i<lines.length; i++) | ||
print(f, lines[i]); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// This macro creates a band (donut shaped) | ||
// selection of the specified size. | ||
|
||
if (selectionType==9) | ||
exit("Area selection required"); | ||
pixels = parseFloat(getArgument()); | ||
if (isNaN(pixels)) exit("Distance is invalid: "+getArgument()); | ||
getPixelSize(unit, pixelWidth, pixelHeight); | ||
size = pixels*pixelWidth; | ||
decimalPlaces = 0; | ||
if (floor(size)!=size) decimalPlaces = 2; | ||
Dialog.create("Make Band"); | ||
Dialog.addNumber("Band Size:", size, decimalPlaces, 4, unit); | ||
//Dialog.addMessage("Enter negative number to shrink"); | ||
Dialog.show(); | ||
size = Dialog.getNumber(); | ||
pixels = size/pixelWidth; | ||
makeBand(pixels); | ||
return toString(pixels); | ||
|
||
function makeBand(n) { | ||
if (n >255) | ||
exit("Cannot make bands wider that 255 pixels"); | ||
id = getImageID(); | ||
setBatchMode(true); | ||
getBoundingRect(xbase, ybase, width, height); | ||
getSelectionCoordinates(xc, yc); | ||
run("Create Mask"); | ||
run("Invert"); | ||
run("Options...", "iterations=1 count=1"); | ||
run("Distance Map"); | ||
setThreshold(0, n); | ||
x = xbase + width/2; | ||
y = ybase + height/2; | ||
count = 0; | ||
while(getPixel(x,y)>n) { | ||
if (count++==10000) | ||
exit("Unable to scale selection"); | ||
x = xbase + width*random(); | ||
y = ybase + height*random(); | ||
} | ||
doWand(x, y); | ||
setKeyDown('alt'); | ||
makeSelection("polygon", xc, yc); | ||
close(); | ||
selectImage(id); | ||
run("Restore Selection"); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Moves the selection left and down a specified distance in pixels. | ||
|
||
xy = split(getArgument()); | ||
if (lengthOf(xy)!=2) { | ||
dx = 10; | ||
dy = 10; | ||
} else { | ||
dx = parseFloat(xy[0]); | ||
if (isNaN(dx)) dx = 10; | ||
dy = parseFloat(xy[1]); | ||
if (isNaN(dy)) dy = 10; | ||
} | ||
getPixelSize(unit, pixelWidth, pixelHeight); | ||
if (unit=="pixel") unit = "pixels"; | ||
dxc = dx*pixelWidth; | ||
dyc = dy*pixelHeight; | ||
Dialog.create("Move"); | ||
Dialog.addNumber("Delta_X ("+unit+"):", dxc); | ||
Dialog.addNumber("Delta_Y ("+unit+"):", dyc); | ||
Dialog.show(); | ||
dx = Dialog.getNumber()/pixelWidth; | ||
dy = Dialog.getNumber()/pixelHeight; | ||
moveSelection(dx, dy); | ||
return toString(dx)+" "+toString(dy); | ||
|
||
function moveSelection(dx, dy) { | ||
getBoundingRect(x, y, width, height); | ||
if (selectionType==0) | ||
makeRectangle(x+dx, y+dy, width, height); | ||
else if (selectionType==1) | ||
makeOval(x+dx, y+dy, width, height); | ||
else { | ||
getSelectionCoordinates(xCoordinates, yCoordinates); | ||
for (i=0; i<xCoordinates.length; i++) { | ||
xCoordinates[i] += dx; | ||
yCoordinates[i] += dy; | ||
} | ||
makeSelection(selectionType, xCoordinates, yCoordinates); | ||
} | ||
} |
Oops, something went wrong.