Tabnine Logo
ConvertBufferedImage
Code IndexAdd Tabnine to your IDE (free)

How to use
ConvertBufferedImage
in
boofcv.io.image

Best Java code snippets using boofcv.io.image.ConvertBufferedImage (Showing top 20 results out of 315)

origin: org.boofcv/io

/**
 * Converts a buffered image into an image of the specified type.  In a 'dst' image is provided
 * it will be used for output, otherwise a new image will be created.
 */
public static <T extends ImageGray> T convertFromSingle(BufferedImage src, T dst, Class<T> type) {
  if (type == GrayU8.class) {
    return (T) convertFrom(src, (GrayU8) dst);
  } else if( GrayI16.class.isAssignableFrom(type) ) {
    return (T) convertFrom(src, (GrayI16) dst,(Class)type);
  } else if (type == GrayF32.class) {
    return (T) convertFrom(src, (GrayF32) dst);
  } else {
    throw new IllegalArgumentException("Unknown type " + type);
  }
}
origin: org.boofcv/demonstrations

    public void run() {
      images.clear();
      images.add(ConvertBufferedImage.convertTo(output,null,true));
      images.add(ConvertBufferedImage.convertTo(noisy,null,true));
      images.add(ConvertBufferedImage.convertTo(input,null,true));
      info.reset();
      doRefreshAll();
    }});
}
origin: org.boofcv/demonstrations

public void process(BufferedImage input) {
  this.input = input;
  grayImage = ConvertBufferedImage.convertFromSingle(input, null, imageType);
  workImage = new BufferedImage(input.getWidth(), input.getHeight(), BufferedImage.TYPE_INT_BGR);
  SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      doRefreshAll();
    }
  });
}
origin: org.boofcv/boofcv-swing

private void renderPinhole() {
  if( distortImage == null )
    return;
  imageRendered.reshape(pinholeModel.width,pinholeModel.height);
  distortImage.apply(imageFisheye,imageRendered);
  bufferedRendered = ConvertBufferedImage.checkDeclare(
      imageRendered.width,imageRendered.height,bufferedRendered,BufferedImage.TYPE_INT_RGB);
  ConvertBufferedImage.convertTo(imageRendered,bufferedRendered,true);
}
origin: org.boofcv/io

/**
 * Converts a buffered image into an image of the specified type.
 * 
 * @param src Input BufferedImage which is to be converted
 * @param dst The image which it is being converted into
 * @param orderRgb If applicable, should it adjust the ordering of each color band to maintain color consistency
 */
public static <T extends ImageBase> void convertFrom(BufferedImage src, T dst , boolean orderRgb) {
  if( dst instanceof ImageGray) {
    ImageGray sb = (ImageGray)dst;
    convertFromSingle(src, sb, (Class<ImageGray>) sb.getClass());
  } else if( dst instanceof Planar) {
    Planar ms = (Planar)dst;
    convertFromMulti(src,ms,orderRgb,ms.getBandType());
  } else if( dst instanceof ImageInterleaved ) {
    convertFromInterleaved(src, (ImageInterleaved) dst, orderRgb);
  } else {
    throw new IllegalArgumentException("Unknown type " + dst.getClass().getSimpleName());
  }
}
origin: org.boofcv/demonstrations

@Override
public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {
  System.out.flush();
  original = ConvertBufferedImage.checkCopy(buffered,original);
  work = ConvertBufferedImage.checkDeclare(buffered,work);
  final double timeInSeconds;
  synchronized (lockProcessing) {
    long before = System.nanoTime();
    detector.process((GrayF32)input);
    long after = System.nanoTime();
    timeInSeconds = (after-before)*1e-9;
  }
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      controls.setProcessingTime(timeInSeconds);
      viewUpdated();
    }
  });
}
origin: org.boofcv/boofcv-swing

private void undoRadialDistortion(BufferedImage image) {
  if( undoRadial == null )
    return;
  ConvertBufferedImage.convertFrom(image,origMS,true);
  if( correctedMS.getNumBands() != origMS.getNumBands() )
    correctedMS.setNumberOfBands(origMS.getNumBands());
  correctedMS.reshape(origMS.width,origMS.height);
  for( int i = 0; i < origMS.getNumBands(); i++ ) {
    GrayF32 in = origMS.getBand(i);
    GrayF32 out = correctedMS.getBand(i);
    undoRadial.apply(in,out);
  }
  undistorted = ConvertBufferedImage.checkDeclare(origMS.width,origMS.height,undistorted,image.getType());
  ConvertBufferedImage.convertTo(correctedMS,undistorted,true);
}
origin: org.boofcv/io

  Planar<GrayU8> color = ConvertBufferedImage.convertFromMulti(img,null,true,GrayU8.class);
  savePPM(color, fileName, null);
} else if( fileName.endsWith("pgm") || fileName.endsWith("PGM") ) {
  GrayU8 gray = ConvertBufferedImage.convertFrom(img, (GrayU8) null);
  savePGM(gray, fileName);
}else
origin: org.boofcv/visualize

private void undoRadialDistortion(BufferedImage image) {
  ConvertBufferedImage.convertFromMulti(image, origMS,true, GrayF32.class);
  for( int i = 0; i < origMS.getNumBands(); i++ ) {
    GrayF32 in = origMS.getBand(i);
    GrayF32 out = correctedMS.getBand(i);
    undoRadial.apply(in,out);
  }
  if( correctedMS.getNumBands() == 3 )
    ConvertBufferedImage.convertTo(correctedMS,undistorted,true);
  else if( correctedMS.getNumBands() == 1 )
    ConvertBufferedImage.convertTo(correctedMS.getBand(0),undistorted);
  else
    throw new RuntimeException("What kind of image has "+correctedMS.getNumBands()+"???");
}
origin: org.boofcv/demonstrations

private void setDescriptorInput() {
  if( describe != null )  {
    if( describe.getImageType().getFamily() == ImageType.Family.GRAY) {
      T input = ConvertBufferedImage.convertFromSingle(image, null, imageType);
      describe.setImage(input);
    } else {
      Planar<T> input = ConvertBufferedImage.convertFromPlanar(image, null, true, imageType);
      describe.setImage(input);
    }
  }
}
origin: org.boofcv/demonstrations

@Override
protected void handleInputChange(int source, InputMethod method, int width, int height)
{
  imageBinary.reshape(width, height);
  visualizedBinary = ConvertBufferedImage.checkDeclare(width, height, visualizedBinary,BufferedImage.TYPE_INT_BGR);
}
origin: org.boofcv/demonstrations

  public static void main(String[] args) {
    BufferedImage original = UtilImageIO.loadImage(UtilIO.pathExample("simple_objects.jpg"));

    Planar<GrayF32> input = new Planar<>(GrayF32.class,
        original.getWidth(),original.getHeight(),3);

    ConvertBufferedImage.convertFromPlanar(original,input,true,GrayF32.class);

    Planar<GrayF32> output = new Planar<>(GrayF32.class,
        original.getWidth()/3,original.getHeight()/3,3);
    Planar<GrayF32> output2 = new Planar<>(GrayF32.class,
        original.getWidth()/3,original.getHeight()/3,3);

    AverageDownSampleOps.down(input, output);
    new FDistort(input,output2).scaleExt().apply();

    BufferedImage outputFull = ConvertBufferedImage.convertTo_F32(output, null, true);
    BufferedImage outputFull2 = ConvertBufferedImage.convertTo_F32(output2, null, true);

    ShowImages.showWindow(original,"Original");
    ShowImages.showWindow(outputFull,"3x small average");
    ShowImages.showWindow(outputFull2,"3x small bilinear");
  }
}
origin: org.boofcv/demonstrations

public void process( final BufferedImage image ) {
  input.reshape(image.getWidth(),image.getHeight());
  output.reshape(image.getWidth(),image.getHeight());
  ConvertBufferedImage.convertFromPlanar(image, input,true, GrayF32.class);
  SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      setInputImage(image);
      doRefreshAll();
    }});
}
origin: org.boofcv/visualize

public void setSelected( int selected ) {
  this.selectedImage = selected;
  this.isUndistorted = false;
  if( origMS == null ) {
    BufferedImage image = images.get(selected);
    // the number of bands can be difficult to ascertain without digging deep into the data structure
    // so just declare a new one using convert
    origMS = ConvertBufferedImage.convertFromMulti(image,null,true,GrayF32.class);
    correctedMS = ConvertBufferedImage.convertFromMulti(image,null,true,GrayF32.class);
    undistorted = new BufferedImage(image.getWidth(),image.getHeight(),image.getType());
  }
}
origin: org.boofcv/demonstrations

ConvertBufferedImage.convertFrom(buff[0], color1, true);
ConvertBufferedImage.convertFrom(buff[1], color2, true);
    rectColor1, rectColor2,rectMask, rectifiedK, rectifiedR);
visualRect1 = ConvertBufferedImage.checkDeclare(
    rectColor1.width, rectColor1.height, visualRect1, visualRect1.getType());
visualRect2 = ConvertBufferedImage.checkDeclare(
    rectColor2.width, rectColor2.height, visualRect2, visualRect2.getType());
ConvertBufferedImage.convertTo(rectColor1, visualRect1, true);
ConvertBufferedImage.convertTo(rectColor2, visualRect2, true);
BoofSwingUtil.invokeNowOrLater(() -> {
  rectifiedPanel.setImages(visualRect1, visualRect2);
visualDisparity = ConvertBufferedImage.checkDeclare(
    disparity.width,disparity.height,visualDisparity,visualDisparity.getType());
origin: org.boofcv/io

public static <T extends ImageBase> T convertFrom(BufferedImage src , boolean orderRgb , T output ) {
  ImageType<T> imageType = output.getImageType();
  switch( imageType.getFamily() ) {
    case GRAY:
      convertFromSingle(src, (ImageGray)output, imageType.getImageClass());
      break;
    case PLANAR:
      convertFromMulti(src, (Planar) output, orderRgb, imageType.getImageClass());
      break;
    case INTERLEAVED:
      convertFromInterleaved(src, (ImageInterleaved) output, orderRgb);
      break;
    default:
      throw new RuntimeException("Not supported yet");
  }
  return output;
}
origin: org.boofcv/demonstrations

  @Override
  public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {

    synchronized (this) {
      original = ConvertBufferedImage.checkCopy(buffered, original);
      work = ConvertBufferedImage.checkDeclare(buffered, work);
    }

//        SwingUtilities.invokeLater(new Runnable() {
//            @Override
//            public void run() {
//                Dimension d = guiImage.getPreferredSize();
//                if( d.getWidth() < buffered.getWidth() || d.getHeight() < buffered.getHeight() ) {
//                    guiImage.setPreferredSize(new Dimension(buffered.getWidth(), buffered.getHeight()));
//                }
//            }});

    synchronized (this) {
      inputToBinary.process((T)input,binary);
      contourAlg.process(binary,labeled);
    }

    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        viewUpdated();
      }
    });
  }

origin: org.boofcv/boofcv-swing

@Override
public synchronized void paintComponent(Graphics g) {
  super.paintComponent(g);
  projectScene();
  imageOutput = ConvertBufferedImage.checkDeclare(imageRgb.width,imageRgb.height,imageOutput,BufferedImage.TYPE_INT_RGB);
  DataBufferInt buffer = (DataBufferInt)imageOutput.getRaster().getDataBuffer();
  System.arraycopy(imageRgb.data,0,buffer.getData(),0,imageRgb.width*imageRgb.height);
  g.drawImage(imageOutput,0,0,null);
}
origin: hazelcast/hazelcast-jet-demos

/**
 * The actual classification of the images by using the pre-trained model.
 */
private static Entry<String, Double> classifyWithModel(ImageClassifierVggCifar10 classifier, BufferedImage image) {
  Planar<GrayF32> planar = new Planar<>(GrayF32.class, image.getWidth(), image.getHeight(), 3);
  ConvertBufferedImage.convertFromPlanar(image, planar, true, GrayF32.class);
  classifier.classify(planar);
  return classifier.getAllResults().stream()
      .map(score -> entry(classifier.getCategories().get(score.category), score.score))
      .max(Comparator.comparing(Entry::getValue)).get();
}
origin: org.boofcv/boofcv-WebcamCapture

@Override
public T next() {
  if( bufferedImage == null )
    bufferedImage = webcam.getImage();
  ConvertBufferedImage.convertFrom(bufferedImage, output, true);
  return output;
}
boofcv.io.imageConvertBufferedImage

Javadoc

Functions for converting to and from BufferedImage.

Most used methods

  • convertFrom
    Converts a buffered image into an image of the specified type.
  • convertTo
    Draws the component into a BufferedImage.
  • convertFromSingle
  • checkDeclare
  • convertFromMulti
    Converts the buffered image into an Planar image of the specified type.
  • convertFromPlanar
  • convertTo_F32
    Converts a Planar GrayF32 into a BufferedImage.
  • checkCopy
  • checkInputs
    If null the dst is declared, otherwise it checks to see if the 'dst' as the same shape as 'src'.
  • convertFromInterleaved
  • convertTo_U8
    Converts a Planar GrayU8 into a BufferedImage.
  • orderBandsBufferedFromRGB
    The image the BufferedImage was created from had RGB or RGBA color order. This swaps the bytes aroun
  • convertTo_U8,
  • orderBandsBufferedFromRGB,
  • orderBandsBufferedFromRgb,
  • orderBandsIntoBuffered,
  • orderBandsIntoRGB,
  • swapBandOrder

Popular in Java

  • Reading from database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • getResourceAsStream (ClassLoader)
  • getSupportFragmentManager (FragmentActivity)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now