/** * */ package cortexrules; import java.awt.geom.*; // Front End imports import analyze.*; /** *

This program takes the cortex output from * a version of the gabor model and links together * orientation elements that are the same valence. * * If they are adjancent they are joined together. * * Ultimately the output should be a general path that * draws a segmented object from this information *

* @author John H. Krantz, Ph.D. * Copyright 2007 * @version 0.1 * */ public class ConnectSame { // flags to indicate locations checked private boolean [][] checked; // start search position private int startX = 0, startY = 0; // routine to add to list of found shapes AddShape add = new AddShape(); // rule name public final static String NAME = "Opportunistic Contiguity"; // get methods /** * getAllShapes: allows all segmented shapes to be discovered * in the output of the cortex model * @param double [][][] cortex the cortex output data * @param Rectangle2D [][] rfArray the plotting array for the cortex * @return GeneralPath[][] the segmented shapes */ /** * first attempt. It just finds what is closest * and is opportunistic as it graps the first * contiguous edge without going through all orientations */ public GeneralPath [][] getAllShapes(double [][][] cortex, Rectangle2D [][] rfArray){ checked = new boolean[rfArray[0].length][rfArray.length]; // clear the array for (int i = 0; i < checked.length; i ++){ for (int j = 0; j < checked[0].length; j ++){ checked[i][j] = false; } } // objects to return GeneralPath posShapes [] = null; GeneralPath negShapes [] = null; // individual object that is found GeneralPath shape = new GeneralPath(); // start for searching for object. startX = 0; startY = 0; do { // chech for an object if (!checked[startX][startY]){ shape = null; boolean started = false;// has the first position been determined // array of points already part of shape boolean [][] already = new boolean[rfArray[0].length] [rfArray.length]; // clear for (int i = 0; i < already.length; i ++){ for (int j = 0; j < already[0].length; j ++){ already[i][j] = false; } } // connect mid points int x = startX; int y = startY; boolean pos = true; // direction of orientation do { if (!checked[x][y]){ if (cortex[PlotOutput.ANGLE][x][y] != PlotOutput.NO_ANGLE & cortex[PlotOutput.ANGLE][x][y] != PlotOutput.BREAK){ shape = new GeneralPath(); shape.moveTo(rfArray[y][x].getCenterX(), rfArray[y][x].getCenterY()); started = true; already[x][y] = true; startX = x; startY = y; if(cortex[PlotOutput.ANGLE][x][y] >= 0){ pos = true; // following positive or maxima } else { pos = false; // following negative or minima } } // end if there is an orientation } checked[x][y] = true; if (!started){ x ++; // increment counters if (x >= rfArray[0].length){ x = 0;// next row y ++; } } } while (!started & y < rfArray.length); // now find the rest of the page if(started){ boolean done = false; do { // continue till and end is found boolean connected = false; int i = -1, j = -1; do {// check all local connections // make sure it is on the array field if (x+i >=0 & x+i < rfArray[0].length & y+j >=0 & y+j < rfArray.length){ // make sure it is an angle and not already // connected if (cortex[PlotOutput.ANGLE][x+i][y+j] != PlotOutput.NO_ANGLE & !already[x+i][y+j]){ // make sure angle is of same sign if ((pos & cortex[PlotOutput.ANGLE][x+i][y+j] >= 0) | (!pos & cortex[PlotOutput.ANGLE][x+i][y+j] < 0)){ connected = true; x = x+i; y = y+j; checked[x][y] = true; already[x][y] = true; shape.lineTo(rfArray[y][x].getCenterX(), rfArray[y][x].getCenterY()); } // end if same direction } // end if an orientation } // if in range of array i ++; if (i > 1){ i = -1; j ++; if (j == 0 & i == 0) i ++; // do // not test current position } } while(!connected & j < 2); if (!connected) done = true;// if no connections // are found at this point, we are done } while (!done); // need rule to do a closing fo the path // shape.closePath(); } if (pos){ posShapes = add.addShape(posShapes, shape); } else { negShapes = add.addShape(negShapes, shape); } } // increment counters startX ++; if (startX >= checked.length){ startX = 0; startY ++; } } while (startY < checked[0].length); GeneralPath [][] shapes = {posShapes,negShapes}; return shapes; } }