Java ImageIO使用CIE实验室颜色空间读取和写入压缩的Tiff文件

时间:2014-07-15 10:53:33

标签: image-processing tiff javax.imageio cielab

我实际上尝试使用CIE Lab色彩空间读取和编写压缩的tif文件。

不幸的是,如果我尝试阅读并在此之后将tif写回硬盘驱动器,颜色与光源不同。

ImageIO lib是否能够读取和写入带有CIE实验室色彩空间的压缩tif文件?

如果有可能,我担心代码有问题。在singleTiffs列表中至少有一个以这种方式创建的tiff-ImageInputStream: ImageIO.createImageInputStream(testTiff)

如果有人可以帮助我会很棒。非常感谢!

// Get iterator for input images
    Iterator<ImageInputStream> iterator = singleTiffs.iterator();

    // Get tif writer and set output to file
    Iterator writers = ImageIO.getImageWritersByFormatName("tiff");
    ImageWriter writer = (ImageWriter) writers.next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(newMultiPageTIFF);
    writer.setOutput(ios);

    // Write each image out to the new file
    boolean firstImage = true;
    while(iterator.hasNext())
    {

        ImageInputStream iis = iterator.next();

        // Get a reader for the stream
        Iterator readers = ImageIO.getImageReaders(iis);
        ImageReader reader = (ImageReader) readers.next();
        reader.setInput(iis);


        // Read the stream metadata
        // IIOMetadata streamMetadata = reader.getStreamMetadata();

        // Read the image metadata - we are assuming there is only one image
        // in the tiff
        IIOMetadata imageMetadata = reader.getImageMetadata(0);

        // Set up the writeParam
        TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
        tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_COPY_FROM_METADATA);

        BufferedImage bi = reader.read(0, null);
        IIOImage image = new IIOImage(bi, null, imageMetadata);
        if(firstImage == false)
            writer.writeInsert(-1, image, tiffWriteParam);
        else
        {
            writer.write(null, image, tiffWriteParam);
            firstImage = false;
        }

        // Done writing all images for this image
        reader.dispose();
    }

    // End writing of all files
    writer.dispose();

0 个答案:

没有答案