/** * @return The short side length of the minimum enclosing rectangle */ public double getShortSideMBR(){ Point[] mbr = getMinimumBoundingRectangle(); if(mbr == null){ return Double.NaN; } double firstSide = Math.sqrt(Math.pow(cal.getX(mbr[1].x) -cal.getX(mbr[0].x),2)+Math.pow(cal.getY(mbr[1].y) - cal.getY(mbr[0].y),2)); double secondSide = Math.sqrt(Math.pow(cal.getX(mbr[1].x) -cal.getX(mbr[2].x),2)+Math.pow(cal.getY(mbr[1].y) -cal.getY(mbr[2].y),2)); return firstSide<secondSide?firstSide:secondSide; }
/** * @return The long side length of the minimum enclosing rectangle */ public double getLongSideMBR(){ Point[] mbr = getMinimumBoundingRectangle(); if(mbr == null){ return Double.NaN; } double firstSide = Math.sqrt(Math.pow(cal.getX(mbr[1].x) -cal.getX(mbr[0].x),2)+Math.pow(cal.getY(mbr[1].y) - cal.getY(mbr[0].y),2)); double secondSide = Math.sqrt(Math.pow(cal.getX(mbr[1].x) -cal.getX(mbr[2].x),2)+Math.pow(cal.getY(mbr[1].y) -cal.getY(mbr[2].y),2)); return firstSide>secondSide?firstSide:secondSide; }
public static void scale(final Set<UPoint> set, final Calibration cal) { for (final Iterator<UPoint> it = set.iterator(); it.hasNext();) { final UPoint point = it.next(); point.x = cal.getX(point.x); point.y = cal.getY(point.y); point.z = cal.getZ(point.z); } }
public UPoint(final int x, final int y, final int z, final Calibration cal) { this.x = cal.getX(x); this.y = cal.getY(y); this.z = cal.getZ(z); }
public UPoint(final int x, final int y, final Calibration cal) { this.x = cal.getX(x); this.y = cal.getY(y); this.z = cal.getZ(0); }
@Override public void mouseMoved(final int x, final int y) { final Calibration cal = getCalibration(); final StringBuilder sb = new StringBuilder(64).append("x=").append(doubleToString(cal.getX(x))).append(' ').append(cal.getUnit()) .append(", y=").append(doubleToString(cal.getY(y))).append(' ').append(cal.getUnit()); if (ProjectToolbar.getToolId() <= ProjectToolbar.SELECT) { sb.append(", value="); final int[] v = getPixel(x, y); switch (type) { case ImagePlus.GRAY8: case ImagePlus.GRAY16: sb.append(v[0]); break; case ImagePlus.COLOR_256: case ImagePlus.COLOR_RGB: sb.append(v[0]).append(',').append(v[1]).append(',').append(v[2]); break; case ImagePlus.GRAY32: sb.append(Float.intBitsToFloat(v[0])); break; default: sb.setLength(sb.length() -8); // no value info break; } } // Utils.showStatus would be too slow at reporting, because it waits for fast subsequent calls. IJ.showStatus(sb.toString()); }
void getCentroid(ImageProcessor ip) { byte[] mask = ip.getMaskArray(); int count=0, mi; double xsum=0.0, ysum=0.0; for (int y=ry,my=0; y<(ry+rh); y++,my++) { mi = my*rw; for (int x=rx; x<(rx+rw); x++) { if (mask==null||mask[mi++]!=0) { count++; xsum += x; ysum += y; } } } xCentroid = xsum/count+0.5; yCentroid = ysum/count+0.5; if (cal!=null) { xCentroid = cal.getX(xCentroid); yCentroid = cal.getY(yCentroid, height); } }
void getCentroid(ImageProcessor ip) { byte[] mask = ip.getMaskArray(); int count=0, mi; double xsum=0.0, ysum=0.0; for (int y=ry,my=0; y<(ry+rh); y++,my++) { mi = my*rw; for (int x=rx; x<(rx+rw); x++) { if (mask==null||mask[mi++]!=0) { count++; xsum += x; ysum += y; } } } xCentroid = xsum/count+0.5; yCentroid = ysum/count+0.5; if (cal!=null) { xCentroid = cal.getX(xCentroid); yCentroid = cal.getY(yCentroid, height); } }
/** * Region-Based Moments Definition of "Gorman et. al. Practical Algorithms for Image Analysis" (p. 157). * (computational expensive!) * @return Region-Based Moments of order (p + q) * @param q (order = (p + q)) * @param p (order = (p + q)) */ public double getMoment(int p, int q) { if(p<=2 && q<=2){ if(momentsLUT[p][q]!=-1){ return momentsLUT[p][q]; } } double moment = 0; Rectangle bounds = outerContour.getBounds(); for(int x = bounds.x; x < bounds.x+bounds.width+1;x++){ for(int y = bounds.y; y < bounds.y+bounds.height+1;y++){ if(outerContour.contains((double)x,(double)y)){ moment += Math.pow(cal.getX(x), p) * Math.pow(cal.getY(y), q); } } } momentsLUT[p][q] = moment; return moment; }
if (cal!=null) { xCenterOfMass = cal.getX(xCenterOfMass); yCenterOfMass = cal.getY(yCenterOfMass, height);
void getCentroid(ImageProcessor ip, double minThreshold, double maxThreshold) { float[] pixels = (float[])ip.getPixels(); byte[] mask = ip.getMaskArray(); double count=0.0, xsum=0.0, ysum=0.0, v; int i, mi; for (int y=ry,my=0; y<(ry+rh); y++,my++) { i = y*width + rx; mi = my*rw; for (int x=rx; x<(rx+rw); x++) { if (mask==null||mask[mi++]!=0) { v = pixels[i]; if (v>=minThreshold && v<=maxThreshold) { count++; xsum+=x; ysum+=y; } } i++; } } xCentroid = xsum/count+0.5; yCentroid = ysum/count+0.5; if (cal!=null) { xCentroid = cal.getX(xCentroid); yCentroid = cal.getY(yCentroid, height); } }
void getCentroid(ImageProcessor ip, double minThreshold, double maxThreshold) { float[] pixels = (float[])ip.getPixels(); byte[] mask = ip.getMaskArray(); double count=0.0, xsum=0.0, ysum=0.0, v; int i, mi; for (int y=ry,my=0; y<(ry+rh); y++,my++) { i = y*width + rx; mi = my*rw; for (int x=rx; x<(rx+rw); x++) { if (mask==null||mask[mi++]!=0) { v = pixels[i]; if (v>=minThreshold && v<=maxThreshold) { count++; xsum+=x; ysum+=y; } } i++; } } xCentroid = xsum/count+0.5; yCentroid = ysum/count+0.5; if (cal!=null) { xCentroid = cal.getX(xCentroid); yCentroid = cal.getY(yCentroid, height); } }
if (cal!=null) { xCentroid = cal.getX(xCentroid); yCentroid = cal.getY(yCentroid, height);
if (cal!=null) { xCentroid = cal.getX(xCentroid); yCentroid = cal.getY(yCentroid, height);
roiY = cal!=null?cal.getY(ry, height):ry; roiWidth = rw*pw; roiHeight = rh*ph;
roiY = cal!=null?cal.getY(ry, height):ry; roiWidth = rw*pw; roiHeight = rh*ph;
public void mouseMoved(MouseEvent e) { int x = cc.offScreenX(e.getX()); int y = cc.offScreenY(e.getY()); double posX, posY, posZ; int voxelValue; int materialID; String materialName; if(x<imp.getWidth() && y<imp.getHeight()) { Calibration cal = imp.getCalibration(); posX = cal.getX(x); posX = Double.valueOf(IJ.d2s(posX)).doubleValue(); posY = cal.getY(y); posY = Double.valueOf(IJ.d2s(posY)).doubleValue(); int z = imp.getCurrentSlice()-1; posZ = cal.getZ(z); posZ = Double.valueOf(IJ.d2s(posZ)).doubleValue(); voxelValue = imp.getProcessor().get(x, y); materialID = cc.getLabels().getStack().getProcessor(z+1).get(x,y); materialName = sidebar.getMaterials() .params.getMaterialName(materialID); IJ.showStatus("x=" + posX + ", y=" + posY + ", z=" + posZ + ", value=" + voxelValue + ", material=" + materialName); } }
/** Converts the current cursor location to a string. */ public String getLocationAsString(int x, int y) { Calibration cal = getCalibration(); if (getProperty("FHT")!=null) return getFFTLocation(x, height-y, cal); String xx="", yy=""; if (cal.scaled()) { xx = " ("+x+")"; yy = " ("+y+")"; } String s = " x="+d2s(cal.getX(x)) + xx + ", y=" + d2s(cal.getY(y,height)) + yy; if (getStackSize()>1) { Roi roi2 = getRoi(); if (roi2==null || roi2.getState()==Roi.NORMAL) { int z = isDisplayedHyperStack()?getSlice()-1:getCurrentSlice()-1; String zz = cal.scaled()&&cal.getZ(z)!=z?" ("+z+")":""; s += ", z="+d2s(cal.getZ(z))+zz; } } return s; }
/** Converts the current cursor location to a string. */ public String getLocationAsString(int x, int y) { Calibration cal = getCalibration(); if (getProperty("FHT")!=null) return getFFTLocation(x, height-y, cal); String xx="", yy=""; if (cal.scaled()) { xx = " ("+x+")"; yy = " ("+y+")"; } String s = " x="+d2s(cal.getX(x)) + xx + ", y=" + d2s(cal.getY(y,height)) + yy; if (getStackSize()>1) { Roi roi2 = getRoi(); if (roi2==null || roi2.getState()==Roi.NORMAL) { int z = isDisplayedHyperStack()?getSlice()-1:getCurrentSlice()-1; String zz = cal.scaled()&&cal.getZ(z)!=z?" ("+z+")":""; s += ", z="+d2s(cal.getZ(z))+zz; } } return s; }