atom feed25 messages in net.java.dev.jai-imageio.interestRe: [JAI-IMAGEIO] Read Tiff, Write Ti...
FromSent OnAttachments
jai-...@javadesktop.orgNov 6, 2007 3:39 pm 
robert engelsNov 6, 2007 3:45 pm 
jai-...@javadesktop.orgNov 6, 2007 6:25 pm 
jai-...@javadesktop.orgNov 6, 2007 6:32 pm 
jai-...@javadesktop.orgNov 7, 2007 1:40 am 
jai-...@javadesktop.orgNov 7, 2007 3:04 am 
jai-...@javadesktop.orgNov 7, 2007 3:15 am 
jai-...@javadesktop.orgNov 7, 2007 4:02 am 
jai-...@javadesktop.orgNov 7, 2007 7:10 am 
jai-...@javadesktop.orgNov 7, 2007 7:29 am 
robert engelsNov 7, 2007 7:35 am 
robert engelsNov 7, 2007 7:51 am 
jai-...@javadesktop.orgNov 7, 2007 7:54 am 
robert engelsNov 7, 2007 7:56 am 
robert engelsNov 7, 2007 9:06 am 
Bob DeenNov 7, 2007 2:51 pm 
robert engelsNov 7, 2007 3:22 pm 
Andrey KuznetsovNov 7, 2007 3:39 pm 
robert engelsNov 7, 2007 3:42 pm 
Andrey KuznetsovNov 7, 2007 4:01 pm 
robert engelsNov 7, 2007 4:17 pm 
Andrey KuznetsovNov 7, 2007 4:20 pm 
robert engelsNov 7, 2007 4:32 pm 
mja...@union06.deNov 7, 2007 10:49 pm 
robert engelsNov 8, 2007 10:34 am 
Subject:Re: [JAI-IMAGEIO] Read Tiff, Write Tiff... why are the files different size
From:robert engels (reng@ix.netcom.com)
Date:Nov 8, 2007 10:34:50 am
List:net.java.dev.jai-imageio.interest

Yep, same problem (but as stated in another email, works with JPEG2000).

I used the following to test:

import java.io.File;

import javax.imageio.*; import javax.imageio.stream.ImageOutputStream;

import junit.framework.TestCase;

public class TestWriteImage extends TestCase { public static void main(String[] args) throws Exception { File f = new File("painting.jpg"); File f0 = new File("painting0.jpg");

ImageReader r = ImageIO.getImageReadersByFormatName("jpeg").next(); r.setInput(ImageIO.createImageInputStream(f));

IIOImage img = r.readAll(0,r.getDefaultReadParam());

for(int i=0;i<10;i++) { ImageOutputStream os = ImageIO.createImageOutputStream(f0); ImageWriter w = ImageIO.getImageWriter(r); w.setOutput(os); w.write(null,img,w.getDefaultWriteParam()); w.dispose(); os.close();

r.setInput(ImageIO.createImageInputStream(f0)); img = r.readAll(0,r.getDefaultReadParam()); } } }

On Nov 8, 2007, at 12:49 AM, mja@union06.de wrote:

Robert,

did you also check it with IIOImage including metadata? Here you read the image without any information about the incoming compression/quality and then write the target file without giving its target compression. BufferedImage will loose any information. Or did I go totally wrong and this was part of the former discussion?

Kind regards, Marco

Sadly, this is not true....

I used the following test program:

import java.awt.image.BufferedImage; import java.io.File;

import javax.imageio.ImageIO;

import junit.framework.TestCase;

public class TestWriteImage extends TestCase { public static void main(String[] args) throws Exception { BufferedImage img = ImageIO.read(new File("painting.jpg")); for(int i=0;i<20;i++) { ImageIO.write(img,"jpeg",new File("painting0.jpg")); img = ImageIO.read(new File("painting.jpg")); } } }

The resulting 'painting0.jpg' image is all black...

BUT, if you use JPEG2000, you can set the "bit rate", so that repeated compressions result in the same size/quality file...

Using the following code:

import java.awt.image.BufferedImage; import java.io.File;

import javax.imageio.*; import javax.imageio.stream.ImageOutputStream;

import com.sun.media.imageio.plugins.jpeg2000.J2KImageWriteParam;

import junit.framework.TestCase;

public class TestWriteImage extends TestCase { public static void main(String[] args) throws Exception { BufferedImage img = ImageIO.read(new File("painting.jpg")); File f0 = new File("painting0.jpg"); for(int i=0;i<20;i++) { System.out.println("invocation "+i); J2KImageWriteParam p = new J2KImageWriteParam(); p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); p.setEncodingRate(.5); f0.delete(); ImageWriter w = ImageIO.getImageWritersByFormatName ("jpeg2000").next(); ImageOutputStream ios =ImageIO.createImageOutputStream(f0); w.setOutput(ios); w.write(null,new IIOImage(img,null,null),p); w.dispose(); ios.close(); img = ImageIO.read(f0); } } }

At some point the On Nov 7, 2007, at 9:57 AM, robert engels wrote:

Although,

If you use similar JPEG compression ratio's I think you might end up getting similar (although not exact) images. Because the source image is already compression, it has already reduced the frequencies in the image, so when the image is compressed again, the image is already at that frequency level.

On Nov 7, 2007, at 9:54 AM, jai-@javadesktop.org wrote:

It is my understanding:

if you open a JPEG file, AND either

1. write it as a TIFF (using JPEG in TIFF compression, with compression turned on), you are going to get a TIFF that looks much worse than the original JPEG 2. write it as a TIFF with compression turned off, you are going to get a file that is much larger than the original JPEG.

In this case the original file is a TIFF though... Can I somehow insert that "as is" into a new mulipage TIFF without having to deal with making any changes to the way it was originally compressed in the single page TIFF?

-Mary [Message sent by forum member 'chickiboo' (chickiboo)]

http://forums.java.net/jive/thread.jspa?messageID=244306