5 Replies Latest reply on Jun 25, 2013 2:52 AM by 1d5e47fb-1065-4e46-9b53-38f39767358f Branched to a new discussion.

    Tiff Image with Spot Channel

      I am trying to create a Tiff image in RGB an an extra channel/band for the spot channel (the same way I can do in Photoshop).

      It seems to me that JAI does not recognize a Spot Channel.

      Does anybody know how to go through this?

      Thanks a lot
        • 1. Re: Tiff Image with Spot Channel
          1) Install JAI-ImageIO if you have not already done so. You want its TIFF reader and writer.

          2) Create a ComponentColorModel with the desired number of channels. A key component of this is a custom ColorSpace that takes all the channels and returns a meaningful rgb value. If you do not plan on displaying the image then is does not need to be meaningful.

          2) Create a compatible raster via ColorModel#createCompatibleWritableRaster

          3) Create a BufferedImage using the constructor that takes a ColorModel and a WritableRaster. This will result in a TYPE_CUSTOM image. If your ColorSpace is meaningful then you can display it, though it will not be hardware accelerated and probably slow to display. Its usefulness is that it can be written out as a tif.

          4) Copy the necessary data to the image and write out the image using ImageIO. If you installed JAI-ImageIO, the exact ImageWriter that would be used is com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter. The reason you needed to create a whole image is because Image#canWriteRasters() for this writer returns false.

          When reading the file you'll get a BufferedImage of which only the raster you'll be interested in. It will contain all the color and spot channel data.
          1 person found this helpful
          • 2. Re: Tiff Image with Spot Channel
            Thanks a lot Maxideon, your answer is very helpul.

            I'm having a look at the solution you suggested.

            Hope I manage to solve that.

            Thanks again.
            • 3. Re: Tiff Image with Spot Channel
              Hello again Maxideon,
              I followed your detailed hints!

              I have to say I am not very expert in ColorSpace.

              As you suggested, I started creating a custom ColorSpace.
              public class ColorSpaceWithExtraChannel extends ColorSpace{
                  public ColorSpaceWithExtraChannel() {
                      super (ColorSpace.TYPE_RGB, 4);
                  public String getName (int idx) {
                          return "newChannelName";
                          return super.getName(idx);
                  public float[] toRGB(float[] colorvalue) {
                      return new float[] {colorvalue[0],colorvalue[1],colorvalue[2]};
                  public float[] fromRGB(float[] rgbvalue) {
                      return new float[] {rgbvalue[0],rgbvalue[1],rgbvalue[2],0.0f};
                  public float[] toCIEXYZ(float[] colorvalue) {
                      throw new UnsupportedOperationException("Not supported yet.");
                  public float[] fromCIEXYZ(float[] colorvalue) {
                      throw new UnsupportedOperationException("Not supported yet.");
              Then this is what I did:
              RenderedOp sourceImage = JAI.create("fileload", sourceImagePath);
              ColorSpaceWithExtraChannel colorSpaceWithExtraChannel = new ColorSpaceWithExtraChannel ();
              ComponentColorModel componentColorModel = new ComponentColorModel(colorSpaceWithExtraChannel , true, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
              int w = sourceImage.getWidth(), h = sourceImage.getHeight();
              WritableRaster writableRaster = componentColorModel.createCompatibleWritableRaster(w, h);
              BufferedImage biResult = new BufferedImage(componentColorModel, writableRaster, false, null);
              Graphics2D graphics2D = biResult.createGraphics();
              graphics2D.drawImage(sourceImage.getAsBufferedImage(), 0, 0, null);
              String outputPath = "/tmp/"+System.currentTimeMillis()+"result.tiff";
              ImageWriter writer = ImageIO.getImageWritersByFormatName("tiff").next();
              //hasToBe com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter
              IIOImage iimageFinal = new IIOImage(biResult, null, null);
              FileImageOutputStream fiosOutuputImage = new FileImageOutputStream(new File(outputPath));
              I get no error, but when I open the output file in Photoshop, the channels are not in RGB anymore and the extra channel in a normal channel (not a spot channel).
              I think I did something wrong.

              Thanks again.
              • 4. Re: Tiff Image with Spot Channel
                I did not know you wanted to be able to open the image in Adobe. My solution was more of save in java, open in java type of thing. To get Adobe to interpret the extra channels as spot channels is a much more difficult task.

                Here's a metadata snapshot of an image with a spot channel saved via Adobe.
                254     NewSubfileType     0
                256     ImageWidth     1920
                257     ImageLength     1200
                258     BitsPerSample     8,8,8,8
                259     Compression     1
                262     PhotometricInterpretation     2
                273     StripOffsets     24682
                274     Orientation     1
                277     SamplesPerPixel     4
                278     RowsPerStrip     1200
                279     StripByteCounts     9216000
                282     XResolution     72/1
                283     YResolution     72/1
                284     PlanarConfiguration     1
                296     ResolutionUnit     2
                305     Software     Adobe Photoshop CS5.1 Windows
                306     DateTime     2013:04:09 11:42:39
                338     ExtraSamples     0
                700     unknown     60,63,120,112,...
                33723     unknown     28,1,90,0,3,27,37,71,28,2,0,0,2,8,51
                34377     unknown     56,66,73,...
                36864     EXIFversion     48,50,50,49
                40961     ColorSpace     65535
                40962     PixelXDimension     1920
                40963     PixelYDimension     1200
                36864     EXIFversion     48,50,50,49
                40961     ColorSpace     65535
                40962     PixelXDimension     1920
                40963     PixelYDimension     1200
                Here's a metadata snapshot of the same image, but saved using the TIFFImageWriter.
                256     ImageWidth     1920
                257     ImageLength     1200
                258     BitsPerSample     8,8,8,8
                259     Compression     32773
                262     PhotometricInterpretation     1
                273     StripOffsets     1384,63302,...
                277     SamplesPerPixel     4
                278     RowsPerStrip     8
                279     StripByteCounts     61918,61920,...
                282     XResolution     1/1
                283     YResolution     1/1
                296     ResolutionUnit     1
                I think the key difference is TIFF Tag #338 (google it). I figured if I just added this tag to the metadata, Adobe would see it as a spot channel. Now onto the problem... According to the TIFFImageWriter api the "ExtraSamples" tag may be added or modified if an alpha channel is present and it may be removed if there is no alpha channel. In other words this is one of the few tags that the TIFFImageWriter takes complete control over. I tried tricking it in to setting it to 0, but no go.

                So incidentally, I'm out of advise. You'll have to resort to a 3rd party java TIFFImageWriter or do the writing yourself.
                1 person found this helpful
                • 5. Re: Tiff Image with Spot Channel

                  what you need is a tiff image reader in vb.net to help you so you can have all the color and spot channel data.. use a third party software is a good advice.