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; }
private void loadArrays(DicomImageElement img, DataExplorerModel model) { // Do not load an image if another process already loading it if (preloading && !img.isLoading()) { Boolean cache = (Boolean) img.getTagValue(TagW.ImageCache); if (cache == null || !cache) { long start = System.currentTimeMillis(); try { img.getImage(); } catch (OutOfMemoryError e) { LOGGER.error("Out of memory when loading image: {}", img, e); //$NON-NLS-1$ CvUtil.runGarbageCollectorAndWait(50); return; } long stop = System.currentTimeMillis(); LOGGER.debug("Reading time: {} ms of image: {}", stop - start, img); //$NON-NLS-1$ if (model != null) { model.firePropertyChange(new ObservableEvent(ObservableEvent.BasicAction.ADD, model, null, new SeriesEvent(SeriesEvent.Action.PRELOADING, series, img))); } } } }
addCrosshairLine(layer, pts2, color2, centerPt); PlanarImage dispImg = image.getImage(); if (dispImg != null) { Rectangle2D rect = new Rectangle2D.Double(0, 0, dispImg.width() * image.getRescaleX(),
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; }
destinationDir.mkdirs(); PlanarImage image = img.getImage(null); if (image != null && !img16) { image = img.getRenderedImage(image);
public Mat getMaskedDosePlaneHist(double slicePosition, Mat mask, int maxDose) { DicomImageElement dosePlane = (DicomImageElement) this.getDosePlaneBySlice(slicePosition); int rows = dosePlane.getImage().toMat().rows(); int cols = dosePlane.getImage().toMat().cols(); // Calculate dose matrix for OpenCV Mat src = new Mat(rows, cols, CvType.CV_32FC1); dosePlane.getImage().toMat().convertTo(src, CvType.CV_32FC1); Scalar scalar = new Scalar(this.doseGridScaling * 100); Mat doseMatrix = new Mat(rows, cols, CvType.CV_32FC1); multiply(src, scalar, doseMatrix); List<Mat> doseMatrixVector = new ArrayList<>(); doseMatrixVector.add(doseMatrix); // Masked dose plan histogram Mat hist = new Mat(); // Number of histogram bins MatOfInt histSize = new MatOfInt(maxDose); // Dose varies from 0 to maxDose MatOfFloat histRange = new MatOfFloat(0, maxDose); // Only one 0-th channel MatOfInt channels = new MatOfInt(0); // Ned to change the structure dose mask type vor OpenCV histogram calculation Mat maskSrc = new Mat(mask.rows(), mask.cols(), CvType.CV_8U); mask.convertTo(maskSrc, CvType.CV_8U); Imgproc.calcHist(doseMatrixVector, channels, maskSrc, hist, histSize, histRange); return hist; }
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); }
int imageDataType = ImageConversion.convertToDataType(image.getImage().type()); PresetWindowLevel preset = (PresetWindowLevel) node.getParam(ActionW.PRESET.cmd()); boolean defaultPreset = LangUtil.getNULLtoTrue((Boolean) node.getParam(ActionW.DEFAULT_PRESET.cmd()));
PlanarImage image = dcm.getImage(null, false); if (image == null) { abort[0] = true;
private static void updateImage(ViewCanvas<DicomImageElement> view2D, Filter<DicomImageElement> sopInstanceUIDFilter, int newImageIndex) { int imgIndex = newImageIndex < 0 ? 0 : newImageIndex; if (view2D == view2D.getEventManager().getSelectedViewPane()) { /* * Update the sliceAction action according to nearest image when the filter hides the image of the previous * state. And update the action min and max. */ ActionState seqAction = view2D.getEventManager().getAction(ActionW.SCROLL_SERIES); if (seqAction instanceof SliderCineListener) { SliderChangeListener moveTroughSliceAction = (SliderChangeListener) seqAction; moveTroughSliceAction.setSliderMinMaxValue(1, view2D.getSeries().size(sopInstanceUIDFilter), imgIndex + 1); } } DicomImageElement newImage = null; if (view2D.getSeries() != null) { newImage = view2D.getSeries().getMedia(imgIndex, sopInstanceUIDFilter, view2D.getCurrentSortComparator()); } if (newImage != null && !newImage.isImageAvailable()) { newImage.getImage(); } ((View2d) view2D).setImage(newImage); } }
image.getImage();
PlanarImage imgPl = image.getImage(null); if (imgPl != null) { PlanarImage img = image.getRenderedImage(imgPl);