public static Rectangle getBounds(PlanarImage img) { return new Rectangle(0, 0, img.width(), img.height()); }
@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; 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 String getToolTips() { StringBuilder toolTips = new StringBuilder(); toolTips.append("<html>"); //$NON-NLS-1$ E media = this.getMedia(MEDIA_POSITION.MIDDLE, null, null); if (media instanceof ImageElement) { ImageElement image = (ImageElement) media; PlanarImage img = image.getImage(); if (img != null) { toolTips.append(Messages.getString("Series.img_size")); //$NON-NLS-1$ toolTips.append(StringUtil.COLON_AND_SPACE); toolTips.append(img.width()); toolTips.append('x'); toolTips.append(img.height()); } } toolTips.append("</html>"); //$NON-NLS-1$ return toolTips.toString(); }
@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); }
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; }
@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); }
int height = sourceImage.height();
private Predicate<AcquireImageInfo> oversizedImages() { return acqImg -> { PlanarImage img = acqImg.getImage().getImage(acqImg.getPostProcessOpManager()); return img.width() > Resolution.ULTRA_HD.maxSize || img.height() > Resolution.ULTRA_HD.maxSize; }; }
public boolean hasSameSize(ImageElement image) { if (image != null) { PlanarImage img = getImage(); PlanarImage img2 = image.getImage(); if (img != null && img2 != null && getRescaleWidth(img.width()) == image.getRescaleWidth(img2.width()) && getRescaleHeight(img.height()) == image.getRescaleHeight(img2.height())) { return true; } } return false; }
if (dispImg != null) { Rectangle2D rect = new Rectangle2D.Double(0, 0, dispImg.width() * image.getRescaleX(), dispImg.height() * image.getRescaleY()); addRectangle(layer, rect, axial ? Color.RED : sagittal ? Color.BLUE : Color.GREEN);
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 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; } }
Rectangle2D rect = new Rectangle2D.Double(0, 0, displayImage.width() - 1, displayImage.height() - 1); rect = rect.createIntersection((Rectangle2D) clip); if (rect.isEmpty()) {
private PlanarImage readImage(File file, boolean createTiledLayout) throws Exception { PlanarImage img = null; if (file.getPath().endsWith(".wcv")) { //$NON-NLS-1$ img = new FileRawImage(file).read(); } else if (codec instanceof NativeOpenCVCodec) { img = ImageProcessor.readImageWithCvException(file); if (img == null) { // Try ImageIO img = readImageIOImage(file); } } else { img = readImageIOImage(file); } if (img != null && image != null) { image.setTag(TagW.ImageWidth, img.width()); image.setTag(TagW.ImageHeight, img.height()); } return img; }
protected Rectangle getImageBounds(E img) { if (img != null) { PlanarImage source = getPreprocessedImage(img); // Get the displayed width (adapted in case of the aspect ratio is not 1/1) boolean nosquarePixel = MathUtil.isDifferent(img.getRescaleX(), img.getRescaleY()); int width = source == null || nosquarePixel ? img.getRescaleWidth(getImageSize(img, TagW.ImageWidth, TagW.get("Columns"))) : source.width(); //$NON-NLS-1$ int height = source == null || nosquarePixel ? img.getRescaleHeight(getImageSize(img, TagW.ImageHeight, TagW.get("Rows"))) : source.height(); //$NON-NLS-1$ return new Rectangle(0, 0, width, height); } return new Rectangle(0, 0, 512, 512); }
Mat mean = new Mat(img.height(), img.width(), CvType.CV_32F); img.toMat().convertTo(mean, CvType.CV_32F); int numbSrc = sources.size(); ImageElement imgElement = sources.get(i); PlanarImage image = imgElement.getImage(null, false); if (image.width() != img.width() && image.height() != img.height()) { continue; Mat floatImage = new Mat(img.height(), img.width(), CvType.CV_32F); image.toMat().convertTo(floatImage, CvType.CV_32F); Imgproc.accumulate(floatImage, mean);
if (img != null && (img.width() > ImageFiler.TILESIZE || img.height() > ImageFiler.TILESIZE) && !mimeType.contains("dicom")) { //$NON-NLS-1$ File outFile = imgCachePath.toFile();
if (bestfit || originSize == null) { canvasWidth = img.width() * image.getImage().getRescaleX(); canvasHeight = img.height() * image.getImage().getRescaleY(); } else { canvasWidth = originSize.getWidth() / originZoom;
private Pair<double[], double[]> calculatePixelLookupTable(DicomImageElement dicomImage) { double deltaI = dicomImage.getSliceGeometry().getVoxelSpacingArray()[0]; double deltaJ = dicomImage.getSliceGeometry().getVoxelSpacingArray()[1]; double[] rowDirection = dicomImage.getSliceGeometry().getRowArray(); double[] columnDirection = dicomImage.getSliceGeometry().getColumnArray(); double[] position = dicomImage.getSliceGeometry().getTLHCArray(); // DICOM C.7.6.2.1 Equation C.7.6.2.1-1. double[][] m = { { rowDirection[0] * deltaI, columnDirection[0] * deltaJ, 0, position[0] }, { rowDirection[1] * deltaI, columnDirection[1] * deltaJ, 0, position[1] }, { rowDirection[2] * deltaI, columnDirection[2] * deltaJ, 0, position[2] }, { 0, 0, 0, 1 } }; RealMatrix matrix = MatrixUtils.createRealMatrix(m); double[] x = new double[dicomImage.getImage().width()]; // column index to the image plane. for (int i = 0; i < dicomImage.getImage().width(); i++) { x[i] = matrix.multiply(MatrixUtils.createColumnRealMatrix(new double[] { i, 0, 0, 1 })).getRow(0)[0]; } double[] y = new double[dicomImage.getImage().height()]; // row index to the image plane for (int j = 0; j < dicomImage.getImage().height(); j++) { y[j] = matrix.multiply(MatrixUtils.createColumnRealMatrix(new double[] { 0, j, 0, 1 })).getRow(1)[0]; } return new Pair<>(x, y); }