private void check(final Image real, final Image imag, final Axes axes) { messenger.log("Real input image of type " + real.type()); messenger.log("Imaginary input image of type " + imag.type()); final Dimensions rdims = real.dimensions(); final Dimensions idims = imag.dimensions(); if (!rdims.equals(idims)) throw new IllegalStateException("Real and imaginary images have different dimensions"); if (axes.x && !FMath.power2(rdims.x)) throw new IllegalStateException("Real and imaginary x-size not a power of 2"); if (axes.y && !FMath.power2(rdims.y)) throw new IllegalStateException("Real and imaginary y-size not a power of 2"); if (axes.z && !FMath.power2(rdims.z)) throw new IllegalStateException("Real and imaginary z-size not a power of 2"); if (axes.t && !FMath.power2(rdims.t)) throw new IllegalStateException("Real and imaginary t-size not a power of 2"); if (axes.c && !FMath.power2(rdims.c)) throw new IllegalStateException("Real and imaginary c-size not a power of 2"); }
public Image bitmap(final boolean binary) { // Initialize bitmap: final Bounds bounds = bounds(); final int minx = FMath.floor(bounds.lower.x); final int miny = FMath.floor(bounds.lower.y); final int xdim = 1 + FMath.floor(bounds.upper.x) - minx; final int ydim = 1 + FMath.floor(bounds.upper.y) - miny; final ByteImage bitmap = new ByteImage(new Dimensions(xdim, ydim)); if (major > 0 && minor > 0) { // Fill interior elements: final double sina = Math.sin(angle); final double cosa = Math.cos(angle); final double major2 = major * major; final double minor2 = minor * minor; final double xc = x - minx - 0.5; final double yc = y - miny - 0.5; final Coordinates c = new Coordinates(); final double[] row = new double[xdim]; bitmap.axes(Axes.X); for (int j = 0; j < ydim; ++j, ++c.y) { final double dy = j - yc; final double sinady = sina * dy; final double cosady = cosa * dy; for (int i = 0; i < xdim; ++i) { final double dx = i - xc; final double dxr = cosa * dx + sinady; final double dyr = cosady - sina * dx; if (dxr * dxr / major2 + dyr * dyr / minor2 <= 1) row[i] = 255; else row[i] = 0; } bitmap.set(c, row); } // Fill contour elements: if (!binary) { final int contoursteps = FMath.ceil(CONTOUR_RESOLUTION * perimeter()); final double contouranglestep = 2 * Math.PI / contoursteps; final double[] samplesites = new double[CONTOUR_RESOLUTION]; for (int i = 0; i < CONTOUR_RESOLUTION; ++i) samplesites[i] = (i + 1.0) / (CONTOUR_RESOLUTION + 1.0); final double samplesites2 = CONTOUR_RESOLUTION * CONTOUR_RESOLUTION; final Coordinates pc = new Coordinates(Integer.MIN_VALUE, Integer.MIN_VALUE); final Coordinates cc = new Coordinates(); final Coordinates bc = new Coordinates(); for (int i = 0; i < contoursteps; ++i) { final double contourangle = contouranglestep * i; final double cx = major * Math.cos(contourangle); final double cy = minor * Math.sin(contourangle); cc.x = FMath.floor(x + cosa * cx - sina * cy); cc.y = FMath.floor(y + sina * cx + cosa * cy); if (cc.x != pc.x || cc.y != pc.y) { int hits = 0; for (int yi = 0; yi < CONTOUR_RESOLUTION; ++yi) { final double dy = cc.y + samplesites[yi] - y; for (int xi = 0; xi < CONTOUR_RESOLUTION; ++xi) { final double dx = cc.x + samplesites[xi] - x; final double dxr = cosa * dx + sina * dy; final double dyr = cosa * dy - sina * dx; if (dxr * dxr / major2 + dyr * dyr / minor2 <= 1) ++hits; } } bc.x = cc.x - minx; bc.y = cc.y - miny; bitmap.set(bc, 255 * hits / samplesites2); pc.x = cc.x; pc.y = cc.y; } } } } return bitmap; }