final public void compose( final int[] src, final int[] dst, final float alpha ) { dst[ 0 ] = Math.max( 0, Util.round( dst[ 0 ] - src[ 0 ] * alpha ) ); dst[ 1 ] = Math.max( 0, Util.round( dst[ 1 ] - src[ 0 ] * alpha ) ); dst[ 2 ] = Math.max( 0, Util.round( dst[ 2 ] - src[ 0 ] * alpha ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { final float srcAlpha = src[ 3 ] / 255.0f * alpha; dst[ 0 ] = Math.min( 255, Util.round( src[ 0 ] * srcAlpha + dst[ 0 ] ) ); dst[ 1 ] = Math.min( 255, Util.round( src[ 1 ] * srcAlpha + dst[ 1 ] ) ); dst[ 2 ] = Math.min( 255, Util.round( src[ 2 ] * srcAlpha + dst[ 2 ] ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { dst[ 0 ] = Math.min( 255, Util.round( src[ 0 ] * alpha + dst[ 0 ] ) ); dst[ 1 ] = Math.min( 255, Util.round( src[ 0 ] * alpha + dst[ 1 ] ) ); dst[ 2 ] = Math.min( 255, Util.round( src[ 0 ] * alpha + dst[ 2 ] ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { final float srcAlpha = src[ 3 ] / 255.0f * alpha; dst[ 0 ] = Math.max( 0, Util.round( dst[ 0 ] - src[ 0 ] * srcAlpha ) ); dst[ 1 ] = Math.max( 0, Util.round( dst[ 1 ] - src[ 1 ] * srcAlpha ) ); dst[ 2 ] = Math.max( 0, Util.round( dst[ 2 ] - src[ 2 ] * srcAlpha ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { dst[ 0 ] = Math.min( 255, Util.round( src[ 0 ] * alpha + dst[ 0 ] ) ); dst[ 1 ] = Math.min( 255, Util.round( src[ 1 ] * alpha + dst[ 1 ] ) ); dst[ 2 ] = Math.min( 255, Util.round( src[ 2 ] * alpha + dst[ 2 ] ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { dst[ 0 ] = Math.max( 0, Util.round( dst[ 0 ] - src[ 0 ] * alpha ) ); dst[ 1 ] = Math.max( 0, Util.round( dst[ 1 ] - src[ 1 ] * alpha ) ); dst[ 2 ] = Math.max( 0, Util.round( dst[ 2 ] - src[ 2 ] * alpha ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { final float dstAlpha = 1.0f - alpha; final float l = 0.299f * dst[ 0 ] + 0.587f * dst[ 1 ] + 0.114f * dst[ 2 ]; dst[ 0 ] = Math.max( 0, Math.min( 255, Util.round( l * alpha + dst[ 0 ] * dstAlpha ) ) ); dst[ 1 ] = Math.max( 0, Math.min( 255, Util.round( l * alpha + dst[ 1 ] * dstAlpha ) ) ); dst[ 2 ] = Math.max( 0, Math.min( 255, Util.round( l * alpha + dst[ 2 ] * dstAlpha ) ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { final float dstAlpha = 1.0f - alpha; dst[ 0 ] = Math.max( 0, Math.min( 255, Util.round( ( alpha * src[ 0 ] * dst[ 0 ] ) / 255.0f + dst[ 0 ] * dstAlpha ) ) ); dst[ 1 ] = Math.max( 0, Math.min( 255, Util.round( ( alpha * src[ 1 ] * dst[ 1 ] ) / 255.0f + dst[ 1 ] * dstAlpha ) ) ); dst[ 2 ] = Math.max( 0, Math.min( 255, Util.round( ( alpha * src[ 2 ] * dst[ 2 ] ) / 255.0f + dst[ 2 ] * dstAlpha ) ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { final float srcAlpha = src[ 3 ] / 255.0f * alpha; final float dstAlpha = 1.0f - srcAlpha; dst[ 0 ] = Math.max( 0, Math.min( 255, Util.round( ( srcAlpha * src[ 0 ] * dst[ 0 ] ) / 255.0f + dst[ 0 ] * dstAlpha ) ) ); dst[ 1 ] = Math.max( 0, Math.min( 255, Util.round( ( srcAlpha * src[ 1 ] * dst[ 1 ] ) / 255.0f + dst[ 1 ] * dstAlpha ) ) ); dst[ 2 ] = Math.max( 0, Math.min( 255, Util.round( ( srcAlpha * src[ 2 ] * dst[ 2 ] ) / 255.0f + dst[ 2 ] * dstAlpha ) ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { final float dstAlpha = 1.0f - alpha; dst[ 0 ] = Math.max( 0, Math.min( 255, Util.round( ( alpha * src[ 0 ] * dst[ 0 ] ) / 255.0f + dst[ 0 ] * dstAlpha ) ) ); dst[ 1 ] = Math.max( 0, Math.min( 255, Util.round( ( alpha * src[ 0 ] * dst[ 1 ] ) / 255.0f + dst[ 1 ] * dstAlpha ) ) ); dst[ 2 ] = Math.max( 0, Math.min( 255, Util.round( ( alpha * src[ 0 ] * dst[ 2 ] ) / 255.0f + dst[ 2 ] * dstAlpha ) ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { dst[ 0 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 0 ] - src[ 0 ] * alpha ) ) ) ); dst[ 1 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 1 ] - src[ 0 ] * alpha ) ) ) ); dst[ 2 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 2 ] - src[ 0 ] * alpha ) ) ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { final float srcAlpha = src[ 3 ] / 255.0f * alpha; dst[ 0 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 0 ] - src[ 0 ] * srcAlpha ) ) ) ); dst[ 1 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 1 ] - src[ 1 ] * srcAlpha ) ) ) ); dst[ 2 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 2 ] - src[ 2 ] * srcAlpha ) ) ) ); dst[ 3 ] = 255; } }
final public void compose( final int[] src, final int[] dst, final float alpha ) { dst[ 0 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 0 ] - src[ 0 ] * alpha ) ) ) ); dst[ 1 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 1 ] - src[ 1 ] * alpha ) ) ) ); dst[ 2 ] = Math.max( 0, Math.min( 255, Util.round( Math.abs( dst[ 2 ] - src[ 2 ] * alpha ) ) ) ); dst[ 3 ] = 255; } }
/** * Paint all {@link Spring}s into a {@link ColorProcessor}. */ public void illustrateSprings( final ColorProcessor ip, final double scale, final double maxStretch ) { for ( final Vertex vertex : vertices ) { final double[] v1 = vertex.getW(); for ( final Vertex v : vertex.getConnectedVertices() ) { final Spring spring = vertex.getSpring( v ); //final double stretch = mpicbg.util.Util.pow( Math.min( 1.0f, Math.abs( Point.distance( vertex, v ) - spring.getLength() ) / maxStretch ), 2 ); final double stretch = Math.min( 1.0, Math.abs( Point.distance( vertex, v ) - spring.getLength() ) / maxStretch ); final double r = Math.min( 1, stretch * 2 ); final double g = Math.min( 1, 2 - stretch * 2 ); ip.setColor( new Color( ( float )r, ( float )g, 0 ) ); final double[] v2 = v.getW(); ip.drawLine( mpicbg.util.Util.round( scale * v1[ 0 ] ), mpicbg.util.Util.round( scale * v1[ 1 ] ), mpicbg.util.Util.round( scale * v2[ 0 ] ), mpicbg.util.Util.round( scale * v2[ 1 ] ) ); } } }
final static public void drawWorldPointMatchLines( final ImageProcessor ip, final Collection< ? extends PointMatch > pointMatches, final Color color, final int width, final Rectangle srcRect, final Rectangle dstRect, final double srcMagnification, final double dstMagnification ) { final int oldLineWidth = ip.getLineWidth(); ip.setColor( color ); ip.setLineWidth( width ); for ( final PointMatch pm : pointMatches ) { final double[] w1 = pm.getP1().getW(); final double x1 = ( w1[ 0 ] + srcRect.x ) * srcMagnification; final double y1 = ( w1[ 1 ] + srcRect.y ) * srcMagnification; final double[] w2 = pm.getP2().getW(); final double x2 = ( w2[ 0 ] + dstRect.x ) * dstMagnification; final double y2 = ( w2[ 1 ] + dstRect.y ) * dstMagnification; ip.drawLine( Util.round( x1 ), Util.round( y1 ), Util.round( x2 ), Util.round( y2 ) ); } ip.setLineWidth( oldLineWidth ); }
final static public ColorProcessor paintSprings( final Collection< SpringMesh > meshes, final double scale, final double maxStretch ) { final int width = mpicbg.util.Util.round( meshes.iterator().next().getWidth() * scale ); final int height = mpicbg.util.Util.round( meshes.iterator().next().getHeight() * scale ); final ColorProcessor ip = new ColorProcessor( width, height ); /* estimate maximal spring stretch */ double maxSpringStretch = 0; for ( final SpringMesh m : meshes ) for ( final Vertex vertex : m.getVertices() ) { for ( final Vertex v : vertex.getConnectedVertices() ) { final Spring spring = vertex.getSpring( v ); final double stretch = Math.abs( Point.distance( vertex, v ) - spring.getLength() ); if ( stretch > maxSpringStretch ) maxSpringStretch = stretch; } } for ( final SpringMesh m : meshes ) m.illustrateSprings( ip, scale, maxSpringStretch ); return ip; } /* </visualization> */
final static public void drawWorldPoints( final ImageProcessor ip, final Collection< ? extends Point > points, final Color color, final int width, final Rectangle srcRect, final double magnification ) { final int oldLineWidth = ip.getLineWidth(); ip.setColor( color ); ip.setLineWidth( width ); for ( final Point p : points ) { final double[] w = p.getW(); final double x = ( w[ 0 ] + srcRect.x ) * magnification; final double y = ( w[ 1 ] + srcRect.y ) * magnification; ip.drawDot( Util.round( x ), Util.round( y ) ); } ip.setLineWidth( oldLineWidth ); }
final static public void drawLocalPoints( final ImageProcessor ip, final Collection< ? extends Point > points, final Color color, final int width, final Rectangle srcRect, final double magnification ) { final int oldLineWidth = ip.getLineWidth(); ip.setColor( color ); ip.setLineWidth( width ); for ( final Point p : points ) { final double[] l = p.getL(); final double x = ( l[ 0 ] + srcRect.x ) * magnification; final double y = ( l[ 1 ] + srcRect.y ) * magnification; ip.drawDot( Util.round( x ), Util.round( y ) ); } ip.setLineWidth( oldLineWidth ); }
final static public void drawLocalPoints( final ImageProcessor ip, final Collection< ? extends Point > points, final Color color, final int width, final Rectangle srcRect, final double magnification ) { final int oldLineWidth = ip.getLineWidth(); ip.setColor( color ); ip.setLineWidth( width ); for ( final Point p : points ) { final double[] l = p.getL(); final double x = ( l[ 0 ] + srcRect.x ) * magnification; final double y = ( l[ 1 ] + srcRect.y ) * magnification; ip.drawDot( Util.round( x ), Util.round( y ) ); } ip.setLineWidth( oldLineWidth ); }
final static public void drawWorldPoints( final ImageProcessor ip, final Collection< ? extends Point > points, final Color color, final int width, final Rectangle srcRect, final double magnification ) { final int oldLineWidth = ip.getLineWidth(); ip.setColor( color ); ip.setLineWidth( width ); for ( final Point p : points ) { final double[] w = p.getW(); final double x = ( w[ 0 ] + srcRect.x ) * magnification; final double y = ( w[ 1 ] + srcRect.y ) * magnification; ip.drawDot( Util.round( x ), Util.round( y ) ); } ip.setLineWidth( oldLineWidth ); }