Skip to content

Instantly share code, notes, and snippets.

View tferr's full-sized avatar

Tiago Ferreira tferr

View GitHub Profile
@tferr
tferr / Two_Images_T-test.bsh
Created November 17, 2014 20:27
t-test between two ImageJ1 images
/*
* IJ BAR: https://github.com/tferr/Scripts#scripts
*
* Performs a t-test between two open images (http://thread.gmane.org/gmane.comp.java.imagej/35266) using
* commons-math:
* http://commons.apache.org/proper/commons-math/userguide/stat.html
* http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/stat/inference/TTest.html
*
*/
// yet another multichannel profile plotter
// with smart(?) lookuptables
Stack.getDimensions(w, h, c, z, t);
p = getProfile();
getStatistics(null, null, min, max);
Plot.create("Multi-Channel Profile Plot", "Distance (pixels)", "Value");
Plot.setLimits(0,p.length,min,max);
for (i=1;i<=c;i++) {
Stack.setChannel(i);
@tferr
tferr / Mirror_Selection.ijm
Created December 8, 2014 13:27
ImageJ1 macros that create X/Y mirrors of the active ROI
// ImageJ1 macros that create X/Y mirrors of the active ROI
// http://thread.gmane.org/gmane.comp.java.imagej/35570
macro "Contralateral in X [F1]" {
mirrorROI(-1, 1);
}
macro "Contralateral in Y [F2]" {
mirrorROI(1, -1);
}
@tferr
tferr / ValidateFileExtension.java
Created January 6, 2015 16:14
Validate file extensions using regex
import java.util.regex.Matcher;
import java.util.regex.Pattern;
boolean validFile(String filename) {
String FILE_PATTERN = "(.*(\\.(?i)(stk|tif))$)";
Pattern pattern = Pattern.compile(FILE_PATTERN);
Matcher matcher = pattern.matcher(filename);
return matcher.matches();
}
@tferr
tferr / Random_String.ijm
Created January 6, 2015 16:39
ImageJ1 macro function to generate random string
function randomString(length, spacers) {
template = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
nChars = lengthOf(template);
string = "";
for (i=0; i<length; i++) {
idx = maxOf(0, round(random()*nChars-1));
string += substring(template, idx, idx+1);
if (spacers && i%5==0) string += "_";
}
return string;
@tferr
tferr / getRadioCheckbox.java
Last active August 29, 2015 14:27
Get checkbox of RadioButtonGroup
/**
* Retrieves the Checkbox of a RadioButtonGroup() in an ImageJ1
* GenericDialog associated with the specified label.
*/
Checkbox getRadioCheckbox(ij.gui.GenericDialog gd, String label) {
Component[] gdComponents = gd.getComponents();
for (Component c1 : gdComponents) {
if (c1 instanceof Panel) {
Component[] c1Components = ((Panel) c1).getComponents();
for (Component c2 : c1Components) {
@tferr
tferr / Polar_Plot_Demo.bsh
Created September 15, 2016 13:12
A Demo Polar Plot Rendered in ImageJ
/* Polar_Plot_Demo.bsh
* IJ BAR: https://github.com/tferr/Scripts#scripts
*
* Beanshell implementation of JFreeChart[1] PolarChartDemo[2]
*
* [1] http://www.jfree.org/jfreechart/api/javadoc/
* [2] http://www.java2s.com/Code/Java/Chart/JFreeChartPolarChartDemo.htm
*/
import ij.gui.GUI;
@tferr
tferr / Convert_Traces_to_SWC.py
Created October 27, 2016 17:26 — forked from mhl/Convert_Traces_to_SWC.py
Batch convert Simple Neurite Tracer's .traces files to SWC format
import os
import re
from tracing import PathAndFillManager
# An example script showing how to convert all the .traces
# files in a directory to SWC files. (The .traces format
# is the native file format of Simple Neurite Tracer.)
def run():
d = IJ.getDirectory("Choose your directory of .traces files...")
# @ImageJ ij
# @Dataset data
# @String(label="Projection Type",choices={"Max","Mean","Median","Min", "StdDev", "Sum"}) proj_type
from net.imagej.axis import Axes
from net.imagej.ops import Ops
def proj_method(method):
ImageJ 2.0.0-rc-56/1.51j; Java 1.8.0_66 [x86_64]
-- Application: ImageJ --
Title = ImageJ
Version = 2.0.0-rc-56/1.51j
groupId = net.imagej
artifactId = imagej
Archiver-Version = Plexus Archiver
Build-Jdk = 1.8.0_111
Built-By = jenkins-maven