15/07/2005, 17:49
|
| | Fecha de Ingreso: junio-2005
Mensajes: 286
Antigüedad: 19 años, 5 meses Puntos: 2 | |
Aqui un plug-in bastante simple (mas el estilo no es bueno). La parte donde accesas los pixels es en run() con las loops. Esto lo que hace es una segmentacion basada en dsos valores (los thresholds) (intensity clipping).
Código:
/**
* <p>Title: Test</p>
* <p>Description: Test</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author Willie
* @version 1.0
*/
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.filter.PlugInFilter;
public class test_java implements PlugInFilter {
int T1, T2;
public int setup(String arg, ImagePlus imp) {
return DOES_8G + DOES_STACKS + SUPPORTS_MASKING;
}
public void run(ImageProcessor ip) {
T1 = T2 = 0;
getThreshold();
byte[] pixels = (byte[])ip.getPixels();
int width = ip.getWidth();
Rectangle r = ip.getRoi();
int offset, i;
for (int y=r.y; y<(r.y+r.height); y++) {
offset = y*width;
for (int x=r.x; x<(r.x+r.width); x++) {
i = offset + x;
if ( ((int) (0xff & pixels[i]))< T1){
pixels[i] = (byte)(T1);
}
else{
if ( ((int) (0xff & pixels[i])) > T2){
pixels[i] = (byte)(T2);
}
}
}
}
} //run
/**
* Creates a dialog box, allowing the user to enter the requested
* width, height, x & y coordinates, slice number for a Region Of Interest,
* option for oval, and option for whether x & y coordinates to be centered.
*/
void getThreshold() {
int x = 1,y = 1;
GenericDialog gd = new GenericDialog("Specify Thresholds", IJ.getInstance());
gd.addNumericField("T1",T1, 0); //last number is how many decimals
gd.addNumericField("T2",T2, 0);
/*gd.addNumericField("Height:", iHeight, 0);
gd.addNumericField("X Coordinate:", iXROI, 0);
gd.addNumericField("Y Coordinate:", iYROI, 0);
gd.addNumericField("Slice:", iSlice, 0);*/
// gd.addCheckbox("Oval", oval);
//boolean test1 = false;
// gd.addCheckbox("Centered",test1);
gd.showDialog();
if (gd.wasCanceled()) {
//bAbort = true;
return;
}
/*
iWidth = (int) gd.getNextNumber();
iHeight = (int) gd.getNextNumber();
iXROI = (int) gd.getNextNumber();
iYROI = (int) gd.getNextNumber();
iSlice = (int) gd.getNextNumber();
oval = gd.getNextBoolean();
centered = gd.getNextBoolean();*/
}
}
|