Exemplo n.º 1
0
      ImageJMetadata::ImageJMetadata(const IFD& ifd)
      {
        ifd.getField(IMAGEJ_META_DATA_BYTE_COUNTS).get(counts);
        ifd.getField(IMAGEJ_META_DATA).get(data);
        std::string desc;
        ifd.getField(IMAGEDESCRIPTION).get(desc);
        map = parse_imagedescription(desc);

        parse_value("images", images);
        parse_value("channels", channels);
        parse_value("slices", slices);
        parse_value("frames", frames);
        parse_value("unit", unit);
        parse_value("spacing", spacing);
        parse_value("finterval", finterval);
        parse_value("xorigin", xorigin);
        parse_value("yorigin", yorigin);
        parse_value("mode", mode);
        parse_value("loop", loop);
      }
Exemplo n.º 2
0
      void
      getCoreMetadata(const IFD&    ifd,
                      CoreMetadata& core)
      {
        core.dimensionOrder = ome::xml::model::enums::DimensionOrder::XYCZT;
        core.sizeX = ifd.getImageWidth();
        core.sizeY = ifd.getImageHeight();
        core.pixelType = ifd.getPixelType();

        core.bitsPerPixel = significantBitsPerPixel(core.pixelType);
        pixel_size_type psize = ifd.getBitsPerSample();
        if (psize < core.bitsPerPixel)
          core.bitsPerPixel = psize;

        uint16_t samples = ifd.getSamplesPerPixel();
        tiff::PhotometricInterpretation photometric = ifd.getPhotometricInterpretation();

        core.sizeC.clear();
        core.sizeC.push_back(samples);
        core.sizeZ = core.sizeT = core.imageCount = 1U;

        // libtiff does any needed endian conversion
        // automatically, so the data is always in the native
        // byte order.
#ifdef BOOST_BIG_ENDIAN
        core.littleEndian = false;
#else // ! BOOST_BIG_ENDIAN
        core.littleEndian = true;
#endif // BOOST_BIG_ENDIAN

        // This doesn't match the reality, but since subchannels are
        // addressed as planes this is needed.
        core.interleaved = (ifd.getPlanarConfiguration() == tiff::CONTIG);

        // Indexed samples.
        if (samples == 1 && photometric == tiff::PALETTE)
          {
            try
              {
                ome::compat::array<std::vector<uint16_t>, 3> cmap;
                ifd.getField(tiff::COLORMAP).get(cmap);
                core.indexed = true;
              }
            catch (...)
              {
              }
          }
        // Indexed samples for different photometric interpretations;
        // not currently supported fully.
        else
          {
            try
              {
                uint16_t indexed;
                ifd.getField(tiff::INDEXED).get(indexed);
                if (indexed)
                  {
                    core.indexed = true;
                  }
              }
            catch (...)
              {
              }
          }

        // Add series metadata from tags.
        setMetadata(ifd, core, "PageName #", PAGENAME);
        setMetadata(ifd, core, "ImageWidth", IMAGEWIDTH);
        setMetadata(ifd, core, "ImageLength", IMAGELENGTH);
        setMetadata(ifd, core, "BitsPerSample", BITSPERSAMPLE);

        /// @todo EXIF IFDs

        setMetadata(ifd, core, "PhotometricInterpretation", PHOTOMETRIC);

        /// @todo Text stream output for Tag enums.
        /// @todo Metadata type for PhotometricInterpretation.

        try
          {
            setMetadata(ifd, core, "Artist", ARTIST);
            Threshholding th;
            ifd.getField(THRESHHOLDING).get(th);
            core.seriesMetadata.set("Threshholding", th);
            if (th == HALFTONE)
              {
                setMetadata(ifd, core, "CellWidth", CELLWIDTH);
                setMetadata(ifd, core, "CellLength", CELLLENGTH);
              }
          }
        catch (...)
          {
          }

        setMetadata(ifd, core, "Orientation", ORIENTATION);

        /// @todo Image orientation (storage order and direction) from
        /// ORIENTATION; fix up width and length from orientation.

        setMetadata(ifd, core, "SamplesPerPixel", SAMPLESPERPIXEL);
        setMetadata(ifd, core, "Software", SOFTWARE);
        setMetadata(ifd, core, "Instrument Make", MAKE);
        setMetadata(ifd, core, "Instrument Model", MODEL);
        setMetadata(ifd, core, "Make", MAKE);
        setMetadata(ifd, core, "Model", MODEL);
        setMetadata(ifd, core, "Document Name", DOCUMENTNAME);
        setMetadata(ifd, core, "Date Time", DATETIME);
        setMetadata(ifd, core, "Artist", ARTIST);

        setMetadata(ifd, core, "Host Computer", HOSTCOMPUTER);
        setMetadata(ifd, core, "Copyright", COPYRIGHT);

        setMetadata(ifd, core, "Subfile Type", SUBFILETYPE);
        setMetadata(ifd, core, "Fill Order", FILLORDER);

        setMetadata(ifd, core, "Min Sample Value", MINSAMPLEVALUE);
        setMetadata(ifd, core, "Max Sample Value", MAXSAMPLEVALUE);

        setMetadata(ifd, core, "XResolution", XRESOLUTION);
        setMetadata(ifd, core, "YResolution", YRESOLUTION);

        setMetadata(ifd, core, "Planar Configuration", PLANARCONFIG);

        setMetadata(ifd, core, "XPosition", XPOSITION);
        setMetadata(ifd, core, "YPosition", YPOSITION);

        /// @todo Only set if debugging/verbose.
        // setMetadata(ifd, core, "FreeOffsets", FREEOFFSETS);
        // setMetadata(ifd, core, "FreeByteCounts", FREEBYTECOUNTS);

        setMetadata(ifd, core, "GrayResponseUnit", GRAYRESPONSEUNIT);
        setMetadata(ifd, core, "GrayResponseCurve", GRAYRESPONSECURVE);

        try
          {
            Compression cmpr;
            ifd.getField(COMPRESSION).get(cmpr);
            core.seriesMetadata.set("Compression", cmpr);
            if (cmpr == COMPRESSION_CCITT_T4)
              setMetadata(ifd, core, "T4Options", T4OPTIONS);
            else if (cmpr == COMPRESSION_CCITT_T6)
              setMetadata(ifd, core, "T6Options", T6OPTIONS);
            else if (cmpr == COMPRESSION_LZW)
              setMetadata(ifd, core, "Predictor", PREDICTOR);
          }
        catch (...)
          {
          }

        setMetadata(ifd, core, "ResolutionUnit", RESOLUTIONUNIT);

        setMetadata(ifd, core, "PageNumber", PAGENUMBER);

        // TransferRange only valid if TransferFunction set.
        if (setMetadata(ifd, core, "TransferFunction", TRANSFERFUNCTION))
          setMetadata(ifd, core, "TransferRange", TRANSFERRANGE);

        setMetadata(ifd, core, "WhitePoint", WHITEPOINT);
        setMetadata(ifd, core, "PrimaryChromacities", PRIMARYCHROMATICITIES);
        setMetadata(ifd, core, "HalftoneHints", HALFTONEHINTS);

        setMetadata(ifd, core, "TileWidth", TILEWIDTH);
        setMetadata(ifd, core, "TileLength", TILELENGTH);

        /// @todo Only set if debugging/verbose.
        // setMetadata(ifd, core, "TileOffsets", TILEOFFSETS);
        // setMetadata(ifd, core, "TileByteCounts", TILEBYTECOUNTS);

        setMetadata(ifd, core, "InkSet", INKSET);
        setMetadata(ifd, core, "InkNames", INKNAMES);
        setMetadata(ifd, core, "NumberOfInks", NUMBEROFINKS);
        setMetadata(ifd, core, "DotRange", DOTRANGE);
        setMetadata(ifd, core, "TargetPrinter", TARGETPRINTER);
        setMetadata(ifd, core, "ExtraSamples", EXTRASAMPLES);

        setMetadata(ifd, core, "SampleFormat", SAMPLEFORMAT);

        /// @todo sminsamplevalue
        /// @todo smaxsamplevalue

        /// @todo Only set if debugging/verbose.
        // setMetadata(ifd, core, "StripOffsets", STRIPOFFSETS);
        // setMetadata(ifd, core, "StripByteCounts", STRIPBYTECOUNTS);

        /// @todo JPEG tags

        setMetadata(ifd, core, "YCbCrCoefficients", YCBCRCOEFFICIENTS);
        setMetadata(ifd, core, "YCbCrSubSampling", YCBCRSUBSAMPLING);
        setMetadata(ifd, core, "YCbCrPositioning", YCBCRPOSITIONING);
        setMetadata(ifd, core, "ReferenceBlackWhite", REFERENCEBLACKWHITE);

        try
          {
            uint16_t samples;
            ifd.getField(SAMPLESPERPIXEL).get(samples);
            PhotometricInterpretation photometric;
            ifd.getField(PHOTOMETRIC).get(photometric);
            if (photometric == RGB ||
                photometric == CFA_ARRAY)
              samples = 3;

            try
              {
                std::vector<ExtraSamples> extra;
                ifd.getField(EXTRASAMPLES).get(extra);
                samples += static_cast<uint16_t>(extra.size());
              }
            catch (...)
              {
              }

            core.seriesMetadata.set("NumberOfChannels", samples);
          }
        catch (...)
          {
          }

        core.seriesMetadata.set("BitsPerSample", bitsPerPixel(ifd.getPixelType()));
      }