Inserts a single band into a multi-band image overwriting the original band

@param input Single band image
@param band Which band the image is to be inserted into
@param output The multi-band image which the input image is to be inserted into
511235
public static void insertBand( GrayS64 input, int band , InterleavedS64 output) {

		final int numBands = output.numBands;
		for (int y = 0; y < input.height; y++) {
			int indexIn = input.getStartIndex() + y * input.getStride();
			int indexOut = output.getStartIndex() + y * output.getStride() + band;
			int end = indexOut + output.width*numBands - band;
			for (; indexOut < end; indexOut += numBands , indexIn++ ) {
				output.data[indexOut] = input.data[indexIn];
			}
		}
	}
215671
@Override
    public ImageSource apply(ImageSource input) {
        if (input.isGrayscale()) {
            return input;
        }
        if (!isAlgorithm) {
            double r, g, b, gray;

            for (int i = 0; i < EffectHelper.getSize(input); i++) {
                r = EffectHelper.getRed(i, input);
                g = EffectHelper.getGreen(i, input);
                b = EffectHelper.getBlue(i, input);
                int a = EffectHelper.getAlpha(i, input);

                gray = (r * redCoefficient + g * greenCoefficient + b * blueCoefficient);

                EffectHelper.setRGB(i, (int) gray, (int) gray, (int) gray, a, input);
            }
            return input;
        } else {
            return apply(input, grayscaleMethod);
        }
    }
803432
@Override
  public void writeOutput(VisualizerInput input, Writer w)
  {
    // root html element 
    Html html = new Html();
    Head head = new Head();
    Body body = new Body();
    
    html.removeXmlns();
    html.appendChild(head);
    html.appendChild(body);
    
    try
    {
      LinkedList<String> fonts = new LinkedList<String>();
      if(input.getFont() != null)
      {
        Link linkFont = new Link();
        linkFont.setHref(input.getFont().getUrl());
        head.appendChild(linkFont);
        fonts.add(input.getFont().getName());
      }
      fonts.add("serif");

      Link linkJQueryUI = new Link();
      linkJQueryUI.setHref(input.getResourcePath("coref/jquery-ui-1.11.4.custom/jquery-ui.min.css"));
      linkJQueryUI.setRel("stylesheet");
      linkJQueryUI.setType("text/css");
      head.appendChild(linkJQueryUI);
      
      Link linkJQueryUIStructure = new Link();
      linkJQueryUIStructure.setHref(input.getResourcePath("coref/jquery-ui-1.11.4.custom/jquery-ui.structure.min.css"));
      linkJQueryUIStructure.setRel("stylesheet");
      linkJQueryUIStructure.setType("text/css");
      head.appendChild(linkJQueryUIStructure);
      
      Script scriptJquery = new Script("text/javascript");
      scriptJquery.setSrc(input.getResourcePath("coref/jquery.js"));
      head.appendChild(scriptJquery);
      
      Script scriptUI = new Script("text/javascript");
      scriptUI.setSrc(input.getResourcePath("coref/jquery-ui-1.11.4.custom/jquery-ui.min.js"));
      head.appendChild(scriptUI);
      
      Link linkCoref = new Link();
      linkCoref.setHref(input.getResourcePath("coref/coref.css"));
      linkCoref.setRel("stylesheet");
      linkCoref.setType("text/css");
      head.appendChild(linkCoref);
      
      Script scriptCoref = new Script("text/javascript");
      scriptCoref.setSrc(input.getResourcePath("coref/CorefVisualizer.js"));
      head.appendChild(scriptCoref);
     
      body.setStyle("font-family: '" + StringUtils.join(fonts, "', '") + "';");
      
      //get Info
      globalIndex = 0;
      tokensOfNode = new HashMap<String, List<String>>();
      referentList = new LinkedList<TReferent>();
      komponent = new LinkedList<TComponent>();
      referentOfToken = new HashMap<String, HashMap<Long, Integer>>();
      componentOfToken = new HashMap<String, List<Long>>();
      componenttype = new LinkedList<TComponenttype>();
      SDocument saltDoc = input.getDocument();
     
      SDocumentGraph saltGraph = saltDoc.getDocumentGraph();
      if (saltGraph == null)
      {
        body.setText("An Error occured: Could not get Graph of Result (Graph == null).");
        return;
      }
      List<SRelation<SNode,SNode>> edgeList = saltGraph.getRelations();
      if (edgeList == null)
      {
        return;
      }

      for (SRelation rawRel : edgeList)
      {
        if (includeEdge(rawRel, input.getNamespace()))
        {
          SPointingRelation rel = (SPointingRelation) rawRel;
          
          String relType = componentNameForRelation(rel);
          
          visitedNodes = new LinkedList<String>();
          //got type for this?
          boolean gotIt = false;
          int componentnr;
          for (componentnr = 0; componentnr < componenttype.size(); componentnr++)
          {
            if (componenttype.get(componentnr) != null && componenttype.get(componentnr).type != null 
              && componenttype.get(componentnr).nodeList != null
              && componenttype.get(componentnr).type.equals(relType) 
              && componenttype.get(componentnr).nodeList.contains(rel.getSource().getId()))
            {
              gotIt = true;
              break;
            }
          }
          TComponent currentComponent;
          TComponenttype currentComponenttype;
          if (gotIt)
          {
            currentComponent = komponent.get(componentnr);
            currentComponenttype = componenttype.get(componentnr);
          }
          else
          {
            currentComponenttype = new TComponenttype();
            currentComponenttype.type = relType;
            componenttype.add(currentComponenttype);
            componentnr = komponent.size();
            currentComponent = new TComponent();
            currentComponent.type = relType;
            currentComponent.tokenList = new LinkedList<String>();
            komponent.add(currentComponent);
            currentComponenttype.nodeList.add(rel.getSource().getId());
          }
          TReferent ref = new TReferent();
          ref.annotations = new HashSet<SerializableAnnotation>();
          for(SAnnotation anno : rel.getAnnotations())
          {
            ref.annotations.add(new SerializableAnnotation(anno));
          }
          ref.component = componentnr;
          referentList.add(ref);

          List<String> currentTokens = getAllTokens(rel.getSource(), componentNameForRelation(rel), 
            currentComponenttype, componentnr, input.getNamespace());

          setReferent(rel.getTarget(), globalIndex, 0);//neu
          setReferent(rel.getSource(), globalIndex, 1);//neu

          for (String s : currentTokens)
          {
            if (!currentComponent.tokenList.contains(s))
            {
              currentComponent.tokenList.add(s);
            }
          }

          globalIndex++;
        }
      }

      colorlist = new HashMap<Integer, Integer>();

      // A list containing all the generated HTML elements, one list entry
      // for each text.
      List<List<Node>> nodesPerText = new LinkedList<List<Node>>();
      
      // write output for each text separatly
      List<STextualDS> texts = saltGraph.getTextualDSs();
      if(texts != null && !texts.isEmpty())
      {
        
        for(STextualDS t : texts)
        {
          DataSourceSequence<Integer> sequence= new DataSourceSequence<>(t, 0,
            (t.getText()!= null) ? t.getText().length():0);
          List<SToken> token = saltGraph.getSortedTokenByText(saltGraph.getTokensBySequence(sequence));

          if(token != null)
          {
            boolean validText = true;
            if(Boolean.parseBoolean(input.getMappings().getProperty("hide_empty", "false")))
            {
              validText = false;
              // check if the text contains any matching annotations
              for(SToken tok : token)
              {
                /* 
                 * The token is only added to this map if an valid edge
                 * (according to the resolver trigger) conntected to 
                 * this token was found.
                 */
                if(referentOfToken.get(tok.getId()) != null 
                  && !referentOfToken.get(tok.getId()).isEmpty())
                {
                  validText = true;
                  break;
                }
              }
            }
            
            if(validText)
            {
              List<Node> nodes = outputSingleText(token, input);
              nodesPerText.add(nodes);
            }
          }
        } // end for each STexutalDS
        
        /* 
         * Append the generated output to the body, wrap in table if necessary. 
         */
        
        // present all texts as columns side by side if using multiple texts
        Table tableTexts = new Table();
        Tr trTextRow = new Tr();
        trTextRow.setCSSClass("textRow");

        // only append wrapper table if we have multiple texts
        if(nodesPerText.size() > 1)
        {
          body.appendChild(tableTexts);
          tableTexts.appendChild(trTextRow);
        }
        for(List<Node> nodes : nodesPerText)
        {
           // multi-text mode?
          if(nodesPerText.size() > 1)
          {
            Td tdSingleText = new Td();
            trTextRow.appendChild(tdSingleText);
            tdSingleText.setCSSClass("text");
            tdSingleText.appendChild(nodes);
          }
          else
          {
            body.appendChild(nodes);
          }
        }
        
      }
      else
      {
        Text errorTxt = new Text("Could not find any texts for the " 
          + input.getNamespace() + " node namespace (layer).");
        body.appendChild(errorTxt);
      }
      
      
      
      // write HTML4 transitional doctype
      w.append(new Doctype(DocumentType.HTMLTransitional).write());
      // append the html tree
      w.append(html.write());
      
    }
    catch (IOException ex)
    {
      log.error(null, ex);
    }
  }
750609
public static InterleavedU16 convert( Planar<GrayU16> input , InterleavedU16 output ) {
		if (output == null) {
			output = new InterleavedU16(input.width, input.height,input.getNumBands());
		} else {
			output.reshape(input.width,input.height,input.getNumBands());
		}

		if( BoofConcurrency.USE_CONCURRENT ) {
			ImplConvertImage_MT.convert(input,output);
		} else {
			ImplConvertImage.convert(input,output);
		}

		return output;
	}
506760
protected void initialize(T input , GrayS32 output ) {
		this.graph = output;
		final int N = input.width*input.height;

		regionSize.resize(N);
		threshold.resize(N);
		for( int i = 0; i < N; i++ ) {
			regionSize.data[i] = 1;
			threshold.data[i] = K;
			graph.data[i] = i; // assign a unique label to each pixel since they are all their own region initially
		}

		edges.reset();
		edgesNotMatched.reset();
	}
1355342
@Override
	public void setTo( Planar<T> orig) {
		if (orig.width != width || orig.height != height)
			reshape(orig.width,orig.height);
		if( orig.getBandType() != getBandType() )
			throw new IllegalArgumentException("The band type must be the same");

		int N = orig.getNumBands();
		if( N != getNumBands() ) {
			setNumberOfBands(orig.getNumBands());
		}

		for( int i = 0; i < N; i++ ) {
			bands[i].setTo(orig.getBand(i));
		}
	}
634263
public static <In extends ImageGray,Out extends ImageGray>
	Out checkDeclare(In input, Out output , Class<Out> typeOut) {
		if (output == null) {
			output = (Out) GeneralizedImageOps.createSingleBand(typeOut, input.width, input.height);
		} else {
			output.reshape(input.width, input.height);
		}
		return output;
	}
991515
public static void copyInputToOutput(final InputStream input, final OutputStream output) throws IOException {
        final BufferedInputStream in = new BufferedInputStream(input);
        final BufferedOutputStream out = new BufferedOutputStream(output);
        final byte buffer[] = new byte[8192];
        for (int count = 0; count != -1;) {
            count = in.read(buffer, 0, 8192);
            if (count != -1) {
                out.write(buffer, 0, count);
            }
        }

        try {
            in.close();
            out.close();
        } catch (final IOException ex) {
            throw new IOException("Closing file streams, " + ex.getMessage());
        }
    }
937815
public static <T extends ImageGray<T>> void stdDev(Planar<T> input, T output, @Nullable T avg) {
		stdDev(input, output, avg, 0, input.getNumBands() - 1);
	}
470890
public static void format(final Source input, final Result output) {
        try {
            // Use an identity transformation to write the source to the result.
            final Transformer transformer = createTransformer(null);
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");

            transformer.transform(input, output);
        } catch (final Exception ex) {
            LOGGER.error("Problem formatting DOM representation.", ex);
        }
    }
576425
public void process(Planar<T> input, Planar<T> output) {

		int N = input.getNumBands();
		for( int i = 0; i < N; i++ ) {
			this.output[i] = FactoryGImageGray.wrap(output.getBand(i),this.output[i]);
			interp[i].setImage(input.getBand(i));
		}

		int indexMap = 0;
		for( int i = 0; i < output.height; i++ ) {
			int indexOut = output.startIndex + i*output.stride;
			for( int j = 0; j < output.width; j++ , indexOut++,indexMap++ ) {
				Point2D_F32 p = mapPixels[indexMap];
				if( p != null ) {
					for( int k = 0; k < N; k++ ) {
						this.output[k].set(indexOut, interp[k].get( p.x, p.y));
					}
				}
			}
		}
	}
552138
public static boolean write(Image image, ImageWriter writer, ImageOutputStream output, float quality) {
		if (writer == null) {
			return false;
		}

		writer.setOutput(output);
		final RenderedImage renderedImage = toRenderedImage(image);
		// 设置质量
		ImageWriteParam imgWriteParams = null;
		if (quality > 0 && quality < 1) {
			imgWriteParams = writer.getDefaultWriteParam();
			if (imgWriteParams.canWriteCompressed()) {
				imgWriteParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
				imgWriteParams.setCompressionQuality(quality);
				final ColorModel colorModel = renderedImage.getColorModel();// ColorModel.getRGBdefault();
				imgWriteParams.setDestinationType(new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(16, 16)));
			}
		}

		try {
			if (null != imgWriteParams) {
				writer.write(null, new IIOImage(renderedImage, null, null), imgWriteParams);
			} else {
				writer.write(renderedImage);
			}
			output.flush();
		} catch (IOException e) {
			throw new IORuntimeException(e);
		} finally {
			writer.dispose();
		}
		return true;
	}
697717
public static void moveBandsElemnts(int yOffset, JRDesignBand band) {
		if (band == null)
			return;

		for (JRChild jrChild : band.getChildren()) {
			JRDesignElement elem = (JRDesignElement) jrChild;
			elem.setY(elem.getY() + yOffset);
		}
	}
636862
public static void bufferRgbToMsU8( byte []input , Planar<GrayU8> output ) {
		GrayU8 band0 = output.getBand(0);
		GrayU8 band1 = output.getBand(1);
		GrayU8 band2 = output.getBand(2);

		int indexIn = 0;
		for( int y = 0; y < output.height; y++ ) {
			int indexOut = output.startIndex + y*output.stride;
			for( int x = 0; x < output.width; x++ , indexOut++ ) {
				band0.data[indexOut] = input[indexIn++];
				band1.data[indexOut] = input[indexIn++];
				band2.data[indexOut] = input[indexIn++];
			}
		}
	}
641
public static <T extends ImageBase<T>, O extends ImageBase>
	void add(T inputA, T inputB, O output) {
		if( inputA instanceof ImageGray) {
			if (GrayU8.class == inputA.getClass()) {
				PixelMath.add((GrayU8) inputA, (GrayU8) inputB, (GrayU16) output);
			} else if (GrayS8.class == inputA.getClass()) {
				PixelMath.add((GrayS8) inputA, (GrayS8) inputB, (GrayS16) output);
			} else if (GrayU16.class == inputA.getClass()) {
				PixelMath.add((GrayU16) inputA, (GrayU16) inputB, (GrayS32) output);
			} else if (GrayS16.class == inputA.getClass()) {
				PixelMath.add((GrayS16) inputA, (GrayS16) inputB, (GrayS32) output);
			} else if (GrayS32.class == inputA.getClass()) {
				PixelMath.add((GrayS32) inputA, (GrayS32) inputB, (GrayS32) output);
			} else if (GrayS64.class == inputA.getClass()) {
				PixelMath.add((GrayS64) inputA, (GrayS64) inputB, (GrayS64) output);
			} else if (GrayF32.class == inputA.getClass()) {
				PixelMath.add((GrayF32) inputA, (GrayF32) inputB, (GrayF32) output);
			} else if (GrayF64.class == inputA.getClass()) {
				PixelMath.add((GrayF64) inputA, (GrayF64) inputB, (GrayF64) output);
			} else {
				throw new IllegalArgumentException("Unknown image Type: " + inputA.getClass().getSimpleName());
			}
		} else if (inputA instanceof Planar) {
			Planar inA = (Planar)inputA;
			Planar inB = (Planar)inputB;
			Planar out = (Planar)output;

			for (int i = 0; i < inA.getNumBands(); i++) {
				add(inA.getBand(i),inB.getBand(i),out.getBand(i));
			}
		}
	}
469099
public static void changeSign(DMatrixD1 input , DMatrixD1 output)
    {
        output.reshape(input.numRows,input.numCols);

        final int size = input.getNumElements();

        for( int i = 0; i < size; i++ ) {
            output.data[i] = -input.data[i];
        }
    }
1059336
public static <T extends ImageBase<T>> void log(T input , T output ) {
		if( input instanceof ImageGray ) {
			if (GrayF32.class == input.getClass()) {
				PixelMath.log((GrayF32) input, (GrayF32) output);
			} else if (GrayF64.class == input.getClass()) {
				PixelMath.log((GrayF64) input, (GrayF64) output);
			} else {
				throw new IllegalArgumentException("Unknown image Type: " + input.getClass().getSimpleName());
			}
		} else if( input instanceof Planar ) {
			Planar in = (Planar)input;
			Planar out = (Planar)output;

			for (int i = 0; i < in.getNumBands(); i++) {
				log( in.getBand(i), out.getBand(i));
			}
		}
	}