4 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2014, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
33 import java.awt.image.*;
34 import java.awt.geom.AffineTransform;
36 public class RegimViewer extends JPanel
38 private PnmImage refpnm;
41 private Image jpipImg;
42 private double[] affine_matrix;
43 private AffineTransform affine;
45 public RegimViewer( String refname, double[] mat)
47 refpnm = new PnmImage( refname.replaceFirst("jp2", "pgm")); // decoding not realized
48 affine_matrix = new double[6];
50 affine_matrix[0] = mat[0];
51 affine_matrix[1] = mat[3];
52 affine_matrix[2] = mat[1];
53 affine_matrix[3] = mat[4];
54 affine_matrix[4] = mat[2];
55 affine_matrix[5] = mat[5];
57 affine = new AffineTransform();
59 for( int i=0; i<3; i++){
60 for( int j=0; j<3; j++)
61 System.out.print( mat[i*3+j] + " ");
66 public void projection( Image jpipimg, double scale)
69 refimg = refpnm.createScaleImage( scale);
70 vw = refimg.getWidth(this);
71 vh = refimg.getHeight(this);
72 this.setSize( vw, vh);
74 affine.setTransform( affine_matrix[0], affine_matrix[1], affine_matrix[2], affine_matrix[3], affine_matrix[4], affine_matrix[5]);
78 public void paint(Graphics g)
81 BufferedImage bi, bi2;
83 Graphics2D g2 = (Graphics2D) g;
85 g2.clearRect(0, 0, vw, vh);
87 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
88 RenderingHints.VALUE_ANTIALIAS_ON);
89 g2.setRenderingHint(RenderingHints.KEY_RENDERING,
90 RenderingHints.VALUE_RENDER_QUALITY);
92 iw = refimg.getWidth(this);
93 ih = refimg.getHeight(this);
95 bi = new BufferedImage( iw, ih, BufferedImage.TYPE_INT_RGB);
96 big = bi.createGraphics();
97 big.drawImage(refimg, 0, 0, this);
99 g2.drawImage(bi, 0, 0, this);
101 bi2 = new BufferedImage( jpipImg.getWidth(this), jpipImg.getHeight(this), BufferedImage.TYPE_INT_RGB);
102 big2 = bi2.createGraphics();
103 big2.drawImage( jpipImg, 0, 0, this);
105 g2.setTransform(affine);
107 g2.drawImage(bi2, 0, 0, this);
110 public Dimension get_imsize()
112 return (new Dimension( vw, vh));