private byte[] getROIData(ROI roi, Rectangle rectIMG) {
    byte[] dataROI;
    PlanarImage roiIMG = roi.getAsImage();
    Rectangle rectROI = roiIMG.getBounds();
    // Forcing to component colormodel in order to avoid packed bits
    ImageWorker w = new ImageWorker();
    w.setImage(roiIMG);
    w.forceComponentColorModel();
    RenderedImage img = w.getRenderedImage();
    //
    BufferedImage test =
        new BufferedImage(rectIMG.width, rectIMG.height, BufferedImage.TYPE_BYTE_GRAY);
    ImageLayout2 layout = new ImageLayout2(test);
    layout.setMinX(img.getMinX());
    layout.setMinY(img.getMinY());
    layout.setWidth(img.getWidth());
    layout.setHeight(img.getHeight());
    // Lookup
    byte[] lut = new byte[256];
    lut[255] = 1;
    lut[1] = 1;
    LookupTableJAI table = new LookupTableJAI(lut);
    RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);
    RenderedOp transformed = LookupDescriptor.create(img, table, hints);

    Graphics2D gc2d = null;
    // Translation parameters in order to position the ROI data correctly in the Raster Space
    int trX = -rectIMG.x + rectROI.x - rectIMG.x;
    int trY = -rectIMG.y + rectROI.y - rectIMG.y;
    try {
      gc2d = test.createGraphics();
      gc2d.drawRenderedImage(transformed, AffineTransform.getTranslateInstance(trX, trY));
    } finally {
      gc2d.dispose();
    }
    Rectangle testRect = new Rectangle(rectIMG.width, rectIMG.height);
    DataBufferByte dbRoi = (DataBufferByte) test.getData(testRect).getDataBuffer();
    dataROI = dbRoi.getData();
    // BufferedImage is stored in memory so the planarImage chain before can be disposed
    ImageUtilities.disposePlanarImageChain(transformed);
    // Flush of the BufferedImage
    test.flush();

    return dataROI;
  }
예제 #2
0
  // This method is similar to the testBandMerge method but it tests the ExtendedBandMergeOpImage
  // class
  private void testExtendedBandMerge(RenderedImage[] sources, boolean noDataUsed, boolean roiUsed) {
    // Optional No Data Range used
    Range[] noData;
    // Source image data type
    int dataType = sources[0].getSampleModel().getDataType();
    // If no Data are present, the No Data Range associated is used
    if (noDataUsed) {

      switch (dataType) {
        case DataBuffer.TYPE_BYTE:
          noData = noDataByte;
          break;
        case DataBuffer.TYPE_USHORT:
          noData = noDataUShort;
          break;
        case DataBuffer.TYPE_SHORT:
          noData = noDataShort;
          break;
        case DataBuffer.TYPE_INT:
          noData = noDataInt;
          break;
        case DataBuffer.TYPE_FLOAT:
          noData = noDataFloat;
          break;
        case DataBuffer.TYPE_DOUBLE:
          noData = noDataDouble;
          break;
        default:
          throw new IllegalArgumentException("Wrong data type");
      }
    } else {
      noData = null;
    }

    // ROI to use
    ROI roi = null;
    if (roiUsed) {
      roi = roiData;
    }

    // New array ofr the transformed source images
    RenderedOp[] translated = new RenderedOp[sources.length];

    List<AffineTransform> transform = new ArrayList<AffineTransform>();

    for (int i = 0; i < sources.length; i++) {
      // Translation coefficients
      int xTrans = (int) (Math.random() * 10);
      int yTrans = (int) (Math.random() * 10);
      // Translation operation
      AffineTransform tr = AffineTransform.getTranslateInstance(xTrans, yTrans);
      // Addition to the transformations list
      transform.add(tr);
      // Translation of the image
      translated[i] =
          TranslateDescriptor.create(sources[i], (float) xTrans, (float) yTrans, null, null);
    }
    // Definition of the final image dimensions
    ImageLayout layout = new ImageLayout();
    layout.setMinX(sources[0].getMinX());
    layout.setMinY(sources[0].getMinY());
    layout.setWidth(sources[0].getWidth());
    layout.setHeight(sources[0].getHeight());

    RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);

    // BandMerge operation
    RenderedOp merged =
        BandMergeDescriptor.create(noData, destNoData, hints, transform, roi, translated);

    Assert.assertNotNull(merged.getTiles());
    // Check if the bands number is the same
    assertEquals(BAND_NUMBER, merged.getNumBands());
    // Upper-Left tile indexes
    int minTileX = merged.getMinTileX();
    int minTileY = merged.getMinTileY();
    // Raster object
    Raster upperLeftTile = merged.getTile(minTileX, minTileY);
    // Tile bounds
    int minX = upperLeftTile.getMinX();
    int minY = upperLeftTile.getMinY();
    int maxX = upperLeftTile.getWidth() + minX;
    int maxY = upperLeftTile.getHeight() + minY;

    // Source corners
    final int dstMinX = merged.getMinX();
    final int dstMinY = merged.getMinY();
    final int dstMaxX = merged.getMaxX();
    final int dstMaxY = merged.getMaxY();

    Point2D ptDst = new Point2D.Double(0, 0);
    Point2D ptSrc = new Point2D.Double(0, 0);

    // Cycle on all the tile Bands
    for (int b = 0; b < BAND_NUMBER; b++) {
      RandomIter iter = RandomIterFactory.create(translated[b], null);

      // Source corners
      final int srcMinX = translated[b].getMinX();
      final int srcMinY = translated[b].getMinY();
      final int srcMaxX = translated[b].getMaxX();
      final int srcMaxY = translated[b].getMaxY();

      // Cycle on the y-axis
      for (int x = minX; x < maxX; x++) {
        // Cycle on the x-axis
        for (int y = minY; y < maxY; y++) {
          // Calculated value
          double value = upperLeftTile.getSampleDouble(x, y, b);
          // If the tile pixels are outside the image bounds, then no data is set.
          if (x < dstMinX || x >= dstMaxX || y < dstMinY || y >= dstMaxY) {
            value = destNoData;
          }

          // Set the x,y destination pixel location
          ptDst.setLocation(x, y);
          // Map destination pixel to source pixel
          transform.get(b).transform(ptDst, ptSrc);
          // Source pixel indexes
          int srcX = round(ptSrc.getX());
          int srcY = round(ptSrc.getY());

          double valueOld = destNoData;

          // Check if the pixel is inside the source bounds
          if (!(srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY)) {
            // Old band value
            valueOld = iter.getSampleDouble(srcX, srcY, 0);
          }

          // ROI CHECK
          boolean contained = true;
          if (roiUsed) {
            if (!roi.contains(x, y)) {
              contained = false;
              // Comparison if the final value is not inside a ROI
              assertEquals(value, destNoData, TOLERANCE);
            }
          }

          if (contained) {
            // If no Data are present, no data check is performed
            if (noDataUsed) {
              switch (dataType) {
                case DataBuffer.TYPE_BYTE:
                  byte sampleB = ImageUtil.clampRoundByte(value);
                  byte sampleBOld = ImageUtil.clampRoundByte(valueOld);
                  if (noData[0].contains(sampleBOld)) {
                    assertEquals(sampleB, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleB, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_USHORT:
                  short sampleUS = ImageUtil.clampRoundUShort(value);
                  short sampleUSOld = ImageUtil.clampRoundUShort(valueOld);
                  if (noData[0].contains(sampleUSOld)) {
                    assertEquals(sampleUS, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleUS, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_SHORT:
                  short sampleS = ImageUtil.clampRoundShort(value);
                  short sampleSOld = ImageUtil.clampRoundShort(valueOld);
                  if (noData[0].contains(sampleSOld)) {
                    assertEquals(sampleS, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleS, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_INT:
                  int sampleI = ImageUtil.clampRoundInt(value);
                  int sampleIOld = ImageUtil.clampRoundInt(valueOld);
                  if (noData[0].contains(sampleIOld)) {
                    assertEquals(sampleI, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleI, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_FLOAT:
                  float sampleF = ImageUtil.clampFloat(value);
                  float sampleFOld = ImageUtil.clampFloat(valueOld);
                  if (noData[0].contains(sampleFOld)) {
                    assertEquals(sampleF, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleF, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_DOUBLE:
                  if (noData[0].contains(valueOld)) {
                    assertEquals(value, destNoData, TOLERANCE);
                  } else {
                    assertEquals(value, valueOld, TOLERANCE);
                  }
                  break;
                default:
                  throw new IllegalArgumentException("Wrong data type");
              }
            } else {
              // Else a simple value comparison is done
              assertEquals(value, valueOld, TOLERANCE);
            }
          }
        }
      }
    }
    // Disposal of the output image
    merged.dispose();
  }
예제 #3
0
  private void testBandMerge(RenderedImage[] sources, boolean noDataUsed, boolean roiUsed) {
    // Optional No Data Range used
    Range[] noData;
    // Source image data type
    int dataType = sources[0].getSampleModel().getDataType();
    // If no Data are present, the No Data Range associated is used
    if (noDataUsed) {

      switch (dataType) {
        case DataBuffer.TYPE_BYTE:
          noData = noDataByte;
          break;
        case DataBuffer.TYPE_USHORT:
          noData = noDataUShort;
          break;
        case DataBuffer.TYPE_SHORT:
          noData = noDataShort;
          break;
        case DataBuffer.TYPE_INT:
          noData = noDataInt;
          break;
        case DataBuffer.TYPE_FLOAT:
          noData = noDataFloat;
          break;
        case DataBuffer.TYPE_DOUBLE:
          noData = noDataDouble;
          break;
        default:
          throw new IllegalArgumentException("Wrong data type");
      }
    } else {
      noData = null;
    }

    // ROI to use
    ROI roi = null;
    if (roiUsed) {
      roi = roiData;
    }

    // BandMerge operation
    RenderedOp merged = BandMergeDescriptor.create(noData, destNoData, null, null, roi, sources);
    // Check if the bands number is the same
    assertEquals(BAND_NUMBER, merged.getNumBands());
    // Upper-Left tile indexes
    int minTileX = merged.getMinTileX();
    int minTileY = merged.getMinTileY();
    // Raster object
    Raster upperLeftTile = merged.getTile(minTileX, minTileY);
    // Tile bounds
    int minX = upperLeftTile.getMinX();
    int minY = upperLeftTile.getMinY();
    int maxX = upperLeftTile.getWidth() + minX;
    int maxY = upperLeftTile.getHeight() + minY;
    // Cycle on all the tile Bands
    for (int b = 0; b < BAND_NUMBER; b++) {
      // Selection of the source raster associated with the band
      Raster bandRaster = sources[b].getTile(minTileX, minTileY);
      // Cycle on the y-axis
      for (int x = minX; x < maxX; x++) {
        // Cycle on the x-axis
        for (int y = minY; y < maxY; y++) {
          // Calculated value
          double value = upperLeftTile.getSampleDouble(x, y, b);
          // Old band value
          double valueOld = bandRaster.getSampleDouble(x, y, 0);

          // ROI CHECK
          boolean contained = true;
          if (roiUsed) {
            if (!roi.contains(x, y)) {
              contained = false;
              // Comparison if the final value is not inside a ROI
              assertEquals(value, destNoData, TOLERANCE);
            }
          }

          if (contained) {
            // If no Data are present, no data check is performed
            if (noDataUsed) {
              switch (dataType) {
                case DataBuffer.TYPE_BYTE:
                  byte sampleB = ImageUtil.clampRoundByte(value);
                  byte sampleBOld = ImageUtil.clampRoundByte(valueOld);
                  if (noData[0].contains(sampleBOld)) {
                    assertEquals(sampleB, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleB, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_USHORT:
                  short sampleUS = ImageUtil.clampRoundUShort(value);
                  short sampleUSOld = ImageUtil.clampRoundUShort(valueOld);
                  if (noData[0].contains(sampleUSOld)) {
                    assertEquals(sampleUS, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleUS, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_SHORT:
                  short sampleS = ImageUtil.clampRoundShort(value);
                  short sampleSOld = ImageUtil.clampRoundShort(valueOld);
                  if (noData[0].contains(sampleSOld)) {
                    assertEquals(sampleS, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleS, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_INT:
                  int sampleI = ImageUtil.clampRoundInt(value);
                  int sampleIOld = ImageUtil.clampRoundInt(valueOld);
                  if (noData[0].contains(sampleIOld)) {
                    assertEquals(sampleI, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleI, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_FLOAT:
                  float sampleF = ImageUtil.clampFloat(value);
                  float sampleFOld = ImageUtil.clampFloat(valueOld);
                  if (noData[0].contains(sampleFOld)) {
                    assertEquals(sampleF, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleF, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_DOUBLE:
                  if (noData[0].contains(valueOld)) {
                    assertEquals(value, destNoData, TOLERANCE);
                  } else {
                    assertEquals(value, valueOld, TOLERANCE);
                  }
                  break;
                default:
                  throw new IllegalArgumentException("Wrong data type");
              }
            } else {
              // Else a simple value comparison is done
              assertEquals(value, valueOld, TOLERANCE);
            }
          }
        }
      }
    }
    // Disposal of the output image
    merged.dispose();
  }
    @Override
    public RenderedImage postProcessMosaic(
        RenderedImage mosaic, ROI overallROI, RenderingHints hints) {

      // force the current image in RGB or Gray
      final ImageWorker imageWorker = new ImageWorker(mosaic);
      hints = prepareHints(hints);
      imageWorker.setRenderingHints(hints);

      // make sure the mosaic image is either gray of RGB
      if (!imageWorker.isColorSpaceGRAYScale()) {
        if (!imageWorker.isColorSpaceRGB()) {
          imageWorker.forceColorSpaceRGB();
        }
      }
      imageWorker.forceComponentColorModel(); // todo optimize with paletted imagery

      // do we already have a alpha band in the input image?
      if (imageWorker.getRenderedImage().getColorModel().hasAlpha()) {
        // if so we reuse it applying the ROI on top of it
        RenderedImage alpha = imageWorker.retainLastBand().getRenderedImage();
        RenderedImage maskedAlpha =
            new ImageWorker(hints)
                .mosaic(
                    new RenderedImage[] {alpha},
                    MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
                    null,
                    new ROI[] {overallROI},
                    null,
                    null)
                .getRenderedImage();

        imageWorker.retainBands(mosaic.getColorModel().getNumColorComponents());
        imageWorker.addBand(maskedAlpha, false, true, null);
      } else {

        // turn the roi into a single band image and add it to the mosaic as transparency
        final ImageWorker roiImageWorker = new ImageWorker(overallROI.getAsImage());
        roiImageWorker.setRenderingHints(hints);

        PlanarImage alpha =
            roiImageWorker.forceComponentColorModel().retainFirstBand().getPlanarImage();
        if (!alpha.getBounds().equals(imageWorker.getPlanarImage().getBounds())) {
          // build final layout and use it for giving the alpha band a simil size and tiling
          // to the one of the image
          final ImageLayout layout =
              new ImageLayout(
                  mosaic.getMinX(), mosaic.getMinY(), mosaic.getWidth(), mosaic.getHeight());

          //
          final SampleModel sampleModel = mosaic.getSampleModel();
          layout.setTileHeight(sampleModel.getWidth()).setTileWidth(sampleModel.getHeight());
          hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));

          // correct bounds of the current image
          alpha =
              new ImageWorker(hints)
                  .mosaic(
                      new RenderedImage[] {alpha},
                      MosaicDescriptor.MOSAIC_TYPE_OVERLAY,
                      null,
                      new ROI[] {overallROI},
                      null,
                      null)
                  .getRenderedOperation();
        }
        imageWorker.addBand(alpha, false, true, null);
      }

      RenderedImage result = imageWorker.getRenderedImage();
      return result;
    }
예제 #5
0
  /**
   * Checking if NoData and ROI are defined correctly
   *
   * @param indexed
   * @param image
   * @param roi
   * @param nodata
   * @param destNoData
   */
  private void checkNoDataROI(
      RenderedImage indexed, RenderedImage image, ROI roi, Range nodata, int destNoData) {
    // Ensure the dimensions are the same
    assertEquals(indexed.getMinX(), image.getMinX());
    assertEquals(indexed.getMinY(), image.getMinY());
    assertEquals(indexed.getWidth(), image.getWidth());
    assertEquals(indexed.getHeight(), image.getHeight());

    boolean roiExists = roi != null;
    boolean nodataExists = nodata != null;
    // Simply ensure no exception is thrown
    if (!nodataExists && !roiExists) {
      PlanarImage.wrapRenderedImage(indexed).getTiles();
      return;
    }

    if (nodataExists) {
      nodata = RangeFactory.convertToDoubleRange(nodata);
    }
    RandomIter roiIter = null;
    Rectangle roiBounds = null;
    if (roiExists) {
      PlanarImage roiIMG = roi.getAsImage();
      roiIter = RandomIterFactory.create(roiIMG, null, true, true);
      roiBounds = roi.getBounds();
    }

    // Else check ROI and NoData
    RandomIter sourceIter = RandomIterFactory.create(image, null, true, true);
    RandomIter destIter = RandomIterFactory.create(indexed, null, true, true);
    // Start the iteration (we iterate only the first band)
    int w = image.getWidth();
    int h = image.getHeight();
    int minX = image.getMinX();
    int minY = image.getMinY();
    int maxX = minX + w;
    int maxY = minY + h;
    int limx = minX - image.getTileGridXOffset();
    int limy = minY - image.getTileGridYOffset();
    Rectangle translated = new Rectangle(limx, limy, w, h);

    for (int y = minY; y < maxY; y++) {
      for (int x = minX; x < maxX; x++) {

        double src = sourceIter.getSampleDouble(x, y, 0);
        double dest = destIter.getSampleDouble(x, y, 0);

        boolean valid = true;

        // ROI Check
        if (roiExists
            && !(roiBounds.contains(x, y) && roiIter.getSample(x, y, 0) > 0)
            && translated.contains(x, y)) {
          valid = false;
        }

        // NoData Check
        if (nodataExists && nodata.contains(src)) {
          valid = false;
        }
        if (!valid) {
          assertEquals(destNoData, dest, TOLERANCE);
        }
      }
    }
  }
  /**
   * Returns the specified property.
   *
   * @param name Property name.
   * @param opNode Operation node.
   */
  public Object getProperty(String name, Object opNode) {
    validate(name, opNode);

    if (opNode instanceof RenderedOp && name.equalsIgnoreCase("roi")) {
      RenderedOp op = (RenderedOp) opNode;

      ParameterBlock pb = op.getParameterBlock();

      // Retrieve the rendered source image and its ROI.
      RenderedImage src = pb.getRenderedSource(0);
      Object property = src.getProperty("ROI");
      if (property == null
          || property.equals(java.awt.Image.UndefinedProperty)
          || !(property instanceof ROI)) {
        return java.awt.Image.UndefinedProperty;
      }

      // Return undefined also if source ROI is empty.
      ROI srcROI = (ROI) property;
      if (srcROI.getBounds().isEmpty()) {
        return java.awt.Image.UndefinedProperty;
      }

      // Retrieve the Interpolation object.
      Interpolation interp = (Interpolation) pb.getObjectParameter(1);

      // Determine the effective source bounds.
      Rectangle srcBounds = null;
      PlanarImage dst = op.getRendering();
      if (dst instanceof GeometricOpImage && ((GeometricOpImage) dst).getBorderExtender() == null) {
        srcBounds =
            new Rectangle(
                src.getMinX() + interp.getLeftPadding(),
                src.getMinY() + interp.getTopPadding(),
                src.getWidth() - interp.getWidth() + 1,
                src.getHeight() - interp.getHeight() + 1);
      } else {
        srcBounds = new Rectangle(src.getMinX(), src.getMinY(), src.getWidth(), src.getHeight());
      }

      // If necessary, clip the ROI to the effective source bounds.
      if (!srcBounds.contains(srcROI.getBounds())) {
        srcROI = srcROI.intersect(new ROIShape(srcBounds));
      }

      // Retrieve the Warp object.
      Warp warp = (Warp) pb.getObjectParameter(0);

      // Setting constant image to be warped as a ROI
      Rectangle dstBounds = op.getBounds();

      // Setting layout of the constant image
      ImageLayout2 layout = new ImageLayout2();
      int minx = (int) srcBounds.getMinX();
      int miny = (int) srcBounds.getMinY();
      int w = (int) srcBounds.getWidth();
      int h = (int) srcBounds.getHeight();
      layout.setMinX(minx);
      layout.setMinY(miny);
      layout.setWidth(w);
      layout.setHeight(h);
      RenderingHints hints = op.getRenderingHints();
      hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));

      final PlanarImage constantImage =
          ConstantDescriptor.create(new Float(w), new Float(h), new Byte[] {(byte) 255}, hints);

      PlanarImage roiImage = null;

      // Make sure to specify tileCache, tileScheduler, tileRecyclier, by cloning hints.
      RenderingHints warpingHints = op.getRenderingHints();
      warpingHints.remove(JAI.KEY_IMAGE_LAYOUT);

      // Creating warped roi by the same way (Warp, Interpolation, source ROI) we warped the
      // input image.
      final ParameterBlock paramBlk = new ParameterBlock();
      paramBlk.addSource(constantImage);
      paramBlk.add(warp);
      paramBlk.add(interp);
      paramBlk.add(null);
      paramBlk.add(srcROI);

      // force in the image layout, this way we get exactly the same
      // as the affine we're eliminating
      Hints localHints = new Hints(op.getRenderingHints());
      localHints.remove(JAI.KEY_IMAGE_LAYOUT);
      ImageLayout il = new ImageLayout();
      il.setMinX(dstBounds.x);
      il.setMinY(dstBounds.y);
      il.setWidth(dstBounds.width);
      il.setHeight(dstBounds.height);
      localHints.put(JAI.KEY_IMAGE_LAYOUT, il);
      roiImage = JAI.create("Warp", paramBlk, localHints);
      ROI dstROI = new ROI(roiImage, 1);

      // If necessary, clip the warped ROI to the destination bounds.
      if (!dstBounds.contains(dstROI.getBounds())) {
        dstROI = dstROI.intersect(new ROIShape(dstBounds));
      }

      // Return the warped and possibly clipped ROI.
      return dstROI;
    }

    return java.awt.Image.UndefinedProperty;
  }
예제 #7
0
  private void testType(RenderedImage src, boolean nodataUsed, boolean roiUsed) {
    // Optional No Data Range used
    Range noData;
    // Source image data type
    int dataType = src.getSampleModel().getDataType();
    // If no Data are present, the No Data Range associated is used
    if (nodataUsed) {

      switch (dataType) {
        case DataBuffer.TYPE_BYTE:
          noData = noDataByte;
          break;
        case DataBuffer.TYPE_USHORT:
          noData = noDataUShort;
          break;
        case DataBuffer.TYPE_SHORT:
          noData = noDataShort;
          break;
        case DataBuffer.TYPE_INT:
          noData = noDataInt;
          break;
        case DataBuffer.TYPE_FLOAT:
          noData = noDataFloat;
          break;
        case DataBuffer.TYPE_DOUBLE:
          noData = noDataDouble;
          break;
        default:
          throw new IllegalArgumentException("Wrong data type");
      }
    } else {
      noData = null;
    }

    ROI roi;

    if (roiUsed) {
      roi = roiObject;
    } else {
      roi = null;
    }

    // BandCombined result
    RenderedOp combined =
        BandCombineDescriptor.create(src, matrix, roi, noData, destinationNoData, null);

    int tileWidth = combined.getTileWidth();
    int tileHeight = combined.getTileHeight();
    int minTileX = combined.getMinTileX();
    int minTileY = combined.getMinTileY();
    int numXTiles = combined.getNumXTiles();
    int numYTiles = combined.getNumYTiles();
    int maxTileX = minTileX + numXTiles;
    int maxTileY = minTileY + numYTiles;
    // Ensure same size
    assertEquals(combined.getWidth(), src.getWidth());
    assertEquals(combined.getHeight(), src.getHeight());
    assertEquals(combined.getMinX(), src.getMinX());
    assertEquals(combined.getMinY(), src.getMinY());
    assertEquals(minTileX, src.getMinTileX());
    assertEquals(minTileY, src.getMinTileY());
    assertEquals(numXTiles, src.getNumXTiles());
    assertEquals(numYTiles, src.getNumYTiles());
    assertEquals(tileWidth, src.getTileWidth());
    assertEquals(tileHeight, src.getTileHeight());

    int srcBands = src.getSampleModel().getNumBands();
    int dstBands = combined.getNumBands();

    // Ensure a correct band size
    assertEquals(dstBands, matrix.length);

    // Check on all the pixels if they have been calculate correctly
    for (int tileX = minTileX; tileX < maxTileX; tileX++) {
      for (int tileY = minTileY; tileY < maxTileY; tileY++) {
        Raster tile = combined.getTile(tileX, tileY);
        Raster srcTile = src.getTile(tileX, tileY);

        int minX = tile.getMinX();
        int minY = tile.getMinY();
        int maxX = minX + tileWidth - 1;
        int maxY = minY + tileHeight - 1;

        for (int x = minX; x <= maxX; x++) {
          for (int y = minY; y <= maxY; y++) {

            boolean isValidRoi = !roiUsed || (roiUsed && roiObject.contains(x, y));

            if (isValidRoi) {
              for (int b = 0; b < dstBands; b++) {
                // Getting the result
                double result = tile.getSampleDouble(x, y, b);

                // Calculating the expected result from sources
                boolean valid = false;
                double calculated = 0;

                for (int i = 0; i < srcBands; i++) {
                  double sample = srcTile.getSampleDouble(x, y, i);
                  boolean isValidData =
                      !nodataUsed || (nodataUsed && !noDataDouble.contains(sample));
                  valid |= isValidData;
                  if (isValidData) {
                    switch (dataType) {
                      case DataBuffer.TYPE_BYTE:
                        calculated += ((int) sample & 0xFF) * matrix[b][i];
                        break;
                      case DataBuffer.TYPE_USHORT:
                        calculated += ((int) sample & 0xFFFF) * matrix[b][i];
                        break;
                      case DataBuffer.TYPE_SHORT:
                      case DataBuffer.TYPE_INT:
                      case DataBuffer.TYPE_FLOAT:
                      case DataBuffer.TYPE_DOUBLE:
                        calculated += sample * matrix[b][i];
                        break;
                      default:
                        break;
                    }
                  }
                }

                if (valid) {
                  calculated += matrix[b][srcBands];
                  switch (dataType) {
                    case DataBuffer.TYPE_BYTE:
                      calculated = ImageUtil.clampRoundByte(calculated);
                      result = ImageUtil.clampRoundByte(result);
                      break;
                    case DataBuffer.TYPE_USHORT:
                      calculated = ImageUtil.clampRoundUShort(calculated);
                      result = ImageUtil.clampRoundUShort(result);
                      break;
                    case DataBuffer.TYPE_SHORT:
                      calculated = ImageUtil.clampRoundShort(calculated);
                      result = ImageUtil.clampRoundShort(result);
                      break;
                    case DataBuffer.TYPE_INT:
                      calculated = ImageUtil.clampRoundInt(calculated);
                      result = ImageUtil.clampRoundInt(result);
                      break;
                    case DataBuffer.TYPE_FLOAT:
                      calculated = (float) calculated;
                      calculated = (float) result;
                      break;
                    case DataBuffer.TYPE_DOUBLE:
                      break;
                    default:
                      break;
                  }
                  assertEquals(result, calculated, TOLERANCE);
                } else {
                  assertEquals(result, destNoData, TOLERANCE);
                }
              }
            } else {
              for (int b = 0; b < dstBands; b++) {
                assertEquals(tile.getSampleDouble(x, y, b), destNoData, TOLERANCE);
              }
            }
          }
        }
      }
    }

    // Disposal of the output image
    combined.dispose();
  }