コード例 #1
0
 public static PointCloud rasterToPointCloud(Raster r, int dimx, int dimy, int dim) {
   PointCloud res = null;
   for (int j = 0; j < dimy; j++)
     for (int i = 0; i < dimx; i++) {
       int[] pix = new int[3];
       r.getPixel(i, j, pix);
       //      		System.out.println("pix = [" + pix[0] + " " + pix[1] + " "
       //     				   + pix[2] + "]");
       // convert pixel to L*u*v*
       float[] pixluv = new float[3];
       ImageManipulation.rgb2luv(pix[0], pix[1], pix[2], pixluv);
       double[] coord;
       if (dim == 3) {
         coord = new double[3];
         coord[0] = pixluv[0];
         coord[1] = pixluv[1];
         coord[2] = pixluv[2];
       } else if (dim == 5) {
         coord = new double[5];
         coord[0] = (double) i;
         coord[1] = (double) j;
         coord[2] = pixluv[0];
         coord[3] = pixluv[1];
         coord[4] = pixluv[2];
       } else throw new RuntimeException("Bad dimension!");
       res = new PointCloud(new Point_D(coord), res, true);
     }
   return res;
 }
コード例 #2
0
 static void assignColors(int n, Point_D[] clusterCenters, Color[] cols) {
   // In this version, assign the center's color to each cluster
   for (int i = 0; i < n && clusterCenters[i] != null; i++) {
     int dim = clusterCenters[i].dimension();
     float[] pixluv = {
       (float) clusterCenters[i].getCartesian(dim - 3).doubleValue(),
       (float) clusterCenters[i].getCartesian(dim - 2).doubleValue(),
       (float) clusterCenters[i].getCartesian(dim - 1).doubleValue()
     };
     int[] pix = ImageManipulation.luv2rgb(pixluv[0], pixluv[1], pixluv[2]);
     cols[i] = new Color(pix[0], pix[1], pix[2]);
   }
 }
コード例 #3
0
  public static void testLoadingImage(String[] args) {
    System.out.println("Loading image data: ex 0");
    if (args.length < 1) {
      System.out.println("Usage: java ImageManipulation image");
      System.exit(0);
    }
    // load input image
    BufferedImage bimg = ImageManipulation.loadImage(args[0]);
    int dimx = bimg.getWidth();
    int dimy = bimg.getHeight();
    // get array of pixels from image, in L*u*v* space
    WritableRaster raster = bimg.getRaster();
    System.out.println("Pixels array created from image");

    // build point cloud from raster
    int dim = 3;
    PointCloud N = ImageManipulation.rasterToPointCloud(raster, dimx, dimy, dim);

    // draw input image and corresponding point cloud
    System.out.println("dim = " + dim + ", size = " + PointCloud.size(N));
    Draw.draw3D(N);
    Fenetre fInput = new Fenetre(bimg, "input image");
  }