/** * Returns a ROI that contains the point. * * @param coordenadas point * @return Roi that contains the point */ public int getRoi(Point coordenadas) { Roi roi; if (arrayRois != null) { for (int i = 0; i < arrayRois.length; i++) { roi = arrayRois[i]; if (roi.contains(coordenadas.x, coordenadas.y)) { return i; } } } return -1; }
/* * Searches the x and y coordinate arrays in a wand object to see if they * contain the values provided as parameters * * NOTE: does not account for if the given coordinates represent the same * point only if each array contains the specified coordinate. * * returns true if both points are found in the arrays, otherwise returns * false */ public boolean wandContains(Roi region, int x, int y) { return region.contains(x, y); }
void labelParticles( ImageProcessor ipBinary, ImageProcessor ipRaw, int nFrame, double dPixelSize_, int nAreaCut, double dPSFsigma_, Overlay SpotsPositions__, boolean bShow, Roi RoiAct) { int width = ipBinary.getWidth(); int height = ipBinary.getHeight(); int dBorder; // radius in pixels around center point to fit Gaussian int nArea; int i, j; double dVal, dInt; double dIMax, dIMin; double xCentroid, yCentroid; boolean bBorder; boolean bInRoi; int lab = 1; int[] pos; Stack<int[]> sstack = new Stack<int[]>(); int[][] label = new int[width][height]; OvalRoi spotROI; dBorder = (int) (dPSFsigma_ * DOMConstants.FITRADIUS); for (int r = 1; r < width - 1; r++) for (int c = 1; c < height - 1; c++) { if (ipBinary.getPixel(r, c) == 0.0) continue; if (label[r][c] > 0.0) continue; /* encountered unlabeled foreground pixel at position r, c */ /* it means it is a new spot! */ /* push the position in the stack and assign label */ sstack.push(new int[] {r, c}); label[r][c] = lab; nArea = 0; dIMax = -1000; xCentroid = 0; yCentroid = 0; // xMax = 0; yMax = 0; dInt = 0; bBorder = false; /* start the float fill */ while (!sstack.isEmpty()) { pos = (int[]) sstack.pop(); i = pos[0]; j = pos[1]; // remove all spots at border if (i == 0 || j == 0 || i == (width - 1) || j == (height - 1)) bBorder = true; nArea++; dVal = ipRaw.getPixel(i, j); if (dVal > dIMax) dIMax = dVal; dInt += dVal; xCentroid += dVal * i; yCentroid += dVal * j; if (ipBinary.getPixel(i - 1, j - 1) > 0 && label[i - 1][j - 1] == 0) { sstack.push(new int[] {i - 1, j - 1}); label[i - 1][j - 1] = lab; } if (ipBinary.getPixel(i - 1, j) > 0 && label[i - 1][j] == 0) { sstack.push(new int[] {i - 1, j}); label[i - 1][j] = lab; } if (ipBinary.getPixel(i - 1, j + 1) > 0 && label[i - 1][j + 1] == 0) { sstack.push(new int[] {i - 1, j + 1}); label[i - 1][j + 1] = lab; } if (ipBinary.getPixel(i, j - 1) > 0 && label[i][j - 1] == 0) { sstack.push(new int[] {i, j - 1}); label[i][j - 1] = lab; } if (ipBinary.getPixel(i, j + 1) > 0 && label[i][j + 1] == 0) { sstack.push(new int[] {i, j + 1}); label[i][j + 1] = lab; } if (ipBinary.getPixel(i + 1, j - 1) > 0 && label[i + 1][j - 1] == 0) { sstack.push(new int[] {i + 1, j - 1}); label[i + 1][j - 1] = lab; } if (ipBinary.getPixel(i + 1, j) > 0 && label[i + 1][j] == 0) { sstack.push(new int[] {i + 1, j}); label[i + 1][j] = lab; } if (ipBinary.getPixel(i + 1, j + 1) > 0 && label[i + 1][j + 1] == 0) { sstack.push(new int[] {i + 1, j + 1}); label[i + 1][j + 1] = lab; } } /* end while */ if (!bBorder && nArea > nAreaCut) { xCentroid /= dInt; yCentroid /= dInt; if ((xCentroid > dBorder) && (yCentroid > dBorder) && (xCentroid < (width - 1 - dBorder)) && (yCentroid < (height - 1 - dBorder))) { bInRoi = true; if (RoiAct != null) { if (!RoiAct.contains((int) xCentroid, (int) yCentroid)) bInRoi = false; } if (bInRoi) { // find minimum value around peak position dIMin = 1000000; // nCount = 0; for (i = (int) (Math.round(xCentroid) - dBorder); i <= Math.round(xCentroid) + dBorder; i++) for (j = (int) (Math.round(yCentroid) - dBorder); j <= Math.round(yCentroid) + dBorder; j++) { dVal = ipRaw.getPixel(i, j); if (dVal < dIMin) dIMin = dVal; } ptable_lock.lock(); ptable.incrementCounter(); ptable.addValue("Frame Number", nFrame + 1); ptable.addValue("X_centroid_(px)", xCentroid); ptable.addValue("Y_centroid_(px)", yCentroid); ptable.addValue("MaxInt", dIMax); ptable.addValue("MinInt", dIMin); ptable_lock.unlock(); if (bShow) { spotROI = new OvalRoi( 0.5 + xCentroid - 2 * dPSFsigma_, 0.5 + yCentroid - 2 * dPSFsigma_, 4.0 * dPSFsigma_, 4.0 * dPSFsigma_); spotROI.setStrokeColor(Color.yellow); spotROI.setPosition(nFrame + 1); SpotsPositions__.add(spotROI); } } } } lab++; } // end for cycle return; // label ; }