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()); } }
Planar<GrayU8> color = ConvertBufferedImage.convertFromMulti(img,null,true,GrayU8.class); savePPM(color, fileName, null); } else if( fileName.endsWith("pgm") || fileName.endsWith("PGM") ) {
/** * 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()); } }
/** * Converts a buffered image into an image of the specified type. * * @param src Input BufferedImage which is to be converted * @param orderRgb If applicable, should it adjust the ordering of each color band to maintain color consistency * @param imageType Type of image it is to be converted into * @return The image */ public static <T extends ImageBase> T convertFrom(BufferedImage src , boolean orderRgb , ImageType<T> imageType) { T out = imageType.createImage(src.getWidth(),src.getHeight()); switch( imageType.getFamily() ) { case GRAY: convertFromSingle(src, (ImageGray)out, imageType.getImageClass()); break; case PLANAR: convertFromMulti(src, (Planar) out, orderRgb, imageType.getImageClass()); break; case INTERLEAVED: convertFromInterleaved(src, (ImageInterleaved) out, orderRgb); break; default: throw new RuntimeException("Not supported yet"); } return out; }
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; }
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()+"???"); }