/**
  * Method which updates the value of the bands
  *
  * @param img New image
  * @param n Number of bands
  */
 public void updateBandsFrame(JIPImage img, int n) {
   bandSel.removeAllItems();
   if (img instanceof JIPBmpColor) {
     bandSel.addItem("COLOR-Bands RGB");
   } else if (img instanceof JIPImgGeometric) {
     bandSel.addItem("Geometric image");
   } else {
     for (int i = 0; i < ((JIPImgBitmap) img).getNumBands(); i++)
       bandSel.addItem(prop.getProperty("Band") + " " + i);
     tamFrame.setText(
         prop.getProperty("FrameSize") + ": " + img.getWidth() + "x" + img.getHeight());
   }
 }
Exemplo n.º 2
0
  public JIPImage processImg(JIPImage img) throws JIPException {
    if (img.getType() == ImageType.COLOR || img instanceof JIPImgGeometric)
      throw new JIPException("GrayToGray can not be applied to this image format");
    String p1 = getParamValueString("gray");
    ImageType tipo = Enum.valueOf(ImageType.class, p1);
    JIPImgBitmap imgBmp = (JIPImgBitmap) img;
    int nbands = imgBmp.getNumBands();
    JIPImgBitmap res =
        (JIPImgBitmap) JIPImage.newImage(nbands, img.getWidth(), img.getHeight(), tipo);
    double[] bmp, bmpRes;
    double maxInput = 0, maxOutput = 0;

    switch (img.getType()) {
      case BYTE:
        maxInput = 255;
        break;
      case FLOAT:
      case BIT:
        maxInput = 1;
        break;
      case SHORT:
        maxInput = 65535;
        break;
    }
    switch (tipo) {
      case BYTE:
        maxOutput = 255;
        break;
      case FLOAT:
      case BIT:
        maxOutput = 1;
        break;
      case SHORT:
        maxOutput = 65535;
        break;
    }
    for (int b = 0; b < nbands; b++) {
      bmp = imgBmp.getAllPixels(b);
      bmpRes = new double[bmp.length];
      for (int i = 0; i < bmp.length; i++) bmpRes[i] = maxOutput * bmp[i] / maxInput;
      res.setAllPixels(b, bmpRes);
    }

    return res;
  }