@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage source2 = (PlanarImage) params.get(INPUT_IMG2); PlanarImage result = source; if (source2 != null) { Integer transparency = (Integer) params.get(P_OPACITY); result = ImageProcessor.combineTwoImages(source.toMat(), source2.toMat(), transparency == null ? 255 : transparency); } params.put(Param.OUTPUT_IMG, result); }
public static BufferedImage toBufferedImage(PlanarImage matrix) { if (matrix == null) { return null; } return toBufferedImage(matrix.toMat()); }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Boolean flip = (Boolean) params.get(P_FLIP); if (flip != null && flip) { result = ImageProcessor.flip(source.toMat(), 1); // 1) means flipping around y-axis } params.put(Param.OUTPUT_IMG, result); } }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; KernelData kernel = (KernelData) params.get(P_KERNEL_DATA); if (kernel != null && !kernel.equals(KernelData.NONE)) { result = CvUtil.filter(source.toMat(), kernel); } params.put(Param.OUTPUT_IMG, result); }
public boolean write(PlanarImage mat) { return ImageProcessor.writeImage(mat.toMat(), file); } }
public double getDoseMax() { // Initialise max dose once dose images are available if (!this.images.isEmpty() && doseMax < 0.01) { for (MediaElement me : this.images) { Core.MinMaxLocResult minMaxLoc = minMaxLoc(((ImageElement) me).getImage().toMat()); if (doseMax < minMaxLoc.maxVal) { doseMax = minMaxLoc.maxVal; } } } return doseMax; }
private MediaElement interpolateDosePlanes(int upperBoundaryIndex, int lowerBoundaryIndex, double fractionalDistance) { MediaElement dosePlane = null; DicomImageElement upperPlane = (DicomImageElement) this.images.get(upperBoundaryIndex); DicomImageElement lowerPlane = (DicomImageElement) this.images.get(lowerBoundaryIndex); // A simple linear interpolation (lerp) Mat dosePlaneMat = new Mat(); addWeighted(lowerPlane.getImage().toMat(), 1.0 - fractionalDistance, upperPlane.getImage().toMat(), fractionalDistance, 0.0, dosePlaneMat); //TODO: dosePlaneMat should be an image for new dosePlane MediaElement return dosePlane; }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Boolean mask = (Boolean) params.get(P_SHOW); Rectangle area = (Rectangle) params.get(P_SHAPE); if (mask != null && mask && area != null && !area.equals(new Rectangle(0, 0, source.width(), source.height()))) { Double alpha = (Double) params.get(P_ALPHA); result = ImageProcessor.applyCropMask(source.toMat(), area, alpha == null ? 0.7 : alpha); } params.put(Param.OUTPUT_IMG, result); } }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; double[] matrix = (double[]) params.get(P_AFFINE_MATRIX); Rectangle2D bound = (Rectangle2D) params.get(P_DST_BOUNDS); if (bound != null && matrix != null && !Arrays.equals(identityMatrix, matrix)) { if (bound.getWidth() > 0 && bound.getHeight() > 0) { Mat mat = new Mat(2, 3, CvType.CV_64FC1); mat.put(0, 0, matrix); Integer interpolation = (Integer) params.get(P_INTERPOLATION); if (interpolation != null && interpolation == 3) { interpolation = 4; } result = ImageProcessor.warpAffine(source.toMat(), mat, new Size(bound.getWidth(), bound.getHeight()), interpolation); } else { result = null; } } params.put(Param.OUTPUT_IMG, result); }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Rectangle area = (Rectangle) params.get(P_AREA); if (area != null) { area = area.intersection(new Rectangle(0, 0, source.width(), source.height())); if (area.width > 1 && area.height > 1) { result = ImageProcessor.crop(source.toMat(), area); } } params.put(Param.OUTPUT_IMG, result); }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Double zoomFactorX = (Double) params.get(P_RATIO_X); Double zoomFactorY = (Double) params.get(P_RATIO_Y); if (zoomFactorX != null && zoomFactorY != null && (MathUtil.isDifferent(zoomFactorX, 1.0) || MathUtil.isDifferent(zoomFactorY, 1.0))) { Dimension dim = new Dimension((int) (Math.abs(zoomFactorX) * source.width()), (int) (Math.abs(zoomFactorY) * source.height())); Integer interpolation = (Integer) params.get(P_INTERPOLATION); if (Math.abs(zoomFactorX) < 0.1) { interpolation = Imgproc.INTER_AREA; } else if (interpolation != null && interpolation == 3) { interpolation = 4; } result = ImageProcessor.scale(source.toMat(), dim, interpolation); } params.put(Param.OUTPUT_IMG, result); }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Integer rotationAngle = Optional.ofNullable((Integer) params.get(P_ROTATE)).orElse(0); rotationAngle = rotationAngle % 360; if (rotationAngle != 0) { // optimize rotation by right angles Integer rotOp = null; if (rotationAngle == 90) { rotOp = Core.ROTATE_90_CLOCKWISE; } else if (rotationAngle == 180) { rotOp = Core.ROTATE_180; } else if (rotationAngle == 270) { rotOp = Core.ROTATE_90_COUNTERCLOCKWISE; } if (rotOp != null) { result = ImageProcessor.getRotatedImage(source.toMat(), rotOp); } else { result = ImageProcessor.getRotatedImage(source.toMat(), rotationAngle, source.width() / 2.0, source.height() / 2.0); } } params.put(Param.OUTPUT_IMG, result); }
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; ByteLut lutTable = (ByteLut) params.get(P_LUT); if (lutTable != null) { boolean invert = LangUtil.getNULLtoFalse((Boolean) params.get(P_LUT_INVERSE)); byte[][] lut = invert ? lutTable.getInvertedLutTable() : lutTable.getLutTable(); if (lut == null) { if (invert) { result = ImageProcessor.invertLUT(source.toImageCV()); } } else { result = ImageProcessor.applyLUT(source.toMat(), lut); // result = new LookupTableCV(lut).lookup(source); } } params.put(Param.OUTPUT_IMG, result); }
public static ImageCV buildThumbnail(PlanarImage source, Dimension iconDim, boolean keepRatio) { Objects.requireNonNull(source); if (Objects.requireNonNull(iconDim).width < 1 || iconDim.height < 1) { throw new IllegalArgumentException("Unsupported size: " + iconDim); } final double scale = Math.min(iconDim.getHeight() / source.height(), iconDim.getWidth() / source.width()); if (scale >= 1.0) { return source.toImageCV(); } if (scale < 0.005) { return null; // Image is too large to be converted } Size dim = keepRatio ? new Size((int) (scale * source.width()), (int) (scale * source.height())) : new Size(iconDim.width, iconDim.height); Mat srcImg = Objects.requireNonNull(source).toMat(); ImageCV dstImg = new ImageCV(); Imgproc.resize(srcImg, dstImg, dim, 0, 0, Imgproc.INTER_AREA); return dstImg; }
protected void findMinMaxValues(PlanarImage img, boolean exclude8bitImage) throws OutOfMemoryError { // This function can be called several times from the inner class Load. // Do not compute min and max it has already be done if (img != null && !isImageAvailable()) { if (ImageConversion.convertToDataType(img.type()) == DataBuffer.TYPE_BYTE && exclude8bitImage) { this.minPixelValue = 0.0; this.maxPixelValue = 255.0; } else { MinMaxLocResult val = ImageProcessor.findMinMaxValues(img.toMat()); if (val != null) { this.minPixelValue = val.minVal; this.maxPixelValue = val.maxVal; } // Handle special case when min and max are equal, ex. black image // + 1 to max enables to display the correct value if (this.minPixelValue.equals(this.maxPixelValue)) { this.maxPixelValue += 1.0; } } } }
private static void writeRasterInRaw(PlanarImage image, FileRawImage[] newSeries, ImageCV[] builImgs, ViewParameter params, int dstHeight, int imgIndex) throws IOException { ImageCV img = ImageProcessor.getRotatedImage(image.toMat(), params.rotateCvType); if (newSeries != null && img != null && img.height() == newSeries.length) { if (newSeries[0] == null) { File dir = new File(MPR_CACHE_DIR, params.seriesUID); dir.mkdirs(); for (int i = 0; i < newSeries.length; i++) { newSeries[i] = new FileRawImage(new File(dir, "mpr_" + (i + 1) + ".wcv"));//$NON-NLS-1$ //$NON-NLS-2$ builImgs[i] = new ImageCV(dstHeight, img.width(), img.type()); } } for (int j = 0; j < newSeries.length; j++) { img.row(j).copyTo(builImgs[j].row(imgIndex - 1)); } } }
public static ImageCV minStack(List<ImageElement> sources) { if (sources.size() > 1) { ImageElement firstImg = sources.get(0); ImageCV dstImg = new ImageCV(); PlanarImage img = firstImg.getImage(null, false); img.toMat().copyTo(dstImg); int numbSrc = sources.size(); for (int i = 1; i < numbSrc; i++) { ImageElement imgElement = sources.get(i); PlanarImage image = imgElement.getImage(null, false); if (image.width() != dstImg.width() && image.height() != dstImg.height()) { continue; } if (image instanceof Mat) { Core.min(dstImg, (Mat) image, dstImg); } } return dstImg; } return null; }
public List<MatOfPoint> getIsoDoseContourPoints(KeyDouble slicePosition, double isoDoseThreshold) { List<MatOfPoint> contours = new ArrayList<>(); // Convert from threshold in cCy to raw pixel value threshold double rawThreshold = (isoDoseThreshold / 100) / this.doseGridScaling; DicomImageElement dosePlane = (DicomImageElement) this.getDosePlaneBySlice(slicePosition.getValue()); int rows = dosePlane.getImage().toMat().rows(); int cols = dosePlane.getImage().toMat().cols(); Mat src = new Mat(rows, cols, CvType.CV_32FC1); Mat thr = new Mat(rows, cols, CvType.CV_32FC1); dosePlane.getImage().toMat().convertTo(src, CvType.CV_32FC1); Mat hierarchy = new Mat(); Imgproc.threshold(src, thr, rawThreshold, 255, Imgproc.THRESH_BINARY); Mat thrSrc = new Mat(rows, cols, CvType.CV_8U); thr.convertTo(thrSrc, CvType.CV_8U); Imgproc.findContours(thrSrc, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); return contours; }
public static ImageCV maxStack(List<ImageElement> sources) { if (sources.size() > 1) { ImageElement firstImg = sources.get(0); ImageCV dstImg = new ImageCV(); PlanarImage img = firstImg.getImage(null, false); img.toMat().copyTo(dstImg); int numbSrc = sources.size(); for (int i = 1; i < numbSrc; i++) { ImageElement imgElement = sources.get(i); PlanarImage image = imgElement.getImage(null, false); if (image.width() != dstImg.width() && image.height() != dstImg.height()) { continue; } if (image instanceof Mat) { Core.max(dstImg, (Mat) image, dstImg); } } return dstImg; } return null; } }
double yInt = 255.0 - slope * high; return ImageProcessor.rescaleToByte(source.toMat(), slope, yInt);