@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); }
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; }
Mat mean = new Mat(img.height(), img.width(), CvType.CV_32F); img.toMat().convertTo(mean, CvType.CV_32F); 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() != img.width() && image.height() != img.height()) { continue; type = image.type(); if (CvType.depth(image.type()) == CvType.CV_16S) { Mat floatImage = new Mat(img.height(), img.width(), CvType.CV_32F); image.toMat().convertTo(floatImage, CvType.CV_32F); Imgproc.accumulate(floatImage, mean); } else {
@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); }
/** * Computes Min/Max values from Image excluding range of values provided * * @param img * @param paddingValueMin * @param paddingValueMax */ private void findMinMaxValues(PlanarImage img, Integer paddingValueMin, Integer paddingValueMax) { if (img != null) { if (ImageConversion.convertToDataType(img.type()) == DataBuffer.TYPE_BYTE) { this.minPixelValue = 0.0; this.maxPixelValue = 255.0; } else { MinMaxLocResult val = ImageProcessor.findMinMaxValues(img.toMat(), paddingValueMin, paddingValueMax); 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; } } } }
@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); }
readable = img.width() > 0; if (readable) { mCache.put(this, img);
@Override public void process() throws Exception { PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Double contrast = (Double) params.get(P_CONTRAST_VALUE); Double brigtness = (Double) params.get(P_BRIGTNESS_VALUE); if (contrast != null && brigtness != null) { result = ImageProcessor.rescaleToByte(source.toImageCV(), contrast / 100.0, brigtness); } params.put(Param.OUTPUT_IMG, result); }
protected static String[] getChannelNames(PlanarImage image) { if (image != null) { int channels = CvType.channels(image.type()); if (channels == 3) { return new String[] { Messages.getString("DefaultView2d.blue"), Messages.getString("DefaultView2d.green"), Messages.getString("DefaultView2d.red") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else if (channels == 1) { return new String[] { Messages.getString("DefaultView2d.gray") }; //$NON-NLS-1$ } } return null; }
pixelInfo.setPixelSpacingUnit(imageElement.getPixelSpacingUnit()); pixelInfo.setPixelSize(imageElement.getPixelSize()); double[] c = image.get(p.y, p.x); pixelInfo.setPixelValueUnit(imageElement.getPixelValueUnit()); fillPixelInfo(pixelInfo, imageElement, c);
if (img != null && (img.width() > ImageFiler.TILESIZE || img.height() > ImageFiler.TILESIZE) && !mimeType.contains("dicom")) { //$NON-NLS-1$ File outFile = imgCachePath.toFile(); new FileRawImage(outFile).write(img); PlanarImage img8 = img; if (CvType.depth(img.type()) > CvType.CV_8S && media instanceof ImageElement) { ImageElement imgElement = ((ImageElement) media); Map<String, Object> params = null; double min = 0; double max = 65536; MinMaxLocResult val = ImageProcessor.findMinMaxValues(img.toMat()); if (val != null) { min = val.minVal; ImageProcessor.writeThumbnail(img8.toMat(), new File(ImageFiler.changeExtension(outFile.getPath(), ".jpg")), Thumbnail.MAX_SIZE); //$NON-NLS-1$ return outFile;
public static BufferedImage toBufferedImage(PlanarImage matrix) { if (matrix == null) { return null; } return toBufferedImage(matrix.toMat()); }
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; } } } }
@Override public PlanarImage process() { PlanarImage source = getFirstNodeInputImage(); if (source != null && source.width() > 0) { for (int i = 0; i < operations.size(); i++) { ImageOpNode op = operations.get(i); try { if (i > 0) { op.setParam(Param.INPUT_IMG, operations.get(i - 1).getParam(Param.OUTPUT_IMG)); } if (op.isEnabled()) { op.process(); } else { // Skip this operation op.setParam(Param.OUTPUT_IMG, op.getParam(Param.INPUT_IMG)); } } catch (Exception e) { LOGGER.error("Image {} failed: {}", op.getParam(Param.NAME), e); //$NON-NLS-1$ op.setParam(Param.OUTPUT_IMG, op.getParam(Param.INPUT_IMG)); } } } else { clearNodeIOCache(); } return getLastNodeOutputImage(); }
@Override public void process() throws Exception { ImageElement imageElement = (ImageElement) params.get(P_IMAGE_ELEMENT); PlanarImage source = (PlanarImage) params.get(Param.INPUT_IMG); PlanarImage result = source; Boolean auto = (Boolean) params.get(P_AUTO_LEVEL); if (auto != null && auto && imageElement != null) { double min = imageElement.getMinValue(null, true); double max = imageElement.getMaxValue(null, true); double slope = 255.0 / (max -min); double yint = 255.0 - slope * max; result = ImageProcessor.rescaleToByte(source.toImageCV(), slope, yint); } params.put(Param.OUTPUT_IMG, result); }