public Function_Index getExtendedPolygonIterator() { final List l = new LinkedList(); for (final Iterator it = this.lLTL.iterator(); it.hasNext(); ) { final int[] iA = (int[]) it.next(); l.add(new int[] {iA[1], iA[0]}); } return PolygonFiller.polygonIteratorWithLessThans( PolygonFiller.clipPolygons( Generators.iteratorGenerator( IterationTools.addToEnd( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.lREL)) .iterator(), new PolygonFiller.Node(this.width, this.height, this.height, 1))), Generators.iteratorGenerator( IterationTools.addToEnd( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.rREL)) .iterator(), new PolygonFiller.Node(this.width, this.height, this.height, 1))), this.width + 1, this.height + 1), Generators.iteratorGenerator(this.rLTL.iterator()), Generators.iteratorGenerator(l.iterator()), new int[1000]); }
public ImageProcessor getMask() { if (cachedMask != null && cachedMask.getPixels() != null) return cachedMask; PolygonFiller pf = new PolygonFiller(); if (xSpline != null) pf.setPolygon(toIntR(xSpline), toIntR(ySpline), splinePoints); else if (xpf != null) pf.setPolygon(toIntR(xpf), toIntR(ypf), nPoints); else pf.setPolygon(xp, yp, nPoints); cachedMask = pf.getMask(width, height); return cachedMask; }
float[][][] backwardMatrix() { int[][] matrix = new int[this.height][this.width]; PolygonFillerTest.fillInMatrix( matrix, PolygonFillerTest.convertNewEdgeListToOldEdgeList( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.eT))), 1, 0); matrix = (int[][]) Array.transpose2DMatrix().fn(matrix); matrix = (int[][]) Array.reverseXAxisOf2DMatrix().fn(matrix); matrix = (int[][]) Array.reverseYAxisOf2DMatrix().fn(matrix); final float[] eS = this.endStates.clone(); Array.reverseArray(eS, 0, eS.length); final int[] rLTL2 = new int[1000]; final int[] lLTL2 = new int[1000]; PolygonFiller.reverseLessThanCoordinates( MatrixIteratorTest.convertLTPoints(this.rLTL), rLTL2, this.width - 1, this.height - 1); PolygonFiller.reverseLessThanCoordinates( MatrixIteratorTest.convertLTPoints(this.lLTL), lLTL2, this.width - 1, this.height - 1); final float[][][] matrixB = MatrixIteratorTest.computeMatrix( matrix, new Cell.CellCalculator() { /* (non-Javadoc) * @see bp.pecan.dpc.Cell.CellCalculator#calc(float[], int, int) */ public void calc(float[] cells, int offset, int x, int y) { ForwardBackwardMatrixIterTest.this.setCellsBackwardsLL.calc( cells, offset, ForwardBackwardMatrixIterTest.this.width - 1 - x, ForwardBackwardMatrixIterTest.this.height - 1 - y); } }, this.stateNumber, eS, Float.NEGATIVE_INFINITY, rLTL2, lLTL2); final float[][][] matrixB2 = new float[matrixB.length][matrixB[0].length][this.stateNumber]; for (int i = 0; i < matrixB.length; i++) { for (int j = 0; j < matrixB[i].length; j++) { for (int k = 0; k < matrixB[i][j].length; k++) { matrixB2[matrixB.length - 1 - i][matrixB[i].length - 1 - j][this.stateNumber - 1 - k] = matrixB[i][j][k]; } } } return matrixB2; }
float[][][] forwardMatrix() { int[][] matrix = new int[this.height][this.width]; PolygonFillerTest.fillInMatrix( matrix, PolygonFillerTest.convertNewEdgeListToOldEdgeList( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.eT))), 1, 0); matrix = (int[][]) Array.transpose2DMatrix().fn(matrix); return MatrixIteratorTest.computeMatrix( matrix, this.setCellsForwardsLL, this.stateNumber, this.startStates.clone(), Float.NEGATIVE_INFINITY, MatrixIteratorTest.convertLTPoints(this.lLTL), MatrixIteratorTest.convertLTPoints(this.rLTL)); }
protected void setup(final int minWidth) throws Exception { super.setUp(); this.r = new Random(); this.minMaxOffset = 1 + (int) (Math.random() * 5); this.height = 2 * this.minMaxOffset + (int) (Math.random() * 300); this.width = 2 * this.minMaxOffset + (int) (Math.random() * 300); this.stateNumber = 3; this.d1 = MatrixIteratorTest.getRandomSeq(this.width + 1, 4); this.d2 = MatrixIteratorTest.getRandomSeq(this.height + 1, 4); final Object[] oA = ForwardBackwardMatrixIterTest.getStateMachine_Float( ForwardBackwardMatrixIterTest.getD(this.d1), ForwardBackwardMatrixIterTest.getD(this.d2), "bp/pecan/asymmetric.hmm", 1001); this.setCellsForwardsLL = (Cell.CellCalculator) oA[0]; this.setCellsBackwardsLL = (Cell.CellCalculator) oA[1]; this.setCellsForwardsL = (Cell.CellCalculator) oA[2]; this.setCellsForwardsR = (Cell.CellCalculator) oA[3]; this.setCellsBackwardsL = (Cell.CellCalculator) oA[4]; this.setCellsBackwardsR = (Cell.CellCalculator) oA[5]; final List[] poly = PolygonFillerTest.getRandomPolygon(this.width, this.height, this.minMaxOffset, minWidth); this.lREL = poly[0]; this.rREL = poly[1]; // lLTL = // MatrixIteratorTest.getRandomLTPoints(PolygonFillerTest.convertOldEdgeListToNewEdgeList(lREL)); // rLTL = // MatrixIteratorTest.getRandomLTPoints(PolygonFillerTest.convertOldEdgeListToNewEdgeList(rREL)); this.eT = PolygonFillerTest.convertNewEdgeListToOldEdgeList( (List) IterationTools.append( PolygonFiller.combineEdgeLists( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.lREL)) .iterator(), PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.rREL)) .iterator()), new ArrayList())); int[][] matrix = new int[this.height][this.width]; PolygonFillerTest.fillInMatrix( matrix, PolygonFillerTest.convertNewEdgeListToOldEdgeList( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.eT))), 1, 0); matrix = (int[][]) Array.transpose2DMatrix().fn(matrix); this.lLTL = MatrixIteratorTest.getRandomLTPPointsL(matrix); this.rLTL = MatrixIteratorTest.getRandomLTPPointsR(matrix); this.mI = new MatrixIterator(this.stateNumber, 1000); this.polygonClipper = PolygonFiller.clipPolygons( Generators.iteratorGenerator( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.lREL)) .iterator()), Generators.iteratorGenerator( PolygonFiller.cloneEdgeList( PolygonFillerTest.convertOldEdgeListToNewEdgeList(this.rREL)) .iterator()), this.width, this.height); this.startStates = new float[] { (float) Math.log(1.0 / 3), (float) Math.log(1.0 / 3), (float) Math.log(1.0 / 3) }; this.endStates = new float[] { (float) Math.log(1.0 / 3), (float) Math.log(1.0 / 3), (float) Math.log(1.0 / 3) }; }
void analyzeParticle(int x, int y, ImagePlus imp, ImageProcessor ip) { // Wand wand = new Wand(ip); ImageProcessor ip2 = redirectIP != null ? redirectIP : ip; wand.autoOutline(x, y, level1, level2, wandMode); if (wand.npoints == 0) { IJ.log("wand error: " + x + " " + y); return; } Roi roi = new PolygonRoi(wand.xpoints, wand.ypoints, wand.npoints, roiType); Rectangle r = roi.getBounds(); if (r.width > 1 && r.height > 1) { PolygonRoi proi = (PolygonRoi) roi; pf.setPolygon(proi.getXCoordinates(), proi.getYCoordinates(), proi.getNCoordinates()); ip2.setMask(pf.getMask(r.width, r.height)); if (floodFill) ff.particleAnalyzerFill(x, y, level1, level2, ip2.getMask(), r); } ip2.setRoi(r); ip.setValue(fillColor); ImageStatistics stats = getStatistics(ip2, measurements, calibration); boolean include = true; if (excludeEdgeParticles) { if (r.x == minX || r.y == minY || r.x + r.width == maxX || r.y + r.height == maxY) include = false; if (polygon != null) { Rectangle bounds = roi.getBounds(); int x1 = bounds.x + wand.xpoints[wand.npoints - 1]; int y1 = bounds.y + wand.ypoints[wand.npoints - 1]; int x2, y2; for (int i = 0; i < wand.npoints; i++) { x2 = bounds.x + wand.xpoints[i]; y2 = bounds.y + wand.ypoints[i]; if (!polygon.contains(x2, y2)) { include = false; break; } if ((x1 == x2 && ip.getPixel(x1, y1 - 1) == fillColor) || (y1 == y2 && ip.getPixel(x1 - 1, y1) == fillColor)) { include = false; break; } x1 = x2; y1 = y2; } } } ImageProcessor mask = ip2.getMask(); if (minCircularity > 0.0 || maxCircularity < 1.0) { double perimeter = roi.getLength(); double circularity = perimeter == 0.0 ? 0.0 : 4.0 * Math.PI * (stats.pixelCount / (perimeter * perimeter)); if (circularity > 1.0) circularity = 1.0; // IJ.log(circularity+" "+perimeter+" "+stats.area); if (circularity < minCircularity || circularity > maxCircularity) include = false; } if (stats.pixelCount >= minSize && stats.pixelCount <= maxSize && include) { particleCount++; if (roiNeedsImage) roi.setImage(imp); stats.xstart = x; stats.ystart = y; saveResults(stats, roi); if (showChoice != NOTHING) drawParticle(drawIP, roi, stats, mask); } if (redirectIP != null) ip.setRoi(r); ip.fill(mask); }