private Img<?> getUsableImage(final Img<ComplexType<?>> img) { if (m_imgBuffer.size() > 0) { return m_imgBuffer.poll(); } else { Img tmpImg = m_imgFactory.create(img, m_resultType); // wrap the result image with an ImgView in case the other image has an offset (i.e. minimum) // -> if not set, an iteration order exception will occur long[] min = new long[img.numDimensions()]; img.min(min); return ImgView.wrap(Views.translate(tmpImg, min), tmpImg.factory()); } }
/** * Create a new imgage with using the current settings. * * @return the new image */ @SuppressWarnings("unchecked") public final <T extends NativeType<T> & RealType<T>> ImgPlus<T> nextImage() { // Set up new utils m_dimList = new ArrayList<Long>(); m_axisList = new ArrayList<AxisType>(); ImgFactoryTypes facType; // select a factory if (m_factory == null) { m_factory = ImgFactoryTypes.values()[randomBoundedInt(ImgFactoryTypes.values().length - 2)]; } if (m_randomFactory) { facType = ImgFactoryTypes.values()[randomBoundedInt(ImgFactoryTypes.values().length - 2)]; } else { facType = m_factory; } final ImgFactory<T> imgFac = ImgFactoryTypes.getImgFactory(facType); // process all dimensions processDimension(m_minSizeX, m_sizeX, "X"); processDimension(m_minSizeY, m_sizeY, "Y"); processDimension(m_minSizeZ, m_sizeZ, "Z"); processDimension(m_minSizeChannel, m_sizeChannel, "Channel"); processDimension(m_minSizeT, m_sizeT, "Time"); final long[] dims = new long[m_dimList.size()]; for (int d = 0; d < m_dimList.size(); d++) { dims[d] = m_dimList.get(d); } // Type of img is selected NativeTypes type; if (m_type == null) { m_type = NativeTypes.values()[randomBoundedInt(NativeTypes.values().length - 1)]; } if (m_randomType) { type = NativeTypes.values()[randomBoundedInt(NativeTypes.values().length - 1)]; } else { type = m_type; } // create the actual image final T val = (T) NativeTypes.getTypeInstance(type); final Img<T> img = imgFac.create(dims, val); // fill the image final Cursor<T> cursor = img.cursor(); while (cursor.hasNext()) { cursor.fwd(); double result; if (m_randomFill) { double sign = 1; if (val.getMinValue() < 0) { if (Math.random() > 0.5) { // ~50% negative sign = -1; } } if (type.equals(NativeTypes.DOUBLETYPE) || type.equals(NativeTypes.FLOATTYPE)) { // random value between -1 and 1 result = Math.random() * sign; } else { // random value in type range result = Math.random() * val.getMaxValue() * sign; } } else { result = m_value; } cursor.get().setReal(result); } final ImgPlus<T> imgPlus = new ImgPlus<T>(ImgView.wrap(img, imgFac)); int d = 0; for (final AxisType a : m_axisList) { imgPlus.setAxis(new DefaultLinearAxis(a), d++); } return imgPlus; }