コード例 #1
0
 private float d(Image i1, Image i2) {
   double d = 0;
   for (int i = 0; i < i1.getDataShort().length; i++) {
     d +=
         (i1.getDataShort()[i] - i2.getDataShort()[i])
             * (i1.getDataShort()[i] - i2.getDataShort()[i]);
   }
   return (float) Math.sqrt(d);
 }
コード例 #2
0
 public void constructNormalizedImageClusters() {
   clusterImages.clear();
   for (int i = 0; i < noClusters; i++) {
     Image image = new ImageFloat(dimFilterX, dimFilterY);
     System.arraycopy(
         memClusters.getSrc(),
         i * dimFilterX * dimFilterY,
         image.getDataFloat(),
         0,
         dimFilterX * dimFilterY);
     clusterImages.add(image);
   }
 }
コード例 #3
0
 private void constructImageClusters() {
   for (int i = 0; i < noClusters; i++) {
     Image image = new ImageFloat(dimFilterX, dimFilterY);
     double max = -1 * Double.MAX_VALUE;
     double min = Double.MAX_VALUE;
     int clusterOffset = dimFilterX * dimFilterY * i;
     for (int j = 0; j < dimFilterX * dimFilterY; j++) {
       if (clustersCenters[clusterOffset + j] > max) max = clustersCenters[clusterOffset + j];
       if (clustersCenters[clusterOffset + j] < min) min = clustersCenters[clusterOffset + j];
     }
     max = 255 / (max - min);
     for (int j = 0; j < dimFilterX * dimFilterY; j++) {
       image.getDataFloat()[j] = (float) ((clustersCenters[clusterOffset + j] - min) * max);
     }
     clusterImages.add(image);
   }
 }
コード例 #4
0
 private void randomizeClustersFromData() {
   List<Image> filters = new ArrayList<>();
   int dimImage = (int) Math.sqrt(imageSize);
   while (filters.size() < noClusters) {
     Image initCluster = images.get((int) (Math.random() * images.size()));
     int x = strideX * ((int) (getInitOffset() * ((dimImage - dimFilterX) / strideX)));
     int y = strideY * ((int) (getInitOffset() * ((dimImage - dimFilterY) / strideY)));
     Image filter = initCluster.extractImage(x, y, dimFilterX, dimFilterY);
     if (okToAdd(filters, filter)) {
       // System.out.println(filters.size());
       filters.add(filter);
     }
   }
   for (int i = 0; i < noClusters; i++) {
     for (int j = 0; j < dimFilterX * dimFilterY; j++) {
       clustersCenters[i * dimFilterX * dimFilterY + j] = filters.get(i).getDataShort()[j];
     }
   }
 }