Example #1
0
def rotozoom(surface, angle, size):
    """
    Return Surface rotated and resized by the given angle and size.
    """
    if not angle:
        width = int(surface.getWidth() * size)
        height = int(surface.getHeight() * size)
        return scale(surface, (width, height))
    theta = angle * _deg_rad
    width_i = int(surface.getWidth() * size)
    height_i = int(surface.getHeight() * size)
    cos_theta = _fabs(_cos(theta))
    sin_theta = _fabs(_sin(theta))
    width_f = int(_ceil((width_i * cos_theta) + (height_i * sin_theta)))
    if width_f % 2:
        width_f += 1
    height_f = int(_ceil((width_i * sin_theta) + (height_i * cos_theta)))
    if height_f % 2:
        height_f += 1
    surf = Surface((width_f, height_f), BufferedImage.TYPE_INT_ARGB)
    at = AffineTransform()
    at.translate(width_f / 2.0, height_f / 2.0)
    at.rotate(-theta)
    g2d = surf.createGraphics()
    ot = g2d.getTransform()
    g2d.setTransform(at)
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                         RenderingHints.VALUE_INTERPOLATION_BILINEAR)
    g2d.drawImage(surface, -width_i // 2, -height_i // 2, width_i, height_i,
                  None)
    g2d.setTransform(ot)
    g2d.dispose()
    return surf
Example #2
0
 def rotozoom(self, surface, angle, size):
     """
     Return Surface rotated and resized by the given angle and size.
     """
     if not angle:
         width = int(surface.getWidth()*size)
         height = int(surface.getHeight()*size)
         return self.scale(surface, (width, height))
     theta = angle*self.deg_rad
     width_i = int(surface.getWidth()*size)
     height_i = int(surface.getHeight()*size)
     cos_theta = _fabs( _cos(theta) )
     sin_theta = _fabs( _sin(theta) )
     width_f = int( _ceil((width_i*cos_theta)+(height_i*sin_theta)) )
     if width_f % 2:
         width_f += 1
     height_f = int( _ceil((width_i*sin_theta)+(height_i*cos_theta)) )
     if height_f % 2:
         height_f += 1
     surf = Surface((width_f,height_f), BufferedImage.TYPE_INT_ARGB)
     at = AffineTransform()
     at.translate(width_f/2, height_f/2)
     at.rotate(-theta)
     g2d = surf.createGraphics()
     ot = g2d.getTransform()
     g2d.setTransform(at)
     g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
     g2d.drawImage(surface, -width_i//2, -height_i//2, width_i, height_i, None)
     g2d.setTransform(ot)
     g2d.dispose()
     return surf
Example #3
0
def rotate(surface, angle):
    """
    Return Surface rotated by the given angle.
    """
    if not angle:
        return surface.copy()
    theta = angle * _deg_rad
    width_i = surface.getWidth()
    height_i = surface.getHeight()
    cos_theta = _fabs(_cos(theta))
    sin_theta = _fabs(_sin(theta))
    width_f = int((width_i * cos_theta) + (height_i * sin_theta))
    height_f = int((width_i * sin_theta) + (height_i * cos_theta))
    surf = Surface((width_f, height_f), BufferedImage.TYPE_INT_ARGB)
    at = AffineTransform()
    at.translate(width_f / 2.0, height_f / 2.0)
    at.rotate(-theta)
    g2d = surf.createGraphics()
    ot = g2d.getTransform()
    g2d.setTransform(at)
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                         RenderingHints.VALUE_INTERPOLATION_BILINEAR)
    g2d.drawImage(surface, -width_i // 2, -height_i // 2, None)
    g2d.setTransform(ot)
    g2d.dispose()
    return surf
Example #4
0
 def rotate(self, surface, angle):
     """
     Return Surface rotated by the given angle.
     """
     if not angle:
         return surface.copy()
     theta = angle*self.deg_rad
     width_i = surface.getWidth()
     height_i = surface.getHeight()
     cos_theta = _fabs( _cos(theta) )
     sin_theta = _fabs( _sin(theta) )
     width_f = int( (width_i*cos_theta)+(height_i*sin_theta) )
     height_f = int( (width_i*sin_theta)+(height_i*cos_theta) )
     surf = Surface((width_f,height_f), BufferedImage.TYPE_INT_ARGB)
     at = AffineTransform()
     at.translate(width_f/2, height_f/2)
     at.rotate(-theta)
     g2d = surf.createGraphics()
     ot = g2d.getTransform()
     g2d.setTransform(at)
     g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
     g2d.drawImage(surface, -width_i//2, -height_i//2, None)
     g2d.setTransform(ot)
     g2d.dispose()
     return surf
Example #5
0
def generate_image(width, height):
	renderer = StaticRenderer()
	renderer.setTree(GVTBuilder().build(context, document))
	transform = AffineTransform()
	transform.translate(-svg_x, -svg_y)
	transform.scale(width / svg_width, height / svg_height)
	renderer.setTransform(transform)
	renderer.updateOffScreen(width, height)
	renderer.repaint(Rectangle(0, 0, width, height))
	return renderer.getOffScreen()
def generate_image(width, height):
    renderer = StaticRenderer()
    renderer.setTree(GVTBuilder().build(context, document))
    transform = AffineTransform()
    transform.translate(-svg_x, -svg_y)
    transform.scale(width / svg_width, height / svg_height)
    renderer.setTransform(transform)
    renderer.updateOffScreen(width, height)
    renderer.repaint(Rectangle(0, 0, width, height))
    return renderer.getOffScreen()
Example #7
0
 def showAt(self, mx, my):
     bg.setPaintColor(self.color)
     t = AffineTransform()
     t.translate(mx, -50 + my % 650)  # Restrict to playground
     # Cloning to avoid side effects
     gp1 = self.tri1.clone()
     gp2 = self.tri2.clone()
     gp1.transform(t)
     gp2.transform(t)
     bg.fillGeneralPath(gp1)
     bg.fillGeneralPath(gp2)
Example #8
0
 def _getArea(self):
     h = int((self._get("scale") * self._get("height")))
     w = int((self._get("scale") * self._get("width")))
     p = self._get("position")
     center = self._get("center")
     theta = self._get("rotation")
     #ar = Area(Rectangle2D.Double(-center.x, -center.y, 1, 1))
     ar = self._area(self, center)
     g = AffineTransform()
     g.translate(p.x, p.y)
     g.rotate(theta)
     g.scale(w, h)
     ar.transform(g)
     return ar
Example #9
0
 def _getArea(self):
     h = int((self._get("scale") * self._get("height")))
     w = int((self._get("scale") * self._get("width")))
     p = self._get("position")
     center = self._get("center")
     theta = self._get("rotation")
     #ar = Area(Rectangle2D.Double(-center.x, -center.y, 1, 1))
     ar = self._area(self, center)
     g = AffineTransform()
     g.translate(p.x, p.y)
     g.rotate(theta)
     g.scale(w, h)
     ar.transform(g)
     return ar
def measureCustom(layerset):
    # Obtain a list of all AreaLists:
    alis = layerset.getZDisplayables(AreaList)
    # The loader
    loader = layerset.getProject().getLoader()
    # The ResultsTable
    table = Utils.createResultsTable("AreaLists",
                                     ["id", "layer", "Z", "area", "mean"])
    # The LayerSet's Calibration (units in microns, etc)
    calibration = layerset.getCalibrationCopy()
    # The measurement options as a bit mask:
    moptions = Measurements.AREA | Measurements.MEAN

    for ali in alis:
        affine = ali.getAffineTransformCopy()
        box = ali.getBoundingBox()
        index = 0
        for layer in layerset.getLayers():
            index += 1  # layer index starts at 1, so sum before
            # The java.awt.geom.Area object for the AreaList 'ali'
            # at the given Layer 'layer':
            area = ali.getArea(layer)
            if area:
                # Bring the area to world coordinates,
                # and then local to its own data:
                tr = AffineTransform()
                tr.translate(-box.x, -box.y)
                tr.concatenate(affine)
                area = area.createTransformedArea(tr)
                # Create a snapshot of the images under the area:
                imp = loader.getFlatImage(layer, box, 1, 0xffffffff,
                                          ImagePlus.GRAY8, Patch, False)
                # Set the area as a roi
                imp.setRoi(ShapeRoi(area))
                # Perform measurements (uncalibrated)
                # (To get the calibration, call layerset.getCalibrationCopy())
                stats = ByteStatistics(imp.getProcessor(), moptions,
                                       calibration)
                table.incrementCounter()
                table.addLabel("Name", ali.getTitle())
                table.addValue(0, ali.getId())
                table.addValue(1, index)  # the layer index
                table.addValue(2, layer.getZ())
                table.addValue(3, stats.area)
                table.addValue(4, stats.mean)
        # Update and show the table
        table.show("AreaLists")
Example #11
0
def measureCustom(layerset):
  # Obtain a list of all AreaLists:
  alis = layerset.getZDisplayables(AreaList)
  # The loader
  loader = layerset.getProject().getLoader()
  # The ResultsTable
  table = Utils.createResultsTable("AreaLists", ["id", "layer", "Z", "area", "mean"])
  # The LayerSet's Calibration (units in microns, etc)
  calibration = layerset.getCalibrationCopy()
  # The measurement options as a bit mask:
  moptions = Measurements.AREA | Measurements.MEAN
  
  for ali in alis:
    affine = ali.getAffineTransformCopy()
    box = ali.getBoundingBox()
    index = 0
    for layer in layerset.getLayers():
      index += 1 # layer index starts at 1, so sum before
      # The java.awt.geom.Area object for the AreaList 'ali'
      # at the given Layer 'layer':
      area = ali.getArea(layer)
      if area:
        # Bring the area to world coordinates,
        # and then local to its own data:
        tr = AffineTransform()
        tr.translate(-box.x, -box.y)
        tr.concatenate(affine)
        area = area.createTransformedArea(tr)
        # Create a snapshot of the images under the area:
        imp = loader.getFlatImage(layer, box, 1, 0xffffffff,
              ImagePlus.GRAY8, Patch, False)
        # Set the area as a roi
        imp.setRoi(ShapeRoi(area))
        # Perform measurements (uncalibrated)
	# (To get the calibration, call layerset.getCalibrationCopy())
        stats = ByteStatistics(imp.getProcessor(), moptions, calibration)
	table.incrementCounter()
	table.addLabel("Name", ali.getTitle())
	table.addValue(0, ali.getId())
	table.addValue(1, index) # the layer index
	table.addValue(2, layer.getZ()) 
	table.addValue(3, stats.area)
	table.addValue(4, stats.mean)
    # Update and show the table
    table.show("AreaLists")
Example #12
0
def draw(g, size=(500, 500)):
    """
  Draws a geometry onto a canvas.

  *size* is a tuple that specifies the dimensions of the canvas the geometry will drawn upon. 
  """
    buf = 50.0

    if not isinstance(g, list):
        g = [g]

    e = _fac.createGeometryCollection(g).getEnvelopeInternal()
    scale = size[0] / e.width if e.width > 0 else sys.maxint
    scale = min(scale, size[1] / e.height) if e.height > 0 else 1

    tx = -1 * e.minX
    ty = -1 * e.minY

    at = AffineTransform()

    # scale to size of canvas (inverting the y axis)
    at.scale(scale, -1 * scale)

    # translate to the origin
    at.translate(tx, ty)

    # translate to account for invert
    at.translate(0, -1 * size[1] / scale)

    # buffer
    at.translate(buf / scale, -1 * buf / scale)

    class Panel(swing.JPanel):
        def __init__(self, geoms, atx):
            self.geoms = geoms
            self.atx = atx

        def paintComponent(self, gc):
            opaque = gc.getComposite()
            gc.setRenderingHint(awt.RenderingHints.KEY_ANTIALIASING,
                                awt.RenderingHints.VALUE_ANTIALIAS_ON)
            gc.setStroke(awt.BasicStroke(2))

            i = 0
            for g in self.geoms:
                shp = LiteShape(g, self.atx, False)

                if isinstance(g, (Polygon, MultiPolygon)):
                    i = i + 1
                    gc.setColor(awt.Color.WHITE)
                    gc.setComposite(
                        awt.AlphaComposite.getInstance(
                            awt.AlphaComposite.SRC_OVER, 0.5))
                    gc.fill(shp)

                gc.setComposite(opaque)
                gc.setColor(awt.Color.BLACK)
                gc.draw(shp)

    panel = Panel(g, at)
    s = tuple([int(size[x] + 2 * buf) for x in range(2)])
    panel.preferredSize = s
    frame = swing.JFrame()
    frame.contentPane = panel
    frame.pack()
    frame.visible = True
Example #13
0
def draw(g, size=(500,500)):
  """
  Draws a geometry onto a canvas.

  *size* is a tuple that specifies the dimensions of the canvas the geometry will drawn upon. 
  """
  buf = 50.0

  if not isinstance(g, list):
    g = [g]

  e = _fac.createGeometryCollection(g).getEnvelopeInternal()
  scale = size[0] / e.width if e.width > 0 else sys.maxint
  scale = min(scale, size[1] / e.height) if e.height > 0 else 1 

  tx = -1*e.minX
  ty = -1*e.minY
       
  at = AffineTransform()
  
  # scale to size of canvas (inverting the y axis)
  at.scale(scale,-1*scale)
  
  # translate to the origin
  at.translate(tx,ty)

  # translate to account for invert
  at.translate(0,-1*size[1]/scale)

  # buffer
  at.translate(buf/scale,-1*buf/scale)
        
  class Panel(swing.JPanel):

    def __init__(self, geoms, atx):
      self.geoms = geoms
      self.atx = atx

    def paintComponent(self, gc):
      opaque = gc.getComposite()      
      gc.setRenderingHint(awt.RenderingHints.KEY_ANTIALIASING, 
        awt.RenderingHints.VALUE_ANTIALIAS_ON)
      gc.setStroke(awt.BasicStroke(2))

      i = 0
      for g in self.geoms:
        shp = LiteShape(g, self.atx, False)

        if isinstance(g, (Polygon, MultiPolygon)):
          i = i + 1
          gc.setColor(awt.Color.WHITE)
          gc.setComposite(awt.AlphaComposite.getInstance(awt.AlphaComposite.SRC_OVER, 0.5))
          gc.fill(shp)

        gc.setComposite(opaque)
        gc.setColor(awt.Color.BLACK)
        gc.draw(shp)

  panel = Panel(g, at)
  s = tuple([int(size[x]+2*buf) for x in range(2)])
  panel.preferredSize = s
  frame = swing.JFrame()
  frame.contentPane = panel
  frame.pack()
  frame.visible = True