スキップしてメイン コンテンツに移動

投稿

ラベル(double array)が付いた投稿を表示しています

Java: How to Manipulate Image as Double Array (Read and Write)

Read Image as Double Array You might think "We can use Raster#getPixel method if we would like to grab pixels, can't we?". Yes that's true. The key problem is the low performance because getPixel method internally call SampleModel and convert raw value to proper pixel value every method call. So we should call Raster#getPixels method and grab all pixels one method call. I have done similar stuffs in C# and posted on this blog. On the other hand in Java, this is a bit messy because there are a lot of related classes - Raster, ImageIO, Reader, Writer, etc ;). The simplest way I did is: read image as BufferedImage by ImageIO call BufferedImage#getRaster method call Raster#getPixels method Here is an exmple code. public static TemporalImage readImagePixelDoubleArray(InputStream is, int bitPerPixel) throws IOException{ BufferedImage image = ImageIO.read(is); Raster raster = image.getRaster(); int x = raster.getMinX(); int y = raster.