@Test
 public void testInvalidDatasetTypesFail() throws AssertionError {
   final Stream<DatasetType> allTypes = Arrays.stream(DatasetType.values());
   allTypes
       .filter(t -> t != DatasetType.BIT)
       .forEach(
           type -> {
             dataset = datasetCreator.createDataset(type);
             final boolean result = (boolean) ij.op().run(DatasetIsBinary.class, dataset);
             final String typeClassName = dataset.getType().getClass().getName();
             assertFalse("A Dataset of type " + typeClassName + " should not be binary", result);
           });
 }
Exemplo n.º 2
0
  public void dummySegmentation() {

    List<Dataset> predictDataset = new ArrayList<>(imgDatasets.size());

    INDArray predict = dummyClassification();
    int currIdx = 0;

    for (int ds = 0; ds < imgDatasets.size(); ds++) {
      List<List<int[]>> profilesSet = testData.get(ds).getProfiles();

      predictDataset.add(imagePlaneService.createEmptyPlaneDataset(imgDatasets.get(ds)));

      Dataset currDataset = predictDataset.get(ds);

      RandomAccess<RealType<?>> randomAccess = currDataset.randomAccess();

      for (List<int[]> p : profilesSet) {
        for (int i = 0; i < p.size(); i++) {
          randomAccess.setPosition(p.get(i)[0], 0);
          randomAccess.setPosition(p.get(i)[1], 1);

          double value = predict.getRow(currIdx).getDouble(i);
          if (value != 0) randomAccess.get().setReal(value);
        }
      }
      Overlay[] overlays = BinaryToOverlay.transform(context, currDataset, true);
      //            List<Overlay> overlayList = Arrays.asList(BinaryToOverlay.transform(context,
      // currDataset, true));
      overlayStatService.setRandomColor(Arrays.asList(overlays));
      ImageDisplay display = new DefaultImageDisplay();
      context.inject(display);
      display.display(currDataset);
      for (Overlay o : overlays) {
        display.display(o);
      }
      uis.show(display);
    }
  }
Exemplo n.º 3
0
  /**
   * Generate the corresponding sequences of labels (0, 1) for a set of profiles, depending on if
   * the pixel belongs to the membrane or not
   *
   * @param trainingSet Set of intensity profiles extracted from an image, for the training of the
   *     neural network and for that we need to label.
   * @param labeledDs Dataset where pixels belonging to membranes have been drawn.
   */
  public void generateConfirmationSet(ProfilesSet trainingSet, Dataset labeledDs) {

    RandomAccess<RealType<?>> randomAccess = labeledDs.randomAccess();

    List<int[]> labeledProfiles = new ArrayList<>(trainingSet.getProfiles().size());

    for (int i = 0; i < trainingSet.getProfiles().size(); i++) {

      List<int[]> profile = trainingSet.getProfiles().get(i);
      int[] labels = new int[trainingSet.getMaxLenght()];
      Arrays.fill(labels, 0);

      for (int j = 0; j < profile.size(); j++) {

        int[] point = profile.get(j);

        randomAccess.setPosition(point[0], 0);
        randomAccess.setPosition(point[1], 1);

        double pixelValue = randomAccess.get().getRealDouble();

        if (pixelValue == COLOR) {

          for (int k = j - membraneWidth.getValue() / 2;
              k <= j + membraneWidth.getValue() / 2;
              k++) {
            if (k < 0 || k > labels.length) continue;
            else labels[k] = 1;
          }

          break;
        }
        labeledProfiles.add(labels);
      }
      confirmationSet.add(labeledProfiles);
    }
  }
 @SuppressWarnings({"unchecked", "rawtypes"})
 private RealImageFunction<?, DoubleType> imgFunc(final Dataset ds) {
   final Img<? extends RealType<?>> imgPlus = ds.getImgPlus();
   return new RealImageFunction(imgPlus, new DoubleType());
 }