Skip to content

Commit

Permalink
Move VIB's sources into fiji.git
Browse files Browse the repository at this point in the history
As discussed @ the EMBL hackathon.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Apr 11, 2010
0 parents commit 717b11c
Show file tree
Hide file tree
Showing 375 changed files with 80,899 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ROIBrushTool.txt
@@ -0,0 +1,35 @@

var brushWidth = 10;
var leftClick=16, alt=9;

requires("1.37c");
print("ImageJ version:", call("ij.IJ.getVersion")); // same as getVersion()
print("java.version:", call("java.lang.System.getProperty", "java.version"));
print("user.home:", call("java.lang.System.getProperty", "user.home"));
print("user.dir:", call("java.lang.System.getProperty", "user.dir"));
print("Images URL:", call("ij.Prefs.getImagesURL"));
print("Plugins path:", call("ij.Menus.getPlugInsPath"));


macro "Roi Brush Tool - C111o11ff" {
requires("1.37c");

while (true) {
getCursorLoc(x, y, z, flags);
if (flags&leftClick==0) exit();
if (flags&alt==0){
call("ROIBrush_.label", x,y,z,flags,brushWidth);
}else{
call("ROIBrush_.unlabel", x,y,z,flags,brushWidth);
}
wait(10);
}
}

macro 'Roi Brush Tool Options...' {
brushWidth = getNumber("Roi Brush Width (pixels):", brushWidth);
}




27 changes: 27 additions & 0 deletions adt/Byte3DArray.java
@@ -0,0 +1,27 @@
package adt;

/**
* User: Tom Larkworthy
* Date: 13-Jul-2006
* Time: 20:10:43
*/
public interface Byte3DArray {

void put(int x, int y, int z, byte val);

byte get(int x, int y, int z);

double getDouble(int x, int y, int z);

int getxMin();

int getxMax();

int getyMin();

int getyMax();

int getzMin();

int getzMax();
}
125 changes: 125 additions & 0 deletions adt/ByteProbability.java
@@ -0,0 +1,125 @@
package adt;

import java.util.Random;

/**
* User: Tom Larkworthy
*
* class that encodeds probilities as UNSIGNED bytes and makes things go seriously fast!
* Date: 14-Jul-2006
* Time: 00:08:49
*/
public class ByteProbability {

/**
* converts from byte's to probabilities usage: BYTE_TO_DOUBLE[myByte&0xFF]
*/
public static final double [] BYTE_TO_DOUBLE = new double[256]; //fast convertion between numbers 0-255 and doubles intervales [0.1]
public static final byte [] INTEGER_TO_BYTE = new byte[256]; //fast convertion between numbers 0-255 and unsigned bytes (packed in a signed byte)
public static final byte[][] MULTIPLY = new byte[256][256];
public static final byte[][] DIVIDE = new byte[256][256];


static{
for(int i=0; i<256; i++){
BYTE_TO_DOUBLE[i] = (double)i/(double)255;
}

for(int i=Byte.MIN_VALUE; i<=Byte.MAX_VALUE; i++){
byte val = (byte) i;
int intVal = val&0xFF;
INTEGER_TO_BYTE[intVal] = val;
}

for(int i=0; i<256; i++){
for(int j=0; j<256; j++){
MULTIPLY[i][j] = toByte(BYTE_TO_DOUBLE[i]*BYTE_TO_DOUBLE[j]);
}
}

for(int i=0; i<256; i++){
for(int j=0; j<256; j++){
DIVIDE[i][j] = toByte(BYTE_TO_DOUBLE[i]/BYTE_TO_DOUBLE[j]);
}
}
}

/**
* not so easy, SEQ search SLOW!!!
* @param v
* @return
*/
public static byte toByte(double v) {
byte nearest = 0;

double nearestValue = Double.MAX_VALUE;

for(int i=0; i<256; i++){
double val = BYTE_TO_DOUBLE[i];
double diff = Math.abs(v-val);

if(diff < nearestValue){
nearestValue = diff;
nearest = INTEGER_TO_BYTE[i];
}
}
return nearest;
}


public static final byte multiply(byte a, byte b){
return MULTIPLY[a&0xFF][b&0xFF];
}

public static final byte divide(byte a, byte b){
return DIVIDE[a&0xFF][b&0xFF];
}



public static void main(String[] args) {

for(int i=0;i<256;i++){
System.out.println("i = " + i);
byte tstByte = INTEGER_TO_BYTE[i];
System.out.println("tstByte = " + tstByte);
System.out.println("tstByte&0xFF = " + (tstByte & 0xFF));
System.out.println("INTEGER_TO_BYTE[tstByte & 0xFF] = " + INTEGER_TO_BYTE[tstByte & 0xFF]);
System.out.println("BYTE_TO_DOUBLE[tstByte&0xFF] = " + BYTE_TO_DOUBLE[tstByte & 0xFF]);
tstByte++;
}

Random rnd = new Random();
for(int i=0; i< 20; i++){
int index1 = rnd.nextInt(256);
int index2 = rnd.nextInt(256);

byte a = INTEGER_TO_BYTE[index1];
byte b = INTEGER_TO_BYTE[index2];

double ad = BYTE_TO_DOUBLE[a&0xFF];
double bd = BYTE_TO_DOUBLE[b&0xFF];

double multiply = BYTE_TO_DOUBLE[MULTIPLY[a&0xFF][b&0xFF] & 0xFF];
double check = ad*bd;
System.out.println("multiply via byte = " + multiply);
System.out.println("check via double = " + check);
}

for(int i=0; i< 20; i++){
int index1 = rnd.nextInt(256);
int index2 = rnd.nextInt(256);

byte a = INTEGER_TO_BYTE[index1];
byte b = INTEGER_TO_BYTE[index2];

double ad = BYTE_TO_DOUBLE[a&0xFF];
double bd = BYTE_TO_DOUBLE[b&0xFF];

double multiply = BYTE_TO_DOUBLE[DIVIDE[a&0xFF][b&0xFF] & 0xFF];
double check = ad/bd;
System.out.println("divide via byte = " + multiply);
System.out.println("check via double = " + check);
}
}
}
152 changes: 152 additions & 0 deletions adt/Connectivity2D.java
@@ -0,0 +1,152 @@
/*
* Created on 29-May-2006
*/
package adt;

import java.awt.Point;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
* a structure that partitions points added into it into connected islands (of Points)
* Probably could do with a speedup...
*/
public class Connectivity2D {
HashSet<Points> islands = new HashSet<Points>();

Point topLeft;
Point bottomRight;

public void addPoint(int x, int y) {
addPoint(new Point(x, y));
}

/**
* the contract of calling this method is that the new point must be gauranteed to
* be the most far right lowest point (i.e. its x&y are greater or equal to all other points)
* this gives a slight speedup
* (though I think the bottle neck is the merging of Points)
* @param p
*/
public void addLowerRightPoint(Point p){
//update the bounds
if(topLeft == null) topLeft = new Point(p.x,p.y);
else{
if(p.x < topLeft.x) topLeft.x = p.x;
if(p.y < topLeft.y) topLeft.y = p.y;
}
if(bottomRight == null) bottomRight = new Point(p.x,p.y);

addPoint(p, getUpperLeftNeigbours(p));
}

public void addPoint(Point p) {
//update the bounds
if(topLeft == null) topLeft = new Point(p.x,p.y);
else{
if(p.x < topLeft.x) topLeft.x = p.x;
if(p.y < topLeft.y) topLeft.y = p.y;
}
if(bottomRight == null) bottomRight = new Point(p.x,p.y);
else{
if(p.x > bottomRight.x) bottomRight.x = p.x;
if(p.y > bottomRight.y) bottomRight.y = p.y;
}
addPoint(p, getNeighbours(p));
}

private void addPoint(Point p, Set<Point> neigbours){

//add the point to the relevant island
Points masterIsland = null;
HashSet<Points> slaveIslands = new HashSet<Points>();

//go through every neuighbour of p
for(Point neighbour:neigbours){

//check it against every possible island
for(Points island:islands){

//if an island contains the neighbour, then this point is part of that island
if(island.contains(neighbour)){
island.addPoint(p);

if(masterIsland == null){
//so we have a definite island for this point now
masterIsland = island;
}else if(island != masterIsland){
//this point has joined some islands!
//add the extra islands to a datastructure for later processing
slaveIslands.add(island);
}
}
}
}

if(masterIsland == null){
//this means this point is an island of its own
Points island = new Points();
island.addPoint(p);
islands.add(island);
}else{
//the master island will stay, and all slave islands will be removed and merged with the master
//the point will have allready been added to the island lists
for(Points slave : slaveIslands){
masterIsland.addPoints(slave);
islands.remove(slave);
}
}
}



public Iterable<Points> getIslands(){
return islands;
}

/**
* 4 nieghbours per point
* @param p
* @return
*/
public static Set<Point> getNeighbours(final Point p){
HashSet<Point> neighbours = new HashSet<Point>();
for(int x=-1;x<2;x++)
for(int y=-1;y<2;y++)
{
if(x==0&&y==0)continue;
neighbours.add(new Point(p.x+x,p.y+y));
}
return neighbours;
}

/**
* 2 negihbours (with lower x or y values
* @param p
* @return
*/
public static Set<Point> getUpperLeftNeigbours(final Point p){
HashSet<Point> neighbours = new HashSet<Point>();
neighbours.add(new Point(p.x-1,p.y));
neighbours.add(new Point(p.x,p.y-1));
return neighbours;
}

public String toString(){
StringBuffer buf = new StringBuffer();
int islandIndex =0;
for(Points island:islands){
buf.append("\n").append("island: ").append(islandIndex++);

for(Point p:island.getPoints()){
buf.append(p).append("\t");

}
}

return buf.toString();

}

}

0 comments on commit 717b11c

Please sign in to comment.