/** delete a line starting at x, y up to the next (4-connected) vertex */ void removeLineFrom (byte[] pixels, int x, int y) { //IJ.log("del line from "+x+","+y); pixels[x + width*y] = (byte)255; //delete the first point boolean continues; do { continues = false; boolean isInner = (y!=0 && y!=height-1) && (x!=0 && x!=width-1); //not necessary, but faster than isWithin for (int d=0; d<8; d+=2) { //analyze 4-connected neighbors if (isInner || isWithin(x, y, d)) { int v = pixels[x + width*y + dirOffset[d]]; if (v!=(byte)255 && v!=0) { int nRadii = nRadii(pixels, x+DIR_X_OFFSET[d], y+DIR_Y_OFFSET[d]); if (nRadii<=1) { //found a point or line end x += DIR_X_OFFSET[d]; y += DIR_Y_OFFSET[d]; pixels[x + width*y] = (byte)255; //delete the point continues = nRadii==1; //continue along that line break; } } } } // for directions d } while (continues); //IJ.log("deleted to "+x+","+y); } // void removeLineFrom
/** delete a line starting at x, y up to the next (4-connected) vertex */ void removeLineFrom (byte[] pixels, int x, int y) { //IJ.log("del line from "+x+","+y); pixels[x + width*y] = (byte)255; //delete the first point boolean continues; do { continues = false; boolean isInner = (y!=0 && y!=height-1) && (x!=0 && x!=width-1); //not necessary, but faster than isWithin for (int d=0; d<8; d+=2) { //analyze 4-connected neighbors if (isInner || isWithin(x, y, d)) { int v = pixels[x + width*y + dirOffset[d]]; if (v!=(byte)255 && v!=0) { int nRadii = nRadii(pixels, x+DIR_X_OFFSET[d], y+DIR_Y_OFFSET[d]); if (nRadii<=1) { //found a point or line end x += DIR_X_OFFSET[d]; y += DIR_Y_OFFSET[d]; pixels[x + width*y] = (byte)255; //delete the point continues = nRadii==1; //continue along that line break; } } } } // for directions d } while (continues); //IJ.log("deleted to "+x+","+y); } // void removeLineFrom
/** Delete extra structures form watershed of non-EDM images, e.g., foreground patches, * single dots and lines ending somewhere within a segmented particle * Needed for post-processing watershed-segmented images that can have local minima * @param ip 8-bit image with background = 0, lines between 1 and 254 and segmented particles = 255 */ void cleanupExtraLines(ImageProcessor ip) { byte[] pixels = (byte[])ip.getPixels(); for (int y=0, i=0; y<height; y++) { for (int x=0; x<width; x++,i++) { int v = pixels[i]; if (v!=(byte)255 && v!=0) { int nRadii = nRadii(pixels, x, y); //number of lines radiating if (nRadii==0) //single point or foreground patch? pixels[i] = (byte)255; else if (nRadii==1) removeLineFrom(pixels, x, y); } // if v<255 && v>0 } // for x } // for y } // void cleanupExtraLines
/** Delete extra structures form watershed of non-EDM images, e.g., foreground patches, * single dots and lines ending somewhere within a segmented particle * Needed for post-processing watershed-segmented images that can have local minima * @param ip 8-bit image with background = 0, lines between 1 and 254 and segmented particles = 255 */ void cleanupExtraLines(ImageProcessor ip) { byte[] pixels = (byte[])ip.getPixels(); for (int y=0, i=0; y<height; y++) { for (int x=0; x<width; x++,i++) { int v = pixels[i]; if (v!=(byte)255 && v!=0) { int nRadii = nRadii(pixels, x, y); //number of lines radiating if (nRadii==0) //single point or foreground patch? pixels[i] = (byte)255; else if (nRadii==1) removeLineFrom(pixels, x, y); } // if v<255 && v>0 } // for x } // for y } // void cleanupExtraLines